2 title: "How to write a file / give it to the user"
9 With only javascript, this part won't work in old browsers, including IE < 10.
10 For those browsers, you can use a flash polyfill, see below.
13 [example]({{site.baseurl}}/documentation/examples/download-zip-file.html).
15 #### Blob URL / FileSaver
17 With recent browsers, the easiest way is to use `saveAs` or a polyfill, see
18 [FileSaver.js](https://github.com/eligrey/FileSaver.js) :
21 var blob = zip.generate({type:"blob"});
22 saveAs(blob, "hello.zip");
25 Under the hood, the polyfill uses the native `saveAs` from the
26 [FileSaver](http://www.w3.org/TR/file-writer-api/#the-filesaver-interface) API
27 (on Chrome and IE10+) or use a [Blob URL](http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download)
33 For older browsers that support [data URI](http://caniuse.com/datauri), you can also
37 location.href="data:application/zip;base64," + zip.generate({type:"base64"});
40 The biggest issue here is that the filenames are very awkward, Firefox
41 generates filenames such as `a5sZQRsx.zip.part` (see bugs
42 [367231](https://bugzilla.mozilla.org/show_bug.cgi?id=367231) and
43 [532230](https://bugzilla.mozilla.org/show_bug.cgi?id=532230), and Safari
44 isn't much better with just `Unknown`.
46 Browser support and resulting filename :
48 Opera | Firefox | Safari | Chrome | Internet Explorer
49 -------|---------|--------|--------|------------------
50 "default.zip" | random alphanumeric with ".part" extension | "Unknown" (no extension) | "download.zip" on OSX and Linux, just "download" on Windows | No
54 [Downloadify](https://github.com/dcneiner/downloadify) uses a small Flash SWF
55 to download files to a user's computer with a filename that you can choose.
56 Doug Neiner has added the `dataType` option to allow you to pass a zip for
57 downloading. Follow the [Downloadify demo](http://pixelgraphics.us/downloadify/test.html)
58 with the following changes:
62 zip.file("Hello.", "hello.txt");
63 Downloadify.create('downloadify',{
66 return zip.generate({type:"base64"});
74 TODO : send data as GET / POST ?
77 #### Deprecated google gears
79 [Franz Buchinger](http://www.picurl.org/blog/author/franz/) has written a
80 brilliant tutorial on [using JSZip with Google Gears](http://www.picurl.org/blog/2009/11/22/creating-zip-archives-with-gears)
81 ([part 2](http://www.picurl.org/blog/2009/11/29/gearszipper-part2-adding-support-for-real-files-and-canvas-elements/)).
82 If you want to let your Gears users download several files at once I really
83 recommend having a look at some of his [examples](http://picurl.org/gears/zipper/).
89 JSZip can generate Buffers so you can do the following :
92 var fs = require("fs");
93 var JSZip = require("jszip");
95 var zip = new JSZip();
96 // zip.file("file", content);
97 // ... and other manipulations
99 var buffer = zip.generate({type:"nodebuffer"});
101 fs.writeFile("test.zip", buffer, function(err) {