Create zip files using jQuery - javascript

I have an array of files and I want to create a zip file out of this array.
Is there a way to create zip files using jQuery?

You can use the JSZip library mentioned by several people to create the zip. However, forcing a download from javascript and having it use a custom filename is a different matter.
HTML5 introduces a download attribute on <a>s. You could use it like this:
download
Which would force the download as "something.zip" in browsers supporting the download attribute. However, besides this, there is no way to do it from JavaScript.

Related

JS: Generating a zip file with "store" level compression

I want to make a zip file in JavaScript with "store" level compression, i.e. no compression, without having to download a whole library like JSzip because most of the functionality isn't needed. Is there a good way to do that?
The zip file format is relatively straightforward. You can implement your own zip file creation routines that only produce stored entries. You can find the zip file format documented here.
My answer is generate the zip file on the server and let users download it.

create a folder with JavaScript

I know that JavaScript is not allowed by browsers to do much directly with the computer, and that is not my question. My question is: How to, with JavaScript, create a file on the web and then ask, perhaps with a popup window, to download the folder and any files within. This folder would need to allow access for JavaScript to place files within, like image files. This folder might originally be just another JavaScript value (like an object) or a URL.
I have done research, but much of what I found was asking whether JavaScript could create a folder directly to the computer, while my question is asking about creating the folder, and then asking to download it. There must be some way, because when in Google Drive, drive has a way to place multiple files in a .zip folder for download, and this works not just with Chrome but with Firefox and Internet Explorer. Some sites like http://stuk.github.io/jszip/ provide their own way to create .zip files, but I would prefer not to use a JavaScript library, if possible.
This would be useful for generating multiple image files, but only asking the user once for downloading them, instead of for each file.
I would prefer to create the zips client-side.
So this is an interesting question and I shall do my best to answer it. The simple solution is to not do this at all. Use javascript to asynchronously request the server to create the required .zip and then give the user a link/prompt to download. But I digress, you want it all in-house!
JSzip Option
You'll not be able to write a solid library that can .zip files client-side. JSzip is the best option out there, and it's not as solid as it could be. If you have the time you could go through the source and make improvements where required.
Cheeky Option
Your best option - baring the actual best one (server side) which you have discounted - is explained here. That is - create an iframe for each file.
Unfortunately you'll not find any better than those options if you're insisting on client-side work. Browsers weren't made to be zipping files.

Generate and download Zip file on the fly in (client-side) JS

I have n Javascript float arrays.
My goal is to generate and download a Zip file, using JS only, containing n CSV files, one per array.
I am aware of Javascript librairies like JSZip: http://stuk.github.io/jszip/ for generating zip files.
I also know how to generate and download a file on the fly using Blob and/or a library like FileSaver.js
However, I cannot figure out how to achieve the whole thing, client-side only.
Can anybody help me ?

How do I extract a zip file using javascript?

How do I parse zip file string. I looked for hours I couldn't find an easy to do it. All the examples I found didn't make much sense.
I use zipjs to handle zip files. A simple library that can handle reading and writing zip files.
BE MORE CLEAR NEXT TIME. I think this answer is what you need to hear.
A zip file can not be parsed with simple JavaScript. There is simply no native function that can ope ZIP files. There are certain libraries out there, but personally i have not found one that worked properly, and most use some kind of flash plugin to make it "work".
If you really want a zip file to be presented in Javascript, you will have to build its function with PHP. PHP can write to zip files, and read them: PHP ZIP. If you want to read the contents of a zip file, you would have to upload the file to the server (can be done with JS), then make the PHP return a JSON object with all the file_info of all the files inside the ZIP. And last but not least, JS should be able to acces another PHP page that retrieves a particular file, which can be done by reading the file and setting a mimetype before outputting its contents.

How to convert any .htc file into .js file?

How can I convert any .htc file into .js and use the resulting JavaScript?
For example, this is a .htc file: http://curved-corner.googlecode.com/files/border-radius.htc. I want to convert it into .js.
I want to convert it because the CMS I'm working with will not allow me to attach the .htc file. I think it's because of a mime type issue.
It is not possible to convert any .htc file to an "equivalent" .js file. That is, it's not possible automatically, in general. However for the specific file you've posted, you could convert it using jQuery's live event.
But anyway, there's plenty of Javascript-only libraries that do the "border-radius" thing, why do you need to specific convert this one? A quick google search turns up dozens.
You might find some interesting information regarding conversion of HTC to JavaScript objects in this blog: http://ehudpardo.blogspot.com/2011/09/part-1-converting-htc-behaviors-to.html

Categories

Resources