1
0
mirror of https://gitlab.com/JKANetwork/CheckServer.git synced 2026-02-22 13:03:47 +01:00

Start again

This commit is contained in:
2020-10-04 17:14:00 +02:00
parent c0d3912413
commit 091f119048
4382 changed files with 1762543 additions and 9606 deletions

View File

@@ -0,0 +1,158 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Create .zip files using Javascript. Provides a simple API to place any content generated by Javascript into a .zip file for your users." />
<title>{{page.title}}</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<!-- <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> -->
<link rel="stylesheet" href="{{site.baseurl}}/documentation/css/pygments.css">
<link rel="stylesheet" href="{{site.baseurl}}/documentation/css/main.css">
<script type="text/javascript" src="{{site.baseurl}}/dist/jszip.js"></script>
<script type="text/javascript" src="//stuk.github.io/jszip-utils/dist/jszip-utils.js"></script>
<!--
Mandatory in IE 6, 7, 8 and 9.
-->
<!--[if IE]>
<script type="text/javascript" src="//stuk.github.io/jszip-utils/dist/jszip-utils-ie.js"></script>
<![endif]-->
<!--
Any version of jQuery will do (it's just to write some examples), this one
happens to be available in our tests.
-->
<script type="text/javascript" src="{{site.baseurl}}/test/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="{{site.baseurl}}/vendor/FileSaver.js"></script>
</head>
<body>
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{{site.baseurl}}/"><strong>JS</strong>Zip</a>
</div>
<ul class="nav navbar-nav">
<li {% if page.section == "api" %}class="active"{% endif %}>
<a href="{{site.baseurl}}/documentation/api_jszip.html">API</a>
</li>
<li {% if page.section == "example" %}class="active"{% endif %}>
<a href="{{site.baseurl}}/documentation/examples.html">How to / examples</a>
</li>
<li {% if page.section == "limitations" %}class="active"{% endif %}>
<a href="{{site.baseurl}}/documentation/limitations.html">Performances / limitations</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/Stuk/jszip">JSZip on Github</a>
</li>
</ul>
</div>
</div>
{% if page.section and page.fullpage != true %}
<div class="row">
<nav class="col-md-3">
{% case page.section %}
{% when "main" %}
<h4>JSZip users :</h4>
<ul class="nav">
<li><a href="{{site.baseurl}}/">Installation</a></li>
<li><a href="{{site.baseurl}}/documentation/faq.html">FAQ</a></li>
<li><a href="{{site.baseurl}}/CHANGES.html">Changelog</a></li>
<li><a href="{{site.baseurl}}/documentation/upgrade_guide.html">Upgrade guide</a></li>
<li><a href="https://github.com/Stuk/jszip/issues">Bug tracker</a></li>
</ul>
<h4>JSZip developers :</h4>
<ul class="nav">
<li><a href="{{site.baseurl}}/documentation/contributing.html">How to contribute</a></li>
<li><a href="https://github.com/Stuk/jszip/graphs/contributors">Contributors</a></li>
</ul>
{% when "api" %}
<ul class="nav">
<li><a href="{{site.baseurl}}/documentation/api_jszip.html">JSZip</a>
<ul>
<li><a href="{{site.baseurl}}/documentation/api_jszip/constructor.html">new JSZip() or JSZip()</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/constructor_load.html">new JSZip(data [,options])</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/file_name.html">JSZip#file(name)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/file_regex.html">JSZip#file(regex)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/file_data.html">JSZip#file(name, data [,options])</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/folder_data.html">JSZip#folder(name)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/folder_regex.html">JSZip#folder(regex)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/filter.html">JSZip#filter(predicate)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/remove.html">JSZip#remove(name)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/generate.html">JSZip#generate(options)</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/load.html">JSZip#load(data [, options])</a></li>
<li><a href="{{site.baseurl}}/documentation/api_jszip/support.html">JSZip.support</a></li>
</ul>
</li>
<li><a href="{{site.baseurl}}/documentation/api_zipobject.html">ZipObject</a></li>
</ul>
{% when "example" %}
<h4>How to ...</h4>
<ul class="nav">
<li><a href="{{site.baseurl}}/documentation/examples.html">Use JSZip</a></li>
<li><a href="{{site.baseurl}}/documentation/howto/read_zip.html">Read a file</a></li>
<li><a href="{{site.baseurl}}/documentation/howto/write_zip.html">Write a file</a></li>
</ul>
<h4>Examples</h4>
<ul class="nav">
<li><a href="{{site.baseurl}}/documentation/examples/read-local-file-api.html">Read local file</a></li>
<li><a href="{{site.baseurl}}/documentation/examples/get-binary-files-ajax.html">Read remote file</a></li>
<li><a href="{{site.baseurl}}/documentation/examples/download-zip-file.html">Give the user its zip file</a></li>
<li><a href="{{site.baseurl}}/documentation/examples/downloader.html">Mini app : downloader</a></li>
</ul>
{% endcase %}
<!-- <ul class="nav"> -->
<!-- <li><a href="{{site.baseurl}}/documentation/faq.html">FAQ</a></li> -->
<!-- </ul> -->
<!-- <li><a href="{{site.baseurl}}/">installation</a></li> -->
</nav>
{% endif %}
<div class="{% if page.section and page.fullpage != true%}col-md-9{% else %}col-md-12{% endif %}">
<h1>{{page.title}}</h1>
<!-- ===================== -->
<!-- === C O N T E N T === -->
<!-- ===================== -->
{{content}}
<!-- ===================== -->
<!-- == / C O N T E N T == -->
<!-- ===================== -->
</div>
</div>
</div>
<script>
// FIXME find how to do that cleanly
(function(){
var tables = document.getElementsByTagName("table");
for(var i = 0; i < tables.length; i++) {
tables[i].className += " table table-condensed table-striped table-bordered ";
}
})();
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-52085706-1', 'stuk.github.io');
ga('send', 'pageview');
</script>
</body>
</html>

View File

@@ -0,0 +1,15 @@
---
title: "JSZip API"
layout: default
section: api
---
An instance of JSZip represents a set of files. You can add them, remove them,
modify them. You can also import an existing zip file or generate one.
### Attributes
attribute name | type | description
---------------------|-------------|-------------
`files` | object | the [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html)s inside the zip with the name as key. See [file(name)]({{site.baseurl}}/documentation/api_jszip/file_name.html).
`comment` | string | the comment of the zip file.

View File

@@ -0,0 +1,23 @@
---
title: "new JSZip() or JSZip()"
layout: default
section: api
---
__Description__ : Create a new JSZip instance.
__Arguments__ : None
__Returns__ : A new JSZip.
__Throws__ : Nothing.
<!-- __Complexity__ : Object creation in **O(1)**. -->
__Example__
```js
var zip = new JSZip();
// same as
var zip = JSZip();
```

View File

@@ -0,0 +1,22 @@
---
title: "new JSZip(data [,options]) or JSZip(data [,options])"
layout: default
section: api
---
This is a shortcut for
```js
var zip = new JSZip();
zip.load(data, options);
```
Please see the documentation of [load]({{site.baseurl}}/documentation/api_jszip/load.html).
__Example__
```js
var zip = new JSZip(data, options);
// same as
var zip = JSZip(data, options);
```

View File

@@ -0,0 +1,90 @@
---
title: "file(name, data [,options])"
layout: default
section: api
---
__Description__ : Add (or update) a file to the zip file.
__Arguments__
name | type | description
--------------------|---------|------------
name | string | the name of the file. You can specify folders in the name : the folder separator is a forward slash ("/").
data | String/ArrayBuffer/Uint8Array/Buffer | the content of the file.
options | object | the options.
Content of `options` :
name | type | default | description
------------|---------|---------|------------
base64 | boolean | `false` | set to `true` if the data is base64 encoded. For example image data from a `<canvas>` element. Plain text and HTML do not need this option.
binary | boolean | `false` | set to `true` if the data should be treated as raw content, `false` if this is a text. If base64 is used, this defaults to `true`, if the data is not a string, this will be set to `true`.
date | date | the current date | the last modification date.
compression | string | null | If set, specifies compression method to use for this specific file. If not, the default file compression will be used, see [generate(options)]({{site.baseurl}}/documentation/api_jszip/generate.html).
compressionOptions | object | `null` | the options to use when compressing the file, see [generate(options)]({{site.baseurl}}/documentation/api_jszip/generate.html).
comment | string | null | The comment for this file.
optimizedBinaryString | boolean | `false` | Set to true if (and only if) the input is a "binary string" and has already been prepared with a 0xFF mask.
createFolders | boolean | `false` | Set to true if folders in the file path should be automatically created, otherwise there will only be virtual folders that represent the path to the file.
unixPermissions | 16 bits number | null | The UNIX permissions of the file, if any.
dosPermissions | 6 bits number | null | The DOS permissions of the file, if any.
dir | boolean | false | Set to true if this is a directory and content should be ignored.
You shouldn't update the data given to this method : it is kept as it so any
update will impact the stored data.
__For the permissions__ :
The field `unixPermissions` also accepts a string representing the octal value :
"644", "755", etc. On nodejs you can use the `mode` attribute of
[nodejs' fs.Stats](http://nodejs.org/api/fs.html#fs_class_fs_stats).
See also [the platform option of generate()]({{site.baseurl}}/documentation/api_jszip/generate.html).
__About `dir`__ :
If `dir` is true or if a permission says it's a folder, this entry be flagged
as a folder and the content will be ignored.
__Returns__ : The current JSZip object, for chaining.
__Throws__ : An exception if the data is not in a supported format.
<!--
__Complexity__ : **O(1)** for anything but binary strings.
For binary strings (`data` is a string and `binary` = true), if
`optimizedBinaryString` is not set, the 0xFF mask will be applied giving a
complexity in **O(n)** where n is the size of the added data.
-->
__Example__
```js
zip.file("Hello.txt", "Hello World\n");
// base64
zip.file("smile.gif", "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs=", {base64: true});
// from an ajax call with xhr.responseType = 'arraybuffer'
zip.file("smile.gif", arraybufferFromXhr);
// or on nodejs
zip.file("smile.gif", fs.readFileSync("smile.gif"));
zip.file("Xmas.txt", "Ho ho ho !", {date : new Date("December 25, 2007 00:00:01")});
zip.file("folder/file.txt", "file in folder");
zip.file("animals.txt", "dog,platypus\n").file("people.txt", "james,sebastian\n");
// result : Hello.txt, smile.gif, Xmas.txt, animals.txt, people.txt,
// folder/, folder/file.txt
// In the above case, the "folder" folder will not have a 'D'irectory attribute or Method property. The
// folder only exists as part of the path to "file.txt".
zip.file("folder/file.txt", "file in folder", {createFolders: true});
// In this case, the "folder" folder WILL have a 'D'irectory attribute and a Method property of "store".
// It will exist whether or not "file.txt" is present.
zip.file("script.sh", "echo 'hello world'", {
unixPermissions : "755"
});
// when generated with platform:UNIX, the script.sh file will be executable
```

View File

@@ -0,0 +1,46 @@
---
title: "file(name)"
layout: default
section: api
---
__Description__ : Get a file with the specified name. You can specify folders
in the name : the folder separator is a forward slash ("/").
__Arguments__
name | type | description
-----|--------|-------------
name | string | the name of the file.
__Returns__ : An instance of [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html) representing
the file if any, `null` otherwise.
__Throws__ : Nothing.
<!-- __Complexity__ : This is a simple lookup in **O(1)**. -->
__Examples__
```js
var zip = new JSZip();
zip.file("file.txt", "content");
zip.file("file.txt").name // "file.txt"
zip.file("file.txt").asText() // "content"
zip.file("file.txt").options.dir // false
// utf8 example
var zip = new JSZip(zipFromAjaxWithUTF8);
zip.file("amount.txt").asText() // "€15"
zip.file("amount.txt").asArrayBuffer() // an ArrayBuffer containing €15 encoded as utf8
zip.file("amount.txt").asUint8Array() // an Uint8Array containing €15 encoded as utf8
// with folders
zip.folder("sub").file("file.txt", "content");
zip.file("sub/file.txt"); // the file
// or
zip.folder("sub").file("file.txt") // the file
```

View File

@@ -0,0 +1,49 @@
---
title: "file(regex)"
layout: default
section: api
---
__Description__ : Search a file in the current folder and subfolders with a
[regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).
The regex is tested against the relative filename.
__Arguments__
name | type | description
------|--------|------------
regex | RegExp | the regex to use.
__Returns__ : An array of matching files (an empty array if none matched). Each
maching file is an instance of [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html).
__Throws__ : Nothing.
<!--
__Complexity__ : **O(k)** where k is the number of entries in the current JSZip
instance.
-->
__Example__
```js
var zip = new JSZip();
zip.file("file1.txt", "content");
zip.file("file2.txt", "content");
zip.file(/file/); // array of size 2
// example with a relative path :
var folder = zip.folder("sub");
folder
.file("file3.txt", "content") // relative path from folder : file3.txt
.file("file4.txt", "content"); // relative path from folder : file4.txt
folder.file(/file/); // array of size 2
folder.file(/^file/); // array of size 2, the relative paths start with file
// arrays contain objects in the form:
// {name: "file2.txt", dir: false, asText : function () {...}, ...}
```

View File

@@ -0,0 +1,43 @@
---
title: "filter(predicate)"
layout: default
section: api
---
__Description__ : Filter nested files/folders with the specified function.
__Arguments__
name | type | description
----------|----------|------------
predicate | function | the predicate to use.
The predicate has the following signature : `function (relativePath, file) {...}` :
name | type | description
-------------|-----------|------------
relativePath | string | the filename and its path, reliatively to the current folder.
file | ZipObject | the file being tested. See [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html).
The predicate must return true if the file should be included, false otherwise.
__Returns__ : An array of matching ZipObject.
__Throws__ : Nothing.
<!-- __Complexity__ : **O(k)** where k is the number of entries. -->
__Example__
```js
var zip = new JSZip().folder("dir");
zip.file("readme.txt", "content");
zip.filter(function (relativePath, file){
// relativePath == "readme.txt"
// file = {name:"dir/readme.txt",options:{...},asText:function}
return true/false;
});
```

View File

@@ -0,0 +1,34 @@
---
title: "folder(name)"
layout: default
section: api
---
__Description__ : Create a directory if it doesn't exist, return a new JSZip
object with the new folder as root.
See also [the `dir` option of file()]({{site.baseurl}}/documentation/api_jszip/file_data.html).
__Arguments__
name | type | description
-----|--------|------------
name | string | the name of the directory.
__Returns__ : A new JSZip (for chaining), with the new folder as root.
__Throws__ : Nothing.
<!-- __Complexity__ : **O(1)** -->
__Example__
```js
zip.folder("images");
zip.folder("css").file("style.css", "body {background: #FF0000}");
// or specify an absolute path (using forward slashes)
zip.file("css/font.css", "body {font-family: sans-serif}")
// result : images/, css/, css/style.css, css/font.css
```

View File

@@ -0,0 +1,40 @@
---
title: "folder(regex)"
layout: default
section: api
---
__Description__ : Search a subdirectory in the current directory with a
[regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).
The regex is tested against the relative path.
__Arguments__
name | type | description
------|--------|------------
regex | RegExp | the regex to use.
__Returns__ : An array of matching folders (an empty array if none matched).
Each maching folder is an instance of [ZipObject]({{site.baseurl}}/documentation/api_zipobject.html).
__Throws__ : Nothing.
<!--
__Complexity__ : **O(k)** where k is the number of entries in the current JSZip
instance.
-->
__Example__
```js
var zip = new JSZip();
zip.folder("home/Pierre/videos");
zip.folder("home/Pierre/photos");
zip.folder("home/Jean/videos");
zip.folder("home/Jean/photos");
zip.folder(/videos/); // array of size 2
zip.folder("home/Jean").folder(/^vid/); // array of 1
```

View File

@@ -0,0 +1,161 @@
---
title: "generate(options)"
layout: default
section: api
---
__Description__ : Generates the complete zip file.
__Arguments__
name | type | default | description
--------------------|---------|---------|------------
options | object | | the options to generate the zip file :
options.base64 | boolean | false | **deprecated**, use `type` instead. If `type` is not used, set to `false` to get the result as a raw byte string, `true` to encode it as base64.
options.compression | string | `STORE` (no compression) | the default file compression method to use. Available methods are `STORE` and `DEFLATE`. You can also provide your own compression method.
options.compressionOptions | object | `null` | the options to use when compressing the file, see below.
options.type | string | `base64` | The type of zip to return, see below for the other types.
options.comment | string | | The comment to use for the zip file.
options.mimeType | string | `application/zip` | mime-type for the generated file. Useful when you need to generate a file with a different extension, ie: ".ods".
options.platform | string | `DOS` | The platform to use when generating the zip file.
options.encodeFileName | function | encode with UTF-8 | the function to encode the file name / comment.
Possible values for `type` :
* `base64` (default) : the result will be a string, the binary in a base64 form.
* `string` : the result will be a string in "binary" form, using 1 byte per char (2 bytes).
* `uint8array` : the result will be a Uint8Array containing the zip. This requires a compatible browser.
* `arraybuffer` : the result will be a ArrayBuffer containing the zip. This requires a compatible browser.
* `blob` : the result will be a Blob containing the zip. This requires a compatible browser.
* `nodebuffer` : the result will be a nodejs Buffer containing the zip. This requires nodejs.
Note : when using type = "uint8array", "arraybuffer" or "blob", be sure to
check if the browser supports it (you can use [`JSZip.support`]({{site.baseurl}}/documentation/api_jszip/support.html)).
The `compressionOptions` parameter depends on the compression type. With
`STORE` (no compression), this parameter is ignored. With `DEFLATE`, you can
give the compression level with `compressionOptions : {level:6}` (or any level
between 1 (best speed) and 9 (best compression)).
Note : if the entry is *already* compressed (coming from a compressed zip file),
calling `generate()` with a different compression level won't update the entry.
The reason is simple : JSZip doesn't know how compressed the content was and
how to match the compression level with the implementation we use.
Note for the `comment` option : the zip format has no flag or field to give the
encoding of this field and JSZip will use UTF-8. With non ASCII characters you
might get encoding issues if the file archiver doesn't use UTF-8 to decode the
comment.
If not set, JSZip will use the field `comment` on its `options`.
Possible values for `platform` : `DOS` and `UNIX`. It also accepts nodejs
`process.platform` values.
When using `DOS`, the attribute `dosPermissions` of each file is used.
When using `UNIX`, the attribute `unixPermissions` of each file is used.
If you set the platform value on nodejs, be sure to use `process.platform`.
`fs.stats` returns a non executable mode for folders on windows, if you
force the platform to `UNIX` the generated zip file will have a strange
behavior on UNIX platforms.
__About `encodeFileName`__ :
By default, JSZip uses UTF-8 to encode the file names / comments. You can use
this method to force an other encoding. Note : the encoding used is not stored
in a zip file, not using UTF-8 may lead to encoding issues.
The function takes a string and returns a bytes array (Uint8Array or Array).
__Returns__ : The generated zip file.
__Throws__ : An exception if the asked `type` is not available in the browser,
see [JSZip.support]({{site.baseurl}}/documentation/api_jszip/support.html).
<!-- __Complexity__ : TODO : worst case, with/out compression, etc -->
__Example__
```js
var content = zip.generate({type:"blob"});
// see FileSaver.js
saveAs(content, "hello.zip");
```
```js
var content = zip.generate({type:"base64"});
location.href="data:application/zip;base64,"+content;
```
```js
var content = zip.generate({type:"nodebuffer"});
require("fs").writeFile("hello.zip", content, function(err){/*...*/});
```
```js
// on nodejs
zip.file(pathname, content, {
date: stat.mtime,
unixPermissions: stat.mode
});
// ...
zip.generate({
type: 'nodebuffer',
platform: process.platform
});
```
```js
//This example will Generate a Open Document Spreasheet, with the correct mime type
var zip = new JSZip();
zip.file("mimetype", "application/vnd.oasis.opendocument.spreadsheet");
var conf2 = zip.folder("Configurations2");
conf2.folder("acceleator");
conf2.folder("images");
conf2.folder("popupmenu");
conf2.folder("statusbar");
conf2.folder("floater");
conf2.folder("menubar");
conf2.folder("progressbar");
conf2.folder("toolbar");
var manifest = "<..."; //xml containing manifest.xml
var styles = "<..."; //xml containing styles.xml
var settings = "<..."; //xml containing settings.xml
var meta = "<..."; //xml containing meta.xml
var content = "<..."; //xml containing content.xml
var metaInf = zip.folder("META-INF");
metaInf.file("manifest.xml", manifest);
zip.file("styles.xml", styles);
zip.file("settings.xml", settings);
zip.file("meta.xml", meta);
zip.file("content.xml", content);
//Generate the file
var odsFile = zip.generate({type: "blob", mimeType: "application/ods", compression: "DEFLATE"});
var url = window.URL.createObjectURL(odsFile);
var link = document.getElementById("link"); //I suppose you'll have a link with this id :)
link.download = "testjs.ods";
link.href = url;
```
Using a custom charset :
```js
// using iconv-lite for example
var iconv = require('iconv-lite');
zip.generate({
type: 'uint8array',
encodeFileName: function (string) {
return iconv.encode(string, 'your-encoding');
}
});
```

View File

@@ -0,0 +1,105 @@
---
title: "load(data [, options])"
layout: default
section: api
---
__Description__ : Read an existing zip and merge the data in the current JSZip
object at the current folder level. This technique has some limitations, see
[here]({{site.baseurl}}/documentation/limitations.html).
__Arguments__
name | type | description
-------------------|--------|------------
data | String/Array of bytes/ArrayBuffer/Uint8Array/Buffer | the zip file
options | object | the options to load the zip file
Content of `options` :
name | type | default | description
------------------------------|---------|---------|------------
options.base64 | boolean | false | set to `true` if the data is base64 encoded, `false` for binary.
options.checkCRC32 | boolean | false | set to `true` if the read data should be checked against its CRC32.
options.optimizedBinaryString | boolean | false | set to true if (and only if) the input is a string and has already been prepared with a 0xFF mask.
options.createFolders | boolean | false | set to true to create folders in the file path automatically. Leaving it false will result in only virtual folders (i.e. folders that merely represent part of the file path) being created.
options.decodeFileName | function | decode from UTF-8 | the function to decode the file name / comment.
You shouldn't update the data given to this method : it is kept as it so any
update will impact the stored data.
Zip features supported by this method :
* Compression (<code>DEFLATE</code> supported)
* zip with data descriptor
* ZIP64
* UTF8 in file name, UTF8 in file content
Zip features not (yet) supported :
* password protected zip
* multi-volume zip
__About `decodeFileName`__ :
A zip file has a flag to say if the filename and comment are encoded with UTF-8.
If it's not set, JSZip has **no way** to know the encoding used. It usually
is the default encoding of the operating system.
The function takes the bytes array (Uint8Array or Array) and returns the
decoded string.
__Returns__ : The current JSZip object.
__Throws__ : An exception if the loaded data is not valid zip data or if it
uses features (multi volume, password protected, etc).
<!--
__Complexity__ : for k the number of entries in the zip file and n the length
of the data :
The default use case is **O(k)**.
If the data is in base64, we must first decode it : **O(k + n)**.
If the data is a string not in base64 and optimizedBinaryString is false, we
must apply the 0xFF mask : **O(k + n)**.
If checkCRC32 is true, it **adds** to the above complexity **O(n)** and the
complexity of the decompression algorithm.
-->
__Example__
```js
var zip = new JSZip();
zip.load(zipDataFromXHR);
```
```js
require("fs").readFile("hello.zip", function (err, data) {
if (err) throw err;
var zip = new JSZip();
zip.load(data);
}
```
Using sub folders :
```js
var zip = new JSZip();
zip.folder("subfolder").load(data);
// the content of data will be loaded in subfolder/
```
Using a custom charset :
```js
// using iconv-lite for example
var iconv = require('iconv-lite');
zip.load(content, {
decodeFileName: function (bytes) {
return iconv.decode(bytes, 'your-encoding');
}
});
```

View File

@@ -0,0 +1,37 @@
---
title: "remove(name)"
layout: default
section: api
---
__Description__ : Delete a file or folder (recursively).
__Arguments__
name | type | description
-----|--------|------------
name | string | the name of the file/folder to delete.
__Returns__ : The current JSZip object.
__Throws__ : Nothing.
<!--
__Complexity__ : **O(k)** where k is the number of entry to delete (may be > 1
when removing a folder).
-->
__Example__
```js
var zip = new JSZip();
zip.file("Hello.txt", "Hello World\n");
zip.file("temp.txt", "nothing").remove("temp.txt");
// result : Hello.txt
zip.folder("css").file("style.css", "body {background: #FF0000}");
zip.remove("css");
//result : empty zip
```

View File

@@ -0,0 +1,16 @@
---
title: "JSZip.support"
layout: default
section: api
---
If the browser supports them, JSZip can take advantage of some "new" features :
ArrayBuffer, Blob, Uint8Array. To know if JSZip can use them, you can check the
JSZip.support object. It contains the following boolean properties :
* `arraybuffer` : true if JSZip can read and generate ArrayBuffer, false otherwise.
* `uint8array` : true if JSZip can read and generate Uint8Array, false otherwise.
* `blob` : true if JSZip can generate Blob, false otherwise.
* `nodebuffer` : true if JSZip can read and generate nodejs Buffer, false otherwise.

View File

@@ -0,0 +1,37 @@
---
title: "ZipObject API"
layout: default
section: api
---
This represents an entry in the zip file. If the entry comes from an existing
archive previously [loaded]({{site.baseurl}}/documentation/api_jszip/load.html), the content
will be automatically decompressed/converted first.
### Attributes
attribute name | type | description
----------------------------|-------------|-------------
`name` | string | the absolute path of the file
`dir` | boolean | true if this is a directory
`date` | date | the last modification date
`comment` | string | the comment for this file
`unixPermissions` | 16 bits number | The UNIX permissions of the file, if any.
`dosPermissions` | 6 bits number | The DOS permissions of the file, if any.
`options` | object | the options of the file. The available options are :
`options.base64` | boolean | **Deprecated**, see [file(name, data [,options])]({{site.baseurl}}/documentation/api_jszip/file_data.html)
`options.binary` | boolean | **Deprecated**, see [file(name, data [,options])]({{site.baseurl}}/documentation/api_jszip/file_data.html)
`options.dir` | boolean | **Deprecated**, use `dir`. True if this is a directory
`options.date` | date | **Deprecated**, use `date`. See [file(name, data [,options])]({{site.baseurl}}/documentation/api_jszip/file_data.html)
`options.compression` | compression | see [file(name, data [,options])]({{site.baseurl}}/documentation/api_jszip/file_data.html)
### Getters
method | return type | description
------------------|---------------|-------------
`asText()` | string | the content as an unicode string.
`asBinary()` | string | the content as binary string.
`asArrayBuffer()` | ArrayBuffer | need a [compatible browser]({{site.baseurl}}/documentation/api_jszip/support.html).
`asUint8Array()` | Uint8Array | need a [compatible browser]({{site.baseurl}}/documentation/api_jszip/support.html).
`asNodeBuffer()` | nodejs Buffer | need [nodejs]({{site.baseurl}}/documentation/api_jszip/support.html).

View File

@@ -0,0 +1,62 @@
---
title: Contributing
layout: default
section: main
---
### Download the sources
You should create a [Github](https://github.com/) account and
[fork the repository](https://help.github.com/articles/fork-a-repo) (you will
need one to create the pull request).
If you just want the get the source code, you can use git and do
`git clone https://github.com/Stuk/jszip.git` to get the sources. You can also
download the latest sources [here](https://github.com/Stuk/jszip/archive/master.zip).
### Building the project
#### Code
The dependencies are handled by npm, the first step is to run
`npm install` to get the dependencies.
JSZip uses Grunt to handle the build, [see here to install its CLI](http://gruntjs.com/getting-started).
Here are the interesting build commands :
* `grunt` will generate the final js file in dist/ and the minified version.
* `npm run test-node` will run the tests in nodejs.
* `npm run test-browser` will the tests in some browsers using SauceLabs, see
below.
* `npm run test` will run the tests in nodejs and in the browser.
* `npm run lint` will use jshint the check the source code.
#### Documentation
The documentation uses jekyll on gh-pages. To render the documentation, you
need to [install jekyll](http://jekyllrb.com/docs/installation/) and then run
`jekyll serve --baseurl ''`.
### Testing the project
To test JSZip in nodejs, use `npm run test-node`.
To test JSZip in a browser, you can open the file `test/index.html` in the
browser you want to test. Don't forget to update the dist/ files with `grunt`.
You can also test JSZip in a lot of browsers at once with
[SauceLabs](https://saucelabs.com/). You will need a SauceLabs account and two
variables into your environment. On linux, just use
```bash
export SAUCE_USERNAME=your-saucelabs-username
export SAUCE_ACCESS_KEY=your-saucelabs-access-key
```
before running the `npm run test-browser` command.
### Merging the changes
If you have tested bug fixes or new features, you can open a
[pull request](https://help.github.com/articles/using-pull-requests) on Github.

View File

@@ -0,0 +1,24 @@
ul.nav ul {
list-style:none;
margin: 0;
padding: 0 0 0 25px;
}
#downloader_application form {
margin-bottom: 10px;
}
#downloader_application ul {
list-style-type: none;
}
.browser_support th {
border-bottom-width: 3px !important;
}
.support_ie {border-bottom-color: #0275BA !important;}
.support_ff {border-bottom-color: #DF7215 !important;}
.support_sf {border-bottom-color: #43B3E9 !important;}
.support_cr {border-bottom-color: #39B642 !important;}
.support_op {border-bottom-color: #C42122 !important;}
.support_nd {border-bottom-color: #8CC84B !important;}

View File

@@ -0,0 +1,64 @@
/* Generated with :
* pygmentize -S default -f html > pygments.css
*/
.hll { background-color: #ffffcc }
.c { color: #408080; font-style: italic } /* Comment */
.err { border: 1px solid #FF0000 } /* Error */
.k { color: #008000; font-weight: bold } /* Keyword */
.o { color: #666666 } /* Operator */
.cm { color: #408080; font-style: italic } /* Comment.Multiline */
.cp { color: #BC7A00 } /* Comment.Preproc */
.c1 { color: #408080; font-style: italic } /* Comment.Single */
.cs { color: #408080; font-style: italic } /* Comment.Special */
.gd { color: #A00000 } /* Generic.Deleted */
.ge { font-style: italic } /* Generic.Emph */
.gr { color: #FF0000 } /* Generic.Error */
.gh { color: #000080; font-weight: bold } /* Generic.Heading */
.gi { color: #00A000 } /* Generic.Inserted */
.go { color: #888888 } /* Generic.Output */
.gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.gs { font-weight: bold } /* Generic.Strong */
.gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.gt { color: #0044DD } /* Generic.Traceback */
.kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.kp { color: #008000 } /* Keyword.Pseudo */
.kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.kt { color: #B00040 } /* Keyword.Type */
.m { color: #666666 } /* Literal.Number */
.s { color: #BA2121 } /* Literal.String */
.na { color: #7D9029 } /* Name.Attribute */
.nb { color: #008000 } /* Name.Builtin */
.nc { color: #0000FF; font-weight: bold } /* Name.Class */
.no { color: #880000 } /* Name.Constant */
.nd { color: #AA22FF } /* Name.Decorator */
.ni { color: #999999; font-weight: bold } /* Name.Entity */
.ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.nf { color: #0000FF } /* Name.Function */
.nl { color: #A0A000 } /* Name.Label */
.nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.nt { color: #008000; font-weight: bold } /* Name.Tag */
.nv { color: #19177C } /* Name.Variable */
.ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.w { color: #bbbbbb } /* Text.Whitespace */
.mf { color: #666666 } /* Literal.Number.Float */
.mh { color: #666666 } /* Literal.Number.Hex */
.mi { color: #666666 } /* Literal.Number.Integer */
.mo { color: #666666 } /* Literal.Number.Oct */
.sb { color: #BA2121 } /* Literal.String.Backtick */
.sc { color: #BA2121 } /* Literal.String.Char */
.sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.s2 { color: #BA2121 } /* Literal.String.Double */
.se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.sh { color: #BA2121 } /* Literal.String.Heredoc */
.si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.sx { color: #008000 } /* Literal.String.Other */
.sr { color: #BB6688 } /* Literal.String.Regex */
.s1 { color: #BA2121 } /* Literal.String.Single */
.ss { color: #19177C } /* Literal.String.Symbol */
.bp { color: #008000 } /* Name.Builtin.Pseudo */
.vc { color: #19177C } /* Name.Variable.Class */
.vg { color: #19177C } /* Name.Variable.Global */
.vi { color: #19177C } /* Name.Variable.Instance */
.il { color: #666666 } /* Literal.Number.Integer.Long */

115
vendors/jszip/documentation/examples.md vendored Normal file
View File

@@ -0,0 +1,115 @@
---
title: "How to use JSZip"
layout: default
section: example
---
An instance of JSZip represents a set of files. You can add them, remove them,
modify them. You can also import an existing zip file or generate one.
### Getting the object
#### In a browser
For a browser, there are two interesting files : `dist/jszip.js` and
`dist/jszip.min.js` (include just one).
If you use an AMD loader (RequireJS for example) JSZip will register itself :
you just have to put the js file at the right place, or configure the loader
(see [here for RequireJS](http://requirejs.org/docs/api.html#config-paths)).
Without any loader, JSZip will declare in the global scope a variable named `JSZip`.
#### In nodejs
In nodejs, you can `require` it :
```js
var JSZip = require("jszip");
```
### Basic manipulations
The first step is to create an instance of JSZip :
```js
var zip = new JSZip();
```
On this instance, we can add (and update) files and folders with
`.file(name, content)` and `.folder(name)`.
They return the current JSZip instance so you can chain the calls.
```js
// create a file
zip.file("hello.txt", "Hello[p my)6cxsw2q");
// oops, cat on keyboard. Fixing !
zip.file("hello.txt", "Hello World\n");
// create a file and a folder
zip.file("nested/hello.txt", "Hello World\n");
// same as
zip.folder("nested").file("hello.txt", "Hello World\n");
```
With `.folder(name)`, the returned object has a different root : if you add files
on this object, you will put them in the created subfolder. This is just a
view, the added files will also be in the "root" object.
```js
var photoZip = zip.folder("photos");
// this call will create photos/README
photoZip.file("README", "a folder with photos");
```
You can access the file content with `.file(name)` and
[its getters]({{site.baseurl}}/documentation/api_zipobject.html) :
```js
zip.file("hello.txt").asText(); // "Hello World\n"
if (JSZip.support.uint8array) {
zip.file("hello.txt").asUint8Array(); // Uint8Array { 0=72, 1=101, 2=108, more...}
}
```
You can also remove files or folders with `.remove(name)` :
```js
zip.remove("photos/README");
zip.remove("photos");
// same as
zip.remove("photos"); // by removing the folder, you also remove its content.
```
### Generate a zip file
With `.generate(options)` you can generate a zip file (not a real file but its
representation in memory). Check
[this page]({{site.baseurl}}/documentation/howto/write_zip.html) for more
informations on how to write / give the file to the user.
```js
var content = null;
if (JSZip.support.uint8array) {
content = zip.generate({type : "uint8array"});
} else {
content = zip.generate({type : "string"});
}
```
### Read a zip file
With `.load(data)` you can load a zip file. Check
[this page]({{site.baseurl}}/documentation/howto/read_zip.html) to see how to
do properly (it's more tricky that it seems).
```js
var new_zip = new JSZip();
// more files !
new_zip.load(content);
// you now have every files contained in the loaded zip
new_zip.file("hello.txt").asText(); // "Hello World\n"
```

View File

@@ -0,0 +1,59 @@
---
title: "Download the generated zip file"
layout: default
section: example
---
<p>Tip : check the source of the page !</p>
<h2>The FileSaver API</h2>
<div>
Works on firefox, chrome , opera &gt;= 15 and IE &gt;= 10 (but NOT in compatibility view).<br/>
<button id="blob" class="btn btn-primary">click to download</button>
</div>
<h2>The data URL</h2>
<div>
Does not work in IE, has restrictions on the length.<br/>
<button id="data_uri" class="btn btn-primary">click to download</button>
</div>
<script type="text/javascript">
(function () {
var zip = new JSZip();
zip.file("Hello.txt", "Hello world\n");
function bindEvent(el, eventName, eventHandler) {
if (el.addEventListener){
// standard way
el.addEventListener(eventName, eventHandler, false);
} else if (el.attachEvent){
// old IE
el.attachEvent('on'+eventName, eventHandler);
}
}
// Blob
var blobLink = document.getElementById('blob');
if (JSZip.support.blob) {
function downloadWithBlob() {
try {
var blob = zip.generate({type:"blob"});
// see FileSaver.js
saveAs(blob, "hello.zip");
} catch(e) {
blobLink.innerHTML += " " + e;
}
return false;
}
bindEvent(blobLink, 'click', downloadWithBlob);
} else {
blobLink.innerHTML += " (not supported on this browser)";
}
// data URI
function downloadWithDataURI() {
window.location = "data:application/zip;base64," + zip.generate({type:"base64"});
}
var dataUriLink = document.getElementById('data_uri');
bindEvent(dataUriLink, 'click', downloadWithDataURI);
})();
</script>

View File

@@ -0,0 +1,58 @@
---
title: "Mini app : Downloader"
layout: default
section: example
---
<p>Tip : check the source of the page !</p>
<p>
This mini application let you choose the files you want in a list, download
them, zip them and give the result to the user.
</p>
<p>
This demo requires a recent browser, see <a href="{{site.baseurl}}/documentation/howto/write_zip.html">
the howto</a>.
</p>
<div id="downloader_application">
<h3>Please select your files</h3>
<form action="#" id="download_form">
<ul>
<li>
<label>
<input type="checkbox" data-url="{{site.baseurl}}/test/ref/complex_files/Franz Kafka - The Metamorphosis.epub" checked />
Franz Kafka - The Metamorphosis.epub
</label>
</li>
<li>
<label>
<input type="checkbox" data-url="{{site.baseurl}}/documentation/css/pygments.css" checked />
pygments.css
</label>
</li>
<li>
<label>
<input type="checkbox" data-url="{{site.baseurl}}/dist/jszip.js" />
jszip.js
</label>
</li>
<li>
<label>
<input type="checkbox" data-url="{{site.baseurl}}/test/ref/all.zip" />
all.zip
</label>
</li>
</ul>
<button type="submit" class="btn btn-primary">pack them !</button>
</form>
<p class="hide" id="result"></p>
</div>
<script type="text/javascript" src="{{site.baseurl}}/documentation/examples/downloader.js"></script>

View File

@@ -0,0 +1,89 @@
jQuery(function ($) {
"use strict";
/**
* Reset the message.
*/
function resetMessage () {
$("#result")
.removeClass()
.text("");
}
/**
* show a successful message.
* @param {String} text the text to show.
*/
function showMessage(text) {
resetMessage();
$("#result")
.addClass("alert alert-success")
.text(text);
}
/**
* show an error message.
* @param {String} text the text to show.
*/
function showError(text) {
resetMessage();
$("#result")
.addClass("alert alert-danger")
.text(text);
}
/**
* Fetch the content, add it to the JSZip object
* and use a jQuery deferred to hold the result.
* @param {String} url the url of the content to fetch.
* @param {String} filename the filename to use in the JSZip object.
* @param {JSZip} zip the JSZip instance.
* @return {jQuery.Deferred} the deferred containing the data.
*/
function deferredAddZip(url, filename, zip) {
var deferred = $.Deferred();
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
deferred.reject(err);
} else {
zip.file(filename, data, {binary:true});
deferred.resolve(data);
}
});
return deferred;
}
if(!JSZip.support.blob) {
showError("This demo works only with a recent browser !");
return;
}
var $form = $("#download_form").on("submit", function () {
resetMessage();
var zip = new JSZip();
var deferreds = [];
// find every checked item
$(this).find(":checked").each(function () {
var $this = $(this);
var url = $this.data("url");
var filename = url.replace(/.*\//g, "");
deferreds.push(deferredAddZip(url, filename, zip));
});
// when everything has been downloaded, we can trigger the dl
$.when.apply($, deferreds).done(function () {
var blob = zip.generate({type:"blob"});
// see FileSaver.js
saveAs(blob, "example.zip");
showMessage("done !");
}).fail(function (err) {
showError(err);
});
return false;
});
});
// vim: set shiftwidth=4 softtabstop=4:

View File

@@ -0,0 +1,43 @@
---
title: "Get a file with an ajax call"
layout: default
section: example
---
<p>Tip : check the source of the page !</p>
<h3>With JSZipUtils</h3>
<div id="jszip_utils"></div>
<script type="text/javascript">
(function () {
function showError(elt, err) {
elt.innerHTML = "<p class='alert alert-danger'>" + err + "</p>";
}
function showContent(elt, type, content) {
elt.innerHTML = "<p class='alert alert-success'>loaded ! (as a " + type + ")<br/>" +
"Content = " + content + "</p>";
}
//=========================
// JSZipUtils
//=========================
JSZipUtils.getBinaryContent('{{site.baseurl}}/test/ref/text.zip', function(err, data) {
var elt = document.getElementById('jszip_utils');
if(err) {
showError(elt, err);
return;
}
try {
var zip = new JSZip(data);
showContent(elt, "" + data, zip.file("Hello.txt").asText());
} catch(e) {
showError(elt, e);
}
});
})();
</script>

View File

@@ -0,0 +1,87 @@
---
title: "Reading a local file with the File API"
layout: default
section: example
---
<h3>Choose the local(s) zip file(s)</h3>
<p class="note">Note : your browser will process the zip file, don't choose a file too big !</p>
<input type="file" id="file" name="file" multiple /><br />
<div id="error_block" class="alert alert-danger hidden">
You will need a recent browser to use this demo :(
</div>
<div id="result_block" class="hidden">
<h3>Content :</h3>
<div id="result"></div>
</div>
<script type="text/javascript" src="{{site.baseurl}}/test/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
(function () {
if (!window.FileReader || !window.ArrayBuffer) {
$("#error_block").removeClass("hidden").addClass("show");
return;
}
var $result = $("#result");
$("#file").on("change", function(evt) {
// remove content
$result.html("");
// be sure to show the results
$("#result_block").removeClass("hidden").addClass("show");
// see http://www.html5rocks.com/en/tutorials/file/dndfiles/
var files = evt.target.files;
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
var $title = $("<h4>", {
text : theFile.name
});
$result.append($title);
var $fileContent = $("<ul>");
try {
var dateBefore = new Date();
// read the content of the file with JSZip
var zip = new JSZip(e.target.result);
var dateAfter = new Date();
$title.append($("<span>", {
text:" (parsed in " + (dateAfter - dateBefore) + "ms)"
}));
// that, or a good ol' for(var entryName in zip.files)
$.each(zip.files, function (index, zipEntry) {
$fileContent.append($("<li>", {
text : zipEntry.name
}));
// the content is here : zipEntry.asText()
});
// end of the magic !
} catch(e) {
$fileContent = $("<div>", {
"class" : "alert alert-danger",
text : "Error reading " + theFile.name + " : " + e.message
});
}
$result.append($fileContent);
}
})(f);
// read the file !
// readAsArrayBuffer and readAsBinaryString both produce valid content for JSZip.
reader.readAsArrayBuffer(f);
// reader.readAsBinaryString(f);
}
});
})();
</script>

19
vendors/jszip/documentation/faq.md vendored Normal file
View File

@@ -0,0 +1,19 @@
---
title: "Frequently Asked Questions"
layout: default
section: main
---
### "Corrupted zip or bug : unexpected signature"
If you are sure that the zip file is correct, that error often comes from a
corrupted content. An ajax request, if not prepared correctly, will try to
decode the binary content as a text and corrupt it. See
[this page]({{site.baseurl}}/documentation/howto/read_zip.html).
### My browser crashes / becomes unresponsive / never finish the execution
That happens if you try to handle to much data. If possible, try again with a
small (some KB) zip file to see if your code is correct. See
[this page]({{site.baseurl}}/documentation/limitations.html) for more
informations.

View File

@@ -0,0 +1,152 @@
---
title: "How to read a file"
layout: default
section: example
---
This page explains how to read an existing zip file or add a existing file into
the zip file.
### In the browser
#### AJAX request
Getting binary data with an ajax request is hard (mainly because of IE <= 9).
The easy way is to use [JSZipUtils.getBinaryContent](https://github.com/stuk/jszip-utils).
With JSZipUtils.getBinaryContent, you can do the following (see the
documentation for more examples) :
```js
JSZipUtils.getBinaryContent('path/to/content.zip', function(err, data) {
if(err) {
throw err; // or handle err
}
var zip = new JSZip(data);
});
```
<br>
If you need to adapt an existing solution to what getBinaryContent does, here
are the details. When doing a XHR request (level 1, without setting the
`responseType`) the browser will try to interpret the response as a string and
decode it from its charset. To avoid this on Firefox/Chrome/Opera, you need to
set mime type : `xhr.overrideMimeType("text/plain; charset=x-user-defined");`.
On IE <= 9, this is harder. The overrideMimeType trick doesn't work so we need
to use [vbscript](http://stackoverflow.com/questions/1095102/how-do-i-load-binary-image-data-using-javascript-and-xmlhttprequest)
and non standard attributes.
On IE > 9, overrideMimeType doesn't work but xhr2 does.
With [xhr 2](http://caniuse.com/xhr2), you can just set the responseType
attribute : `xhr.responseType = "arraybuffer";`. With this, the browser will
return an ArrayBuffer.
#### Local files
If the browser supports the [FileReader API](http://caniuse.com/filereader),
you can use it to read a zip file. JSZip can read ArrayBuffer, so you can use
`FileReader.readAsArrayBuffer(Blob)`, see this [example]({{site.baseurl}}/documentation/examples/read-local-file-api.html).
### In nodejs
JSZip can read Buffers so you can do the following :
#### Local file
```js
"use strict";
var fs = require("fs");
var JSZip = require("jszip");
// read a zip file
fs.readFile("test.zip", function(err, data) {
if (err) throw err;
var zip = new JSZip(data);
});
// read a file and add it to a zip
fs.readFile("picture.png", function(err, data) {
if (err) throw err;
var zip = new JSZip();
zip.file("picture.png", data);
});
```
#### Remote file
There are a lot of nodejs libraries doing http requests, from the built-in
[http](http://nodejs.org/docs/latest/api/http.html) to the
[npm packages](https://www.npmjs.org/browse/keyword/http). Here are two
examples, one with the default http API, the other with
[request](https://github.com/mikeal/request) (but you're free to use your
favorite library !). If possible, download the file as a Buffer (you will get
better performances). If it's not possible, you can fallback to a binary string
(the option is likely to be `encoding : "binary"`).
##### With http :
```js
"use strict";
var http = require("http");
var url = require("url");
var JSZip = require("jszip");
var req = http.get(url.parse("http://localhost/.../file.zip"), function (res) {
if (res.statusCode !== 200) {
console.log(res.statusCode);
// handle error
return;
}
var data = [], dataLen = 0;
// don't set the encoding, it will break everything !
// or, if you must, set it to null. In that case the chunk will be a string.
res.on("data", function (chunk) {
data.push(chunk);
dataLen += chunk.length;
});
res.on("end", function () {
var buf = new Buffer(dataLen);
for (var i=0,len=data.length,pos=0; i<len; i++) {
data[i].copy(buf, pos);
pos += data[i].length;
}
// here we go !
var zip = new JSZip(buf);
console.log(zip.file("content.txt").asText());
});
});
req.on("error", function(err){
// handle error
});
```
##### With request :
```js
"use strict";
var request = require('request');
var JSZip = require("jszip");
request({
method : "GET",
url : "http://localhost/.../file.zip",
encoding: null // <- this one is important !
}, function (error, response, body) {
if(error || response.statusCode !== 200) {
// handle error
return;
}
var zip = new JSZip(body);
console.log(zip.file("content.txt").asText());
});
```

View File

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

View File

@@ -0,0 +1,88 @@
---
title: "Limitations of JSZip"
layout: default
section: limitations
fullpage: true
---
### Not supported features
All the features of zip files are not supported. Classic zip files will work
but encrypted zip, multi-volume, etc are not supported and the load() method
will throw an `Error`.
### ZIP64 and 32bit integers
ZIP64 files can be loaded, but only if the zip file is not "too big". ZIP64 uses 64bits integers
but Javascript represents all numbers as
[64-bit double precision IEEE 754 floating point numbers](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf)
(see section 8.5). So, we have 53bits for integers and
[bitwise operations treat everything as 32bits](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators).
So if all the 64bits integers can fit into 32 bits integers, everything will be
fine. If it's not the case, you will have other problems anyway (see next
limitation).
### Performance issues
An other limitation comes from the browser (and the machine running the
browser). A compressed zip file of 10MB is "easily" opened by firefox / chrome
/ opera / IE10+ but will crash older IE. Also keep in mind that strings in
javascript are encoded in UTF-16 : a 10MB ascii text file will take 20MB of
memory.
If you're having performance issues, please consider the following :
* Don't use IE &lt;= 9. Everything is better with typed arrays.
* Use typed arrays (Uint8Array, ArrayBuffer, etc) if possible :
* If you generate a zip file, you should use `type:"uint8array"`
(or blob, arraybuffer, nodebuffer).
* If you load the file from an ajax call, ask your XHR an ArrayBuffer.
Loading a string is asking for troubles.
* Don't use compression (see below).
* If you want to get the content of an ASCII file as a string, consider using
`asBinary()` instead of `asText()`. The transformation
"binary string" -&gt; "unicode string" is a consuming process.
Note about compression :
When reading a file, JSZip will store the content without decompressing it.
When generating a compressed file, JSZip will reuse if possible compressed
content :
* If you read a zip file compressed with DEFLATE and call `generate` with the
DEFLATE compression, JSZip won't call the compression algorithms (same with
STORE everywhere.)
* If you read a zip file compressed with DEFLATE and call `generate` with the
STORE compression, JSZip will have to decompress everything.
On IE &lt;=9, typed arrays are not supported and the compression algorithm
will fallback on arrays. In that case, JSZip needs to convert the binary string
into an array, DEFLATE it and convert the result into a binary string.
You don't want that to happen.
### The output zip will differ from the input zip
Reading and generating a zip file won't give you back the same file.
Some data are discarded (file metadata) and other are added (subfolders).
### Encodings support
JSZip only supports UTF-8 natively. A zip file doesn't contain the name of the
encoding used, you need to know it before doing anything.
#### File name
If the name of a file inside the zip is encoded with UTF-8 then JSZip can
detect it (Language encoding flag, Unicode Path Extra Field). If not, JSZip
can't detect the encoding used and will generate [Mojibake](https://en.wikipedia.org/wiki/Mojibake).
You can use the [encodeFileName]({{site.baseurl}}/documentation/api_jszip/generate.html)
option and the [decodeFileName]({{site.baseurl}}/documentation/api_jszip/load.html)
option to encode/decode using a custom encoding.
#### File content
The `asText()` method uses UTF-8 to decode the content. If you have a text in
a different encoding, you can get the bytes array with `asUint8Array()` and
decode it with a lib (iconv, iconv-lite, etc) on your side.
To save a text using a non-UTF-8 encoding, do the same : encode it into a
Uint8Array before adding it to JSZip.

View File

@@ -0,0 +1,57 @@
---
title: Upgrade Guide
layout: default
section: main
---
### From 2.2.2 to 2.3.0
* On `ZipObject#options`, the attributes `date` and `dir` have been
deprecated and are now on `ZipObject`.
* On `ZipObject#options`, the attributes `base64` and `binary` have been
deprecated.
* `JSZip.base64`, `JSZip.prototype.crc32`, `JSZip.prototype.utf8decode`,
`JSZip.prototype.utf8encode` and `JSZip.utils` have been deprecated.
```js
// deprecated
zip.file("test.txt").options.date
zip.file("test.txt").options.dir
// new API
zip.file("test.txt").date
zip.file("test.txt").dir
```
### From 2.0.0 to 2.1.0
* The packaging changed : instead of loading jszip.js, jszip-load.js,
jszip-inflate.js, jszip-deflate.js, just include dist/jszip.js or
dist/jszip.min.js.
For AMD loader users : JSZip now registers itself. You just have to put the
file at the right place or configure your loader.
### From 1.x to 2.x
* `JSZipBase64` has been renamed to `JSZip.base64`.
* The `data` attribute doesn't exist anymore :
use the getters `asText()`, `asBinary()`, etc
* The compression/decompression methods now give their input type with the
`compressInputType` and `uncompressInputType` attributes.
Example for the data attribute :
```js
// before
zip.file("test.txt").data;
zip.files["test.txt"].data;
zip.file("image.png").data;
zip.files["image.png"].data;
// after
zip.file("test.txt").asText();
zip.files["test.txt"].asText();
zip.file("image.png").asBinary();
zip.files["image.png"].asBinary();
```