1
0
mirror of https://gitlab.com/JKANetwork/CheckServer.git synced 2026-06-18 22:26:18 +02: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
+23
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();
```
@@ -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);
```
+90
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
```
+46
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
```
+49
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 () {...}, ...}
```
+43
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;
});
```
+34
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
```
+40
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
```
+161
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');
}
});
```
+105
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');
}
});
```
+37
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
```
+16
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.