

JSZip - Create .zip files with Javascript - ChrisArchitect
http://jszip.stuartk.co.uk/

======
bradleyland
Having worked with a few Zip libraries, I can't bring myself to use any
library that has an O(n) memory requirement as it relates to archive size. I
can't see how this would avoid that because of the way the file is delivered
to the client.

------
mitchellh
Cute project.

For practical usage in dynamically creating ZIP files, I've found it far more
efficient and easy to use the `mod_zip` extension to Nginx[1]. It works really
well, is highly RAM efficient, and pushes the logic down to some of the most
stable software out there (Nginx).

[1]: <http://wiki.nginx.org/NgxZip>

~~~
anthonyryan1
What version of nginx are you using with it? The last time I looked into that
particular plugin it did not appear to work correctly.

------
engtech
I've been looking at something similiar for huge static HTML files of
autogenerated documentation.

I don't see why I can't deflate the tables as javascript data and then use JS
to inflate and display them.

Just playing around with it I was able to compress a 120MB HTML file to 3.5MB.

~~~
dspillett
Would mod_deflate or equivalent (mod_gzip in older Apache versions, static and
dynamic compression can be enabled easily in recent versions of IIS too) not
do this for you?

If you are worried about the CPU cost of the compression and added request
latency, you can pre-compress static content with most modern web servers (see
[http://stackoverflow.com/questions/75482/how-can-i-pre-
compr...](http://stackoverflow.com/questions/75482/how-can-i-pre-compress-
files-with-mod-deflate-in-apache-2-x) for Apache info).

~~~
engtech
In this case, there are no servers.

There are only local HTML files that are checked in to revision control and
shipped alongside releases.

HTML was chosen as the documentation file format because it's easy to find
something to view it with.

------
JangoSteve
It's odd to me that everyone is talking about the user experience for
downloading files created with this. The real awesome use case with a library
like this (and what I'm currently using this for in a new project) is
providing a user a multi-select to upload files, and zipping then up into a
single compressed file before uploading to the server.

------
josscrowcroft
Fantastic. I already have at least 3 use cases in mind!

I'm interested to look into ways of feature-detection for this that could
cause the zip to be generated client-side for supporting browsers and server-
side for older..

~~~
JangoSteve
I'm currently using this in a site, I fan post my feature detection line for
it when I get back to the office.

------
udp
Pretty cool, but the method for "downloading" looks _painful_ (converting the
generated ZIP to base64 in order to use it as an URL).

I wonder what the size limit is?

~~~
dpup
Chrome (last time I checked) will crash if the data URL is over 2MB. Luckily
there are the Blob and BlobBuilder APIs now. Using Stuart's code as a starting
point I've successfully built >700MB zip files on flixtractr.com. The main
downside is that when you request the blob URL not all browser/platform
combinations give it an extension that matches the mime-type, so you have to
tell your users they may need to rename the file.

The platform is getting there. Slowly.

~~~
dpup
<http://crbug.com/103234> tracks the crash I mentioned.

------
anons2011
Very nice, I guess this would be pretty useful for online template creation
sites, so they can download their modified html/css files as a zip.

------
jonpaul
While it is indeed cool that this is done in the browser, it'd be nice to see
some emphasis on using it within Node.js. Presumably, it'd probably work
without too many modifications.

~~~
maratd
With Node.js, you should use the built-in zlib support.

~~~
jonpaul
I thought the zlib support could only handle gzip files and not zip files?
This would indicate that it only supports gzip files:
<http://zlib.net/zlib_faq.html#faq11>

~~~
maratd
Sorry, I was vague. You should use the zlib library when it doesn't matter
what the container format happens to be. If you need zip, you can still do it
by simply using an outside process to do it. That will be much faster, easier,
and more efficient than using something like this.

------
maratd
This is unbelievably useful if you need to have the client download multiple
files with one click just using the client-side. This wasn't possible before.
Great job!

~~~
smackfu
Aren't the multiple files still on the server side? Why can't the server side
just zip them?

~~~
maratd
> Aren't the multiple files still on the server side?

No, you can generate a file using JavaScript/Canvas/SVG/etc. and then allow
the user to save it to their system.

~~~
dspillett
Aye. I once created a "theme generator" for SonyEricsson phones with
javascript client-side and php server-side.

Their themes were basically a .tar.gz of files: one listing all the colours
and other options and the rest being images for the various interface
elements.

With the canvas and something like this, almost the entire thing could be done
client-site now.

