UrgentcareCLI 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +60 -25
- data/Notes +1 -1
- data/README.md +5 -5
- data/Rakefile +2 -0
- data/UrgentCare.gemspec +3 -3
- data/background.jpg +0 -0
- data/lib/UrgentCare.rb +3 -0
- data/lib/UrgentCare/CLI.rb +6 -2
- data/lib/UrgentCare/version.rb +1 -1
- data/lib/Urgentcare/Scraper.rb +65 -23
- data/node_modules/.bin/rimraf +1 -0
- data/node_modules/.package-lock.json +250 -0
- data/node_modules/balanced-match/.github/FUNDING.yml +2 -0
- data/node_modules/balanced-match/LICENSE.md +21 -0
- data/node_modules/balanced-match/README.md +97 -0
- data/node_modules/balanced-match/index.js +62 -0
- data/node_modules/balanced-match/package.json +48 -0
- data/node_modules/brace-expansion/LICENSE +21 -0
- data/node_modules/brace-expansion/README.md +129 -0
- data/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/brace-expansion/package.json +47 -0
- data/node_modules/concat-map/.travis.yml +4 -0
- data/node_modules/concat-map/LICENSE +18 -0
- data/node_modules/concat-map/README.markdown +62 -0
- data/node_modules/concat-map/example/map.js +6 -0
- data/node_modules/concat-map/index.js +13 -0
- data/node_modules/concat-map/package.json +43 -0
- data/node_modules/concat-map/test/map.js +39 -0
- data/node_modules/core-util-is/LICENSE +19 -0
- data/node_modules/core-util-is/README.md +3 -0
- data/node_modules/core-util-is/float.patch +604 -0
- data/node_modules/core-util-is/lib/util.js +107 -0
- data/node_modules/core-util-is/package.json +32 -0
- data/node_modules/core-util-is/test.js +68 -0
- data/node_modules/fs.realpath/LICENSE +43 -0
- data/node_modules/fs.realpath/README.md +33 -0
- data/node_modules/fs.realpath/index.js +66 -0
- data/node_modules/fs.realpath/old.js +303 -0
- data/node_modules/fs.realpath/package.json +26 -0
- data/node_modules/glob/LICENSE +21 -0
- data/node_modules/glob/README.md +375 -0
- data/node_modules/glob/changelog.md +67 -0
- data/node_modules/glob/common.js +234 -0
- data/node_modules/glob/glob.js +788 -0
- data/node_modules/glob/package.json +51 -0
- data/node_modules/glob/sync.js +484 -0
- data/node_modules/immediate/LICENSE.txt +20 -0
- data/node_modules/immediate/README.md +93 -0
- data/node_modules/immediate/dist/immediate.js +75 -0
- data/node_modules/immediate/dist/immediate.min.js +1 -0
- data/node_modules/immediate/lib/browser.js +69 -0
- data/node_modules/immediate/lib/index.js +73 -0
- data/node_modules/immediate/package.json +42 -0
- data/node_modules/inflight/LICENSE +15 -0
- data/node_modules/inflight/README.md +37 -0
- data/node_modules/inflight/inflight.js +54 -0
- data/node_modules/inflight/package.json +29 -0
- data/node_modules/inherits/LICENSE +16 -0
- data/node_modules/inherits/README.md +42 -0
- data/node_modules/inherits/inherits.js +9 -0
- data/node_modules/inherits/inherits_browser.js +27 -0
- data/node_modules/inherits/package.json +29 -0
- data/node_modules/isarray/.npmignore +1 -0
- data/node_modules/isarray/.travis.yml +4 -0
- data/node_modules/isarray/Makefile +6 -0
- data/node_modules/isarray/README.md +60 -0
- data/node_modules/isarray/component.json +19 -0
- data/node_modules/isarray/index.js +5 -0
- data/node_modules/isarray/package.json +45 -0
- data/node_modules/isarray/test.js +20 -0
- data/node_modules/jszip/.codeclimate.yml +16 -0
- data/node_modules/jszip/.editorconfig +8 -0
- data/node_modules/jszip/.jshintignore +1 -0
- data/node_modules/jszip/.jshintrc +21 -0
- data/node_modules/jszip/.travis.yml +17 -0
- data/node_modules/jszip/CHANGES.md +163 -0
- data/node_modules/jszip/LICENSE.markdown +651 -0
- data/node_modules/jszip/README.markdown +35 -0
- data/node_modules/jszip/dist/jszip.js +30 -0
- data/node_modules/jszip/dist/jszip.min.js +13 -0
- data/node_modules/jszip/index.d.ts +270 -0
- data/node_modules/jszip/lib/base64.js +106 -0
- data/node_modules/jszip/lib/compressedObject.js +74 -0
- data/node_modules/jszip/lib/compressions.js +14 -0
- data/node_modules/jszip/lib/crc32.js +77 -0
- data/node_modules/jszip/lib/defaults.js +11 -0
- data/node_modules/jszip/lib/external.js +19 -0
- data/node_modules/jszip/lib/flate.js +85 -0
- data/node_modules/jszip/lib/generate/ZipFileWorker.js +540 -0
- data/node_modules/jszip/lib/generate/index.js +57 -0
- data/node_modules/jszip/lib/index.js +52 -0
- data/node_modules/jszip/lib/license_header.js +11 -0
- data/node_modules/jszip/lib/load.js +81 -0
- data/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +74 -0
- data/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +42 -0
- data/node_modules/jszip/lib/nodejsUtils.js +57 -0
- data/node_modules/jszip/lib/object.js +389 -0
- data/node_modules/jszip/lib/readable-stream-browser.js +9 -0
- data/node_modules/jszip/lib/reader/ArrayReader.js +57 -0
- data/node_modules/jszip/lib/reader/DataReader.js +116 -0
- data/node_modules/jszip/lib/reader/NodeBufferReader.js +19 -0
- data/node_modules/jszip/lib/reader/StringReader.js +38 -0
- data/node_modules/jszip/lib/reader/Uint8ArrayReader.js +22 -0
- data/node_modules/jszip/lib/reader/readerFor.js +28 -0
- data/node_modules/jszip/lib/signature.js +7 -0
- data/node_modules/jszip/lib/stream/ConvertWorker.js +26 -0
- data/node_modules/jszip/lib/stream/Crc32Probe.js +24 -0
- data/node_modules/jszip/lib/stream/DataLengthProbe.js +29 -0
- data/node_modules/jszip/lib/stream/DataWorker.js +116 -0
- data/node_modules/jszip/lib/stream/GenericWorker.js +263 -0
- data/node_modules/jszip/lib/stream/StreamHelper.js +212 -0
- data/node_modules/jszip/lib/support.js +38 -0
- data/node_modules/jszip/lib/utf8.js +275 -0
- data/node_modules/jszip/lib/utils.js +476 -0
- data/node_modules/jszip/lib/zipEntries.js +262 -0
- data/node_modules/jszip/lib/zipEntry.js +294 -0
- data/node_modules/jszip/lib/zipObject.js +133 -0
- data/node_modules/jszip/package.json +63 -0
- data/node_modules/jszip/vendor/FileSaver.js +247 -0
- data/node_modules/lie/README.md +62 -0
- data/node_modules/lie/dist/lie.js +350 -0
- data/node_modules/lie/dist/lie.min.js +1 -0
- data/node_modules/lie/dist/lie.polyfill.js +358 -0
- data/node_modules/lie/dist/lie.polyfill.min.js +1 -0
- data/node_modules/lie/lib/browser.js +273 -0
- data/node_modules/lie/lib/index.js +298 -0
- data/node_modules/lie/license.md +7 -0
- data/node_modules/lie/lie.d.ts +244 -0
- data/node_modules/lie/package.json +69 -0
- data/node_modules/lie/polyfill.js +4 -0
- data/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/minimatch/README.md +209 -0
- data/node_modules/minimatch/minimatch.js +923 -0
- data/node_modules/minimatch/package.json +30 -0
- data/node_modules/once/LICENSE +15 -0
- data/node_modules/once/README.md +79 -0
- data/node_modules/once/once.js +42 -0
- data/node_modules/once/package.json +33 -0
- data/node_modules/pako/CHANGELOG.md +164 -0
- data/node_modules/pako/LICENSE +21 -0
- data/node_modules/pako/README.md +191 -0
- data/node_modules/pako/dist/pako.js +6818 -0
- data/node_modules/pako/dist/pako.min.js +1 -0
- data/node_modules/pako/dist/pako_deflate.js +3997 -0
- data/node_modules/pako/dist/pako_deflate.min.js +1 -0
- data/node_modules/pako/dist/pako_inflate.js +3300 -0
- data/node_modules/pako/dist/pako_inflate.min.js +1 -0
- data/node_modules/pako/index.js +14 -0
- data/node_modules/pako/lib/deflate.js +400 -0
- data/node_modules/pako/lib/inflate.js +423 -0
- data/node_modules/pako/lib/utils/common.js +105 -0
- data/node_modules/pako/lib/utils/strings.js +187 -0
- data/node_modules/pako/lib/zlib/README +59 -0
- data/node_modules/pako/lib/zlib/adler32.js +51 -0
- data/node_modules/pako/lib/zlib/constants.js +68 -0
- data/node_modules/pako/lib/zlib/crc32.js +59 -0
- data/node_modules/pako/lib/zlib/deflate.js +1874 -0
- data/node_modules/pako/lib/zlib/gzheader.js +58 -0
- data/node_modules/pako/lib/zlib/inffast.js +345 -0
- data/node_modules/pako/lib/zlib/inflate.js +1556 -0
- data/node_modules/pako/lib/zlib/inftrees.js +343 -0
- data/node_modules/pako/lib/zlib/messages.js +32 -0
- data/node_modules/pako/lib/zlib/trees.js +1222 -0
- data/node_modules/pako/lib/zlib/zstream.js +47 -0
- data/node_modules/pako/package.json +44 -0
- data/node_modules/path-is-absolute/index.js +20 -0
- data/node_modules/path-is-absolute/license +21 -0
- data/node_modules/path-is-absolute/package.json +43 -0
- data/node_modules/path-is-absolute/readme.md +59 -0
- data/node_modules/process-nextick-args/index.js +45 -0
- data/node_modules/process-nextick-args/license.md +19 -0
- data/node_modules/process-nextick-args/package.json +25 -0
- data/node_modules/process-nextick-args/readme.md +18 -0
- data/node_modules/readable-stream/.travis.yml +34 -0
- data/node_modules/readable-stream/CONTRIBUTING.md +38 -0
- data/node_modules/readable-stream/GOVERNANCE.md +136 -0
- data/node_modules/readable-stream/LICENSE +47 -0
- data/node_modules/readable-stream/README.md +58 -0
- data/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +60 -0
- data/node_modules/readable-stream/duplex-browser.js +1 -0
- data/node_modules/readable-stream/duplex.js +1 -0
- data/node_modules/readable-stream/lib/_stream_duplex.js +131 -0
- data/node_modules/readable-stream/lib/_stream_passthrough.js +47 -0
- data/node_modules/readable-stream/lib/_stream_readable.js +1019 -0
- data/node_modules/readable-stream/lib/_stream_transform.js +214 -0
- data/node_modules/readable-stream/lib/_stream_writable.js +687 -0
- data/node_modules/readable-stream/lib/internal/streams/BufferList.js +79 -0
- data/node_modules/readable-stream/lib/internal/streams/destroy.js +74 -0
- data/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
- data/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
- data/node_modules/readable-stream/package.json +52 -0
- data/node_modules/readable-stream/passthrough.js +1 -0
- data/node_modules/readable-stream/readable-browser.js +7 -0
- data/node_modules/readable-stream/readable.js +19 -0
- data/node_modules/readable-stream/transform.js +1 -0
- data/node_modules/readable-stream/writable-browser.js +1 -0
- data/node_modules/readable-stream/writable.js +8 -0
- data/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/rimraf/README.md +101 -0
- data/node_modules/rimraf/bin.js +50 -0
- data/node_modules/rimraf/package.json +29 -0
- data/node_modules/rimraf/rimraf.js +372 -0
- data/node_modules/safe-buffer/LICENSE +21 -0
- data/node_modules/safe-buffer/README.md +584 -0
- data/node_modules/safe-buffer/index.d.ts +187 -0
- data/node_modules/safe-buffer/index.js +62 -0
- data/node_modules/safe-buffer/package.json +37 -0
- data/node_modules/selenium-webdriver/CHANGES.md +1114 -0
- data/node_modules/selenium-webdriver/LICENSE +202 -0
- data/node_modules/selenium-webdriver/NOTICE +2 -0
- data/node_modules/selenium-webdriver/README.md +229 -0
- data/node_modules/selenium-webdriver/chrome.js +295 -0
- data/node_modules/selenium-webdriver/chromium.js +829 -0
- data/node_modules/selenium-webdriver/devtools/CDPConnection.js +35 -0
- data/node_modules/selenium-webdriver/edge.js +224 -0
- data/node_modules/selenium-webdriver/example/chrome_android.js +45 -0
- data/node_modules/selenium-webdriver/example/chrome_mobile_emulation.js +46 -0
- data/node_modules/selenium-webdriver/example/firefox_channels.js +84 -0
- data/node_modules/selenium-webdriver/example/google_search.js +50 -0
- data/node_modules/selenium-webdriver/example/google_search_test.js +70 -0
- data/node_modules/selenium-webdriver/example/headless.js +63 -0
- data/node_modules/selenium-webdriver/example/logging.js +64 -0
- data/node_modules/selenium-webdriver/firefox.js +789 -0
- data/node_modules/selenium-webdriver/http/index.js +324 -0
- data/node_modules/selenium-webdriver/http/util.js +172 -0
- data/node_modules/selenium-webdriver/ie.js +503 -0
- data/node_modules/selenium-webdriver/index.js +825 -0
- data/node_modules/selenium-webdriver/io/exec.js +162 -0
- data/node_modules/selenium-webdriver/io/index.js +348 -0
- data/node_modules/selenium-webdriver/io/zip.js +223 -0
- data/node_modules/selenium-webdriver/lib/atoms/find-elements.js +123 -0
- data/node_modules/selenium-webdriver/lib/atoms/get-attribute.js +101 -0
- data/node_modules/selenium-webdriver/lib/atoms/is-displayed.js +101 -0
- data/node_modules/selenium-webdriver/lib/atoms/mutation-listener.js +55 -0
- data/node_modules/selenium-webdriver/lib/by.js +415 -0
- data/node_modules/selenium-webdriver/lib/capabilities.js +553 -0
- data/node_modules/selenium-webdriver/lib/command.js +206 -0
- data/node_modules/selenium-webdriver/lib/error.js +605 -0
- data/node_modules/selenium-webdriver/lib/http.js +704 -0
- data/node_modules/selenium-webdriver/lib/input.js +946 -0
- data/node_modules/selenium-webdriver/lib/logging.js +661 -0
- data/node_modules/selenium-webdriver/lib/promise.js +285 -0
- data/node_modules/selenium-webdriver/lib/proxy.js +212 -0
- data/node_modules/selenium-webdriver/lib/session.js +77 -0
- data/node_modules/selenium-webdriver/lib/symbols.js +37 -0
- data/node_modules/selenium-webdriver/lib/until.js +429 -0
- data/node_modules/selenium-webdriver/lib/webdriver.js +2919 -0
- data/node_modules/selenium-webdriver/net/index.js +107 -0
- data/node_modules/selenium-webdriver/net/portprober.js +75 -0
- data/node_modules/selenium-webdriver/opera.js +406 -0
- data/node_modules/selenium-webdriver/package.json +54 -0
- data/node_modules/selenium-webdriver/proxy.js +32 -0
- data/node_modules/selenium-webdriver/remote/index.js +624 -0
- data/node_modules/selenium-webdriver/safari.js +168 -0
- data/node_modules/selenium-webdriver/testing/index.js +504 -0
- data/node_modules/set-immediate-shim/index.js +7 -0
- data/node_modules/set-immediate-shim/package.json +34 -0
- data/node_modules/set-immediate-shim/readme.md +31 -0
- data/node_modules/string_decoder/.travis.yml +50 -0
- data/node_modules/string_decoder/LICENSE +48 -0
- data/node_modules/string_decoder/README.md +47 -0
- data/node_modules/string_decoder/lib/string_decoder.js +296 -0
- data/node_modules/string_decoder/package.json +31 -0
- data/node_modules/tmp/CHANGELOG.md +288 -0
- data/node_modules/tmp/LICENSE +21 -0
- data/node_modules/tmp/README.md +365 -0
- data/node_modules/tmp/lib/tmp.js +780 -0
- data/node_modules/tmp/node_modules/.bin/rimraf +1 -0
- data/node_modules/tmp/node_modules/rimraf/CHANGELOG.md +65 -0
- data/node_modules/tmp/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/tmp/node_modules/rimraf/README.md +101 -0
- data/node_modules/tmp/node_modules/rimraf/bin.js +68 -0
- data/node_modules/tmp/node_modules/rimraf/package.json +32 -0
- data/node_modules/tmp/node_modules/rimraf/rimraf.js +360 -0
- data/node_modules/tmp/package.json +58 -0
- data/node_modules/util-deprecate/History.md +16 -0
- data/node_modules/util-deprecate/LICENSE +24 -0
- data/node_modules/util-deprecate/README.md +53 -0
- data/node_modules/util-deprecate/browser.js +67 -0
- data/node_modules/util-deprecate/node.js +6 -0
- data/node_modules/util-deprecate/package.json +27 -0
- data/node_modules/wrappy/LICENSE +15 -0
- data/node_modules/wrappy/README.md +36 -0
- data/node_modules/wrappy/package.json +29 -0
- data/node_modules/wrappy/wrappy.js +33 -0
- data/node_modules/ws/LICENSE +21 -0
- data/node_modules/ws/README.md +496 -0
- data/node_modules/ws/browser.js +8 -0
- data/node_modules/ws/index.js +10 -0
- data/node_modules/ws/lib/buffer-util.js +129 -0
- data/node_modules/ws/lib/constants.js +10 -0
- data/node_modules/ws/lib/event-target.js +184 -0
- data/node_modules/ws/lib/extension.js +223 -0
- data/node_modules/ws/lib/limiter.js +55 -0
- data/node_modules/ws/lib/permessage-deflate.js +517 -0
- data/node_modules/ws/lib/receiver.js +507 -0
- data/node_modules/ws/lib/sender.js +405 -0
- data/node_modules/ws/lib/stream.js +165 -0
- data/node_modules/ws/lib/validation.js +104 -0
- data/node_modules/ws/lib/websocket-server.js +418 -0
- data/node_modules/ws/lib/websocket.js +942 -0
- data/node_modules/ws/package.json +56 -0
- data/package-lock.json +458 -0
- data/package.json +5 -0
- data/selenium.log +1 -0
- metadata +314 -19
@@ -0,0 +1,57 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var compressions = require('../compressions');
|
4
|
+
var ZipFileWorker = require('./ZipFileWorker');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Find the compression to use.
|
8
|
+
* @param {String} fileCompression the compression defined at the file level, if any.
|
9
|
+
* @param {String} zipCompression the compression defined at the load() level.
|
10
|
+
* @return {Object} the compression object to use.
|
11
|
+
*/
|
12
|
+
var getCompression = function (fileCompression, zipCompression) {
|
13
|
+
|
14
|
+
var compressionName = fileCompression || zipCompression;
|
15
|
+
var compression = compressions[compressionName];
|
16
|
+
if (!compression) {
|
17
|
+
throw new Error(compressionName + " is not a valid compression method !");
|
18
|
+
}
|
19
|
+
return compression;
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Create a worker to generate a zip file.
|
24
|
+
* @param {JSZip} zip the JSZip instance at the right root level.
|
25
|
+
* @param {Object} options to generate the zip file.
|
26
|
+
* @param {String} comment the comment to use.
|
27
|
+
*/
|
28
|
+
exports.generateWorker = function (zip, options, comment) {
|
29
|
+
|
30
|
+
var zipFileWorker = new ZipFileWorker(options.streamFiles, comment, options.platform, options.encodeFileName);
|
31
|
+
var entriesCount = 0;
|
32
|
+
try {
|
33
|
+
|
34
|
+
zip.forEach(function (relativePath, file) {
|
35
|
+
entriesCount++;
|
36
|
+
var compression = getCompression(file.options.compression, options.compression);
|
37
|
+
var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
|
38
|
+
var dir = file.dir, date = file.date;
|
39
|
+
|
40
|
+
file._compressWorker(compression, compressionOptions)
|
41
|
+
.withStreamInfo("file", {
|
42
|
+
name : relativePath,
|
43
|
+
dir : dir,
|
44
|
+
date : date,
|
45
|
+
comment : file.comment || "",
|
46
|
+
unixPermissions : file.unixPermissions,
|
47
|
+
dosPermissions : file.dosPermissions
|
48
|
+
})
|
49
|
+
.pipe(zipFileWorker);
|
50
|
+
});
|
51
|
+
zipFileWorker.entriesCount = entriesCount;
|
52
|
+
} catch (e) {
|
53
|
+
zipFileWorker.error(e);
|
54
|
+
}
|
55
|
+
|
56
|
+
return zipFileWorker;
|
57
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Representation a of zip file in js
|
5
|
+
* @constructor
|
6
|
+
*/
|
7
|
+
function JSZip() {
|
8
|
+
// if this constructor is used without `new`, it adds `new` before itself:
|
9
|
+
if(!(this instanceof JSZip)) {
|
10
|
+
return new JSZip();
|
11
|
+
}
|
12
|
+
|
13
|
+
if(arguments.length) {
|
14
|
+
throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
|
15
|
+
}
|
16
|
+
|
17
|
+
// object containing the files :
|
18
|
+
// {
|
19
|
+
// "folder/" : {...},
|
20
|
+
// "folder/data.txt" : {...}
|
21
|
+
// }
|
22
|
+
this.files = {};
|
23
|
+
|
24
|
+
this.comment = null;
|
25
|
+
|
26
|
+
// Where we are in the hierarchy
|
27
|
+
this.root = "";
|
28
|
+
this.clone = function() {
|
29
|
+
var newObj = new JSZip();
|
30
|
+
for (var i in this) {
|
31
|
+
if (typeof this[i] !== "function") {
|
32
|
+
newObj[i] = this[i];
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return newObj;
|
36
|
+
};
|
37
|
+
}
|
38
|
+
JSZip.prototype = require('./object');
|
39
|
+
JSZip.prototype.loadAsync = require('./load');
|
40
|
+
JSZip.support = require('./support');
|
41
|
+
JSZip.defaults = require('./defaults');
|
42
|
+
|
43
|
+
// TODO find a better way to handle this version,
|
44
|
+
// a require('package.json').version doesn't work with webpack, see #327
|
45
|
+
JSZip.version = "3.6.0";
|
46
|
+
|
47
|
+
JSZip.loadAsync = function (content, options) {
|
48
|
+
return new JSZip().loadAsync(content, options);
|
49
|
+
};
|
50
|
+
|
51
|
+
JSZip.external = require("./external");
|
52
|
+
module.exports = JSZip;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/*!
|
2
|
+
|
3
|
+
JSZip v__VERSION__ - A JavaScript class for generating and reading zip files
|
4
|
+
<http://stuartk.com/jszip>
|
5
|
+
|
6
|
+
(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
|
7
|
+
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/master/LICENSE.markdown.
|
8
|
+
|
9
|
+
JSZip uses the library pako released under the MIT license :
|
10
|
+
https://github.com/nodeca/pako/blob/master/LICENSE
|
11
|
+
*/
|
@@ -0,0 +1,81 @@
|
|
1
|
+
'use strict';
|
2
|
+
var utils = require('./utils');
|
3
|
+
var external = require("./external");
|
4
|
+
var utf8 = require('./utf8');
|
5
|
+
var ZipEntries = require('./zipEntries');
|
6
|
+
var Crc32Probe = require('./stream/Crc32Probe');
|
7
|
+
var nodejsUtils = require("./nodejsUtils");
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Check the CRC32 of an entry.
|
11
|
+
* @param {ZipEntry} zipEntry the zip entry to check.
|
12
|
+
* @return {Promise} the result.
|
13
|
+
*/
|
14
|
+
function checkEntryCRC32(zipEntry) {
|
15
|
+
return new external.Promise(function (resolve, reject) {
|
16
|
+
var worker = zipEntry.decompressed.getContentWorker().pipe(new Crc32Probe());
|
17
|
+
worker.on("error", function (e) {
|
18
|
+
reject(e);
|
19
|
+
})
|
20
|
+
.on("end", function () {
|
21
|
+
if (worker.streamInfo.crc32 !== zipEntry.decompressed.crc32) {
|
22
|
+
reject(new Error("Corrupted zip : CRC32 mismatch"));
|
23
|
+
} else {
|
24
|
+
resolve();
|
25
|
+
}
|
26
|
+
})
|
27
|
+
.resume();
|
28
|
+
});
|
29
|
+
}
|
30
|
+
|
31
|
+
module.exports = function (data, options) {
|
32
|
+
var zip = this;
|
33
|
+
options = utils.extend(options || {}, {
|
34
|
+
base64: false,
|
35
|
+
checkCRC32: false,
|
36
|
+
optimizedBinaryString: false,
|
37
|
+
createFolders: false,
|
38
|
+
decodeFileName: utf8.utf8decode
|
39
|
+
});
|
40
|
+
|
41
|
+
if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {
|
42
|
+
return external.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file."));
|
43
|
+
}
|
44
|
+
|
45
|
+
return utils.prepareContent("the loaded zip file", data, true, options.optimizedBinaryString, options.base64)
|
46
|
+
.then(function (data) {
|
47
|
+
var zipEntries = new ZipEntries(options);
|
48
|
+
zipEntries.load(data);
|
49
|
+
return zipEntries;
|
50
|
+
}).then(function checkCRC32(zipEntries) {
|
51
|
+
var promises = [external.Promise.resolve(zipEntries)];
|
52
|
+
var files = zipEntries.files;
|
53
|
+
if (options.checkCRC32) {
|
54
|
+
for (var i = 0; i < files.length; i++) {
|
55
|
+
promises.push(checkEntryCRC32(files[i]));
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return external.Promise.all(promises);
|
59
|
+
}).then(function addFiles(results) {
|
60
|
+
var zipEntries = results.shift();
|
61
|
+
var files = zipEntries.files;
|
62
|
+
for (var i = 0; i < files.length; i++) {
|
63
|
+
var input = files[i];
|
64
|
+
zip.file(input.fileNameStr, input.decompressed, {
|
65
|
+
binary: true,
|
66
|
+
optimizedBinaryString: true,
|
67
|
+
date: input.date,
|
68
|
+
dir: input.dir,
|
69
|
+
comment: input.fileCommentStr.length ? input.fileCommentStr : null,
|
70
|
+
unixPermissions: input.unixPermissions,
|
71
|
+
dosPermissions: input.dosPermissions,
|
72
|
+
createFolders: options.createFolders
|
73
|
+
});
|
74
|
+
}
|
75
|
+
if (zipEntries.zipComment.length) {
|
76
|
+
zip.comment = zipEntries.zipComment;
|
77
|
+
}
|
78
|
+
|
79
|
+
return zip;
|
80
|
+
});
|
81
|
+
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require('../utils');
|
4
|
+
var GenericWorker = require('../stream/GenericWorker');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* A worker that use a nodejs stream as source.
|
8
|
+
* @constructor
|
9
|
+
* @param {String} filename the name of the file entry for this stream.
|
10
|
+
* @param {Readable} stream the nodejs stream.
|
11
|
+
*/
|
12
|
+
function NodejsStreamInputAdapter(filename, stream) {
|
13
|
+
GenericWorker.call(this, "Nodejs stream input adapter for " + filename);
|
14
|
+
this._upstreamEnded = false;
|
15
|
+
this._bindStream(stream);
|
16
|
+
}
|
17
|
+
|
18
|
+
utils.inherits(NodejsStreamInputAdapter, GenericWorker);
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Prepare the stream and bind the callbacks on it.
|
22
|
+
* Do this ASAP on node 0.10 ! A lazy binding doesn't always work.
|
23
|
+
* @param {Stream} stream the nodejs stream to use.
|
24
|
+
*/
|
25
|
+
NodejsStreamInputAdapter.prototype._bindStream = function (stream) {
|
26
|
+
var self = this;
|
27
|
+
this._stream = stream;
|
28
|
+
stream.pause();
|
29
|
+
stream
|
30
|
+
.on("data", function (chunk) {
|
31
|
+
self.push({
|
32
|
+
data: chunk,
|
33
|
+
meta : {
|
34
|
+
percent : 0
|
35
|
+
}
|
36
|
+
});
|
37
|
+
})
|
38
|
+
.on("error", function (e) {
|
39
|
+
if(self.isPaused) {
|
40
|
+
this.generatedError = e;
|
41
|
+
} else {
|
42
|
+
self.error(e);
|
43
|
+
}
|
44
|
+
})
|
45
|
+
.on("end", function () {
|
46
|
+
if(self.isPaused) {
|
47
|
+
self._upstreamEnded = true;
|
48
|
+
} else {
|
49
|
+
self.end();
|
50
|
+
}
|
51
|
+
});
|
52
|
+
};
|
53
|
+
NodejsStreamInputAdapter.prototype.pause = function () {
|
54
|
+
if(!GenericWorker.prototype.pause.call(this)) {
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
this._stream.pause();
|
58
|
+
return true;
|
59
|
+
};
|
60
|
+
NodejsStreamInputAdapter.prototype.resume = function () {
|
61
|
+
if(!GenericWorker.prototype.resume.call(this)) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
|
65
|
+
if(this._upstreamEnded) {
|
66
|
+
this.end();
|
67
|
+
} else {
|
68
|
+
this._stream.resume();
|
69
|
+
}
|
70
|
+
|
71
|
+
return true;
|
72
|
+
};
|
73
|
+
|
74
|
+
module.exports = NodejsStreamInputAdapter;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var Readable = require('readable-stream').Readable;
|
4
|
+
|
5
|
+
var utils = require('../utils');
|
6
|
+
utils.inherits(NodejsStreamOutputAdapter, Readable);
|
7
|
+
|
8
|
+
/**
|
9
|
+
* A nodejs stream using a worker as source.
|
10
|
+
* @see the SourceWrapper in http://nodejs.org/api/stream.html
|
11
|
+
* @constructor
|
12
|
+
* @param {StreamHelper} helper the helper wrapping the worker
|
13
|
+
* @param {Object} options the nodejs stream options
|
14
|
+
* @param {Function} updateCb the update callback.
|
15
|
+
*/
|
16
|
+
function NodejsStreamOutputAdapter(helper, options, updateCb) {
|
17
|
+
Readable.call(this, options);
|
18
|
+
this._helper = helper;
|
19
|
+
|
20
|
+
var self = this;
|
21
|
+
helper.on("data", function (data, meta) {
|
22
|
+
if (!self.push(data)) {
|
23
|
+
self._helper.pause();
|
24
|
+
}
|
25
|
+
if(updateCb) {
|
26
|
+
updateCb(meta);
|
27
|
+
}
|
28
|
+
})
|
29
|
+
.on("error", function(e) {
|
30
|
+
self.emit('error', e);
|
31
|
+
})
|
32
|
+
.on("end", function () {
|
33
|
+
self.push(null);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
NodejsStreamOutputAdapter.prototype._read = function() {
|
39
|
+
this._helper.resume();
|
40
|
+
};
|
41
|
+
|
42
|
+
module.exports = NodejsStreamOutputAdapter;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
module.exports = {
|
4
|
+
/**
|
5
|
+
* True if this is running in Nodejs, will be undefined in a browser.
|
6
|
+
* In a browser, browserify won't include this file and the whole module
|
7
|
+
* will be resolved an empty object.
|
8
|
+
*/
|
9
|
+
isNode : typeof Buffer !== "undefined",
|
10
|
+
/**
|
11
|
+
* Create a new nodejs Buffer from an existing content.
|
12
|
+
* @param {Object} data the data to pass to the constructor.
|
13
|
+
* @param {String} encoding the encoding to use.
|
14
|
+
* @return {Buffer} a new Buffer.
|
15
|
+
*/
|
16
|
+
newBufferFrom: function(data, encoding) {
|
17
|
+
if (Buffer.from && Buffer.from !== Uint8Array.from) {
|
18
|
+
return Buffer.from(data, encoding);
|
19
|
+
} else {
|
20
|
+
if (typeof data === "number") {
|
21
|
+
// Safeguard for old Node.js versions. On newer versions,
|
22
|
+
// Buffer.from(number) / Buffer(number, encoding) already throw.
|
23
|
+
throw new Error("The \"data\" argument must not be a number");
|
24
|
+
}
|
25
|
+
return new Buffer(data, encoding);
|
26
|
+
}
|
27
|
+
},
|
28
|
+
/**
|
29
|
+
* Create a new nodejs Buffer with the specified size.
|
30
|
+
* @param {Integer} size the size of the buffer.
|
31
|
+
* @return {Buffer} a new Buffer.
|
32
|
+
*/
|
33
|
+
allocBuffer: function (size) {
|
34
|
+
if (Buffer.alloc) {
|
35
|
+
return Buffer.alloc(size);
|
36
|
+
} else {
|
37
|
+
var buf = new Buffer(size);
|
38
|
+
buf.fill(0);
|
39
|
+
return buf;
|
40
|
+
}
|
41
|
+
},
|
42
|
+
/**
|
43
|
+
* Find out if an object is a Buffer.
|
44
|
+
* @param {Object} b the object to test.
|
45
|
+
* @return {Boolean} true if the object is a Buffer, false otherwise.
|
46
|
+
*/
|
47
|
+
isBuffer : function(b){
|
48
|
+
return Buffer.isBuffer(b);
|
49
|
+
},
|
50
|
+
|
51
|
+
isStream : function (obj) {
|
52
|
+
return obj &&
|
53
|
+
typeof obj.on === "function" &&
|
54
|
+
typeof obj.pause === "function" &&
|
55
|
+
typeof obj.resume === "function";
|
56
|
+
}
|
57
|
+
};
|
@@ -0,0 +1,389 @@
|
|
1
|
+
'use strict';
|
2
|
+
var utf8 = require('./utf8');
|
3
|
+
var utils = require('./utils');
|
4
|
+
var GenericWorker = require('./stream/GenericWorker');
|
5
|
+
var StreamHelper = require('./stream/StreamHelper');
|
6
|
+
var defaults = require('./defaults');
|
7
|
+
var CompressedObject = require('./compressedObject');
|
8
|
+
var ZipObject = require('./zipObject');
|
9
|
+
var generate = require("./generate");
|
10
|
+
var nodejsUtils = require("./nodejsUtils");
|
11
|
+
var NodejsStreamInputAdapter = require("./nodejs/NodejsStreamInputAdapter");
|
12
|
+
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Add a file in the current folder.
|
16
|
+
* @private
|
17
|
+
* @param {string} name the name of the file
|
18
|
+
* @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file
|
19
|
+
* @param {Object} originalOptions the options of the file
|
20
|
+
* @return {Object} the new file.
|
21
|
+
*/
|
22
|
+
var fileAdd = function(name, data, originalOptions) {
|
23
|
+
// be sure sub folders exist
|
24
|
+
var dataType = utils.getTypeOf(data),
|
25
|
+
parent;
|
26
|
+
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Correct options.
|
30
|
+
*/
|
31
|
+
|
32
|
+
var o = utils.extend(originalOptions || {}, defaults);
|
33
|
+
o.date = o.date || new Date();
|
34
|
+
if (o.compression !== null) {
|
35
|
+
o.compression = o.compression.toUpperCase();
|
36
|
+
}
|
37
|
+
|
38
|
+
if (typeof o.unixPermissions === "string") {
|
39
|
+
o.unixPermissions = parseInt(o.unixPermissions, 8);
|
40
|
+
}
|
41
|
+
|
42
|
+
// UNX_IFDIR 0040000 see zipinfo.c
|
43
|
+
if (o.unixPermissions && (o.unixPermissions & 0x4000)) {
|
44
|
+
o.dir = true;
|
45
|
+
}
|
46
|
+
// Bit 4 Directory
|
47
|
+
if (o.dosPermissions && (o.dosPermissions & 0x0010)) {
|
48
|
+
o.dir = true;
|
49
|
+
}
|
50
|
+
|
51
|
+
if (o.dir) {
|
52
|
+
name = forceTrailingSlash(name);
|
53
|
+
}
|
54
|
+
if (o.createFolders && (parent = parentFolder(name))) {
|
55
|
+
folderAdd.call(this, parent, true);
|
56
|
+
}
|
57
|
+
|
58
|
+
var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false;
|
59
|
+
if (!originalOptions || typeof originalOptions.binary === "undefined") {
|
60
|
+
o.binary = !isUnicodeString;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
var isCompressedEmpty = (data instanceof CompressedObject) && data.uncompressedSize === 0;
|
65
|
+
|
66
|
+
if (isCompressedEmpty || o.dir || !data || data.length === 0) {
|
67
|
+
o.base64 = false;
|
68
|
+
o.binary = true;
|
69
|
+
data = "";
|
70
|
+
o.compression = "STORE";
|
71
|
+
dataType = "string";
|
72
|
+
}
|
73
|
+
|
74
|
+
/*
|
75
|
+
* Convert content to fit.
|
76
|
+
*/
|
77
|
+
|
78
|
+
var zipObjectContent = null;
|
79
|
+
if (data instanceof CompressedObject || data instanceof GenericWorker) {
|
80
|
+
zipObjectContent = data;
|
81
|
+
} else if (nodejsUtils.isNode && nodejsUtils.isStream(data)) {
|
82
|
+
zipObjectContent = new NodejsStreamInputAdapter(name, data);
|
83
|
+
} else {
|
84
|
+
zipObjectContent = utils.prepareContent(name, data, o.binary, o.optimizedBinaryString, o.base64);
|
85
|
+
}
|
86
|
+
|
87
|
+
var object = new ZipObject(name, zipObjectContent, o);
|
88
|
+
this.files[name] = object;
|
89
|
+
/*
|
90
|
+
TODO: we can't throw an exception because we have async promises
|
91
|
+
(we can have a promise of a Date() for example) but returning a
|
92
|
+
promise is useless because file(name, data) returns the JSZip
|
93
|
+
object for chaining. Should we break that to allow the user
|
94
|
+
to catch the error ?
|
95
|
+
|
96
|
+
return external.Promise.resolve(zipObjectContent)
|
97
|
+
.then(function () {
|
98
|
+
return object;
|
99
|
+
});
|
100
|
+
*/
|
101
|
+
};
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Find the parent folder of the path.
|
105
|
+
* @private
|
106
|
+
* @param {string} path the path to use
|
107
|
+
* @return {string} the parent folder, or ""
|
108
|
+
*/
|
109
|
+
var parentFolder = function (path) {
|
110
|
+
if (path.slice(-1) === '/') {
|
111
|
+
path = path.substring(0, path.length - 1);
|
112
|
+
}
|
113
|
+
var lastSlash = path.lastIndexOf('/');
|
114
|
+
return (lastSlash > 0) ? path.substring(0, lastSlash) : "";
|
115
|
+
};
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Returns the path with a slash at the end.
|
119
|
+
* @private
|
120
|
+
* @param {String} path the path to check.
|
121
|
+
* @return {String} the path with a trailing slash.
|
122
|
+
*/
|
123
|
+
var forceTrailingSlash = function(path) {
|
124
|
+
// Check the name ends with a /
|
125
|
+
if (path.slice(-1) !== "/") {
|
126
|
+
path += "/"; // IE doesn't like substr(-1)
|
127
|
+
}
|
128
|
+
return path;
|
129
|
+
};
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Add a (sub) folder in the current folder.
|
133
|
+
* @private
|
134
|
+
* @param {string} name the folder's name
|
135
|
+
* @param {boolean=} [createFolders] If true, automatically create sub
|
136
|
+
* folders. Defaults to false.
|
137
|
+
* @return {Object} the new folder.
|
138
|
+
*/
|
139
|
+
var folderAdd = function(name, createFolders) {
|
140
|
+
createFolders = (typeof createFolders !== 'undefined') ? createFolders : defaults.createFolders;
|
141
|
+
|
142
|
+
name = forceTrailingSlash(name);
|
143
|
+
|
144
|
+
// Does this folder already exist?
|
145
|
+
if (!this.files[name]) {
|
146
|
+
fileAdd.call(this, name, null, {
|
147
|
+
dir: true,
|
148
|
+
createFolders: createFolders
|
149
|
+
});
|
150
|
+
}
|
151
|
+
return this.files[name];
|
152
|
+
};
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Cross-window, cross-Node-context regular expression detection
|
156
|
+
* @param {Object} object Anything
|
157
|
+
* @return {Boolean} true if the object is a regular expression,
|
158
|
+
* false otherwise
|
159
|
+
*/
|
160
|
+
function isRegExp(object) {
|
161
|
+
return Object.prototype.toString.call(object) === "[object RegExp]";
|
162
|
+
}
|
163
|
+
|
164
|
+
// return the actual prototype of JSZip
|
165
|
+
var out = {
|
166
|
+
/**
|
167
|
+
* @see loadAsync
|
168
|
+
*/
|
169
|
+
load: function() {
|
170
|
+
throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
|
171
|
+
},
|
172
|
+
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Call a callback function for each entry at this folder level.
|
176
|
+
* @param {Function} cb the callback function:
|
177
|
+
* function (relativePath, file) {...}
|
178
|
+
* It takes 2 arguments : the relative path and the file.
|
179
|
+
*/
|
180
|
+
forEach: function(cb) {
|
181
|
+
var filename, relativePath, file;
|
182
|
+
for (filename in this.files) {
|
183
|
+
if (!this.files.hasOwnProperty(filename)) {
|
184
|
+
continue;
|
185
|
+
}
|
186
|
+
file = this.files[filename];
|
187
|
+
relativePath = filename.slice(this.root.length, filename.length);
|
188
|
+
if (relativePath && filename.slice(0, this.root.length) === this.root) { // the file is in the current root
|
189
|
+
cb(relativePath, file); // TODO reverse the parameters ? need to be clean AND consistent with the filter search fn...
|
190
|
+
}
|
191
|
+
}
|
192
|
+
},
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Filter nested files/folders with the specified function.
|
196
|
+
* @param {Function} search the predicate to use :
|
197
|
+
* function (relativePath, file) {...}
|
198
|
+
* It takes 2 arguments : the relative path and the file.
|
199
|
+
* @return {Array} An array of matching elements.
|
200
|
+
*/
|
201
|
+
filter: function(search) {
|
202
|
+
var result = [];
|
203
|
+
this.forEach(function (relativePath, entry) {
|
204
|
+
if (search(relativePath, entry)) { // the file matches the function
|
205
|
+
result.push(entry);
|
206
|
+
}
|
207
|
+
|
208
|
+
});
|
209
|
+
return result;
|
210
|
+
},
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Add a file to the zip file, or search a file.
|
214
|
+
* @param {string|RegExp} name The name of the file to add (if data is defined),
|
215
|
+
* the name of the file to find (if no data) or a regex to match files.
|
216
|
+
* @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded
|
217
|
+
* @param {Object} o File options
|
218
|
+
* @return {JSZip|Object|Array} this JSZip object (when adding a file),
|
219
|
+
* a file (when searching by string) or an array of files (when searching by regex).
|
220
|
+
*/
|
221
|
+
file: function(name, data, o) {
|
222
|
+
if (arguments.length === 1) {
|
223
|
+
if (isRegExp(name)) {
|
224
|
+
var regexp = name;
|
225
|
+
return this.filter(function(relativePath, file) {
|
226
|
+
return !file.dir && regexp.test(relativePath);
|
227
|
+
});
|
228
|
+
}
|
229
|
+
else { // text
|
230
|
+
var obj = this.files[this.root + name];
|
231
|
+
if (obj && !obj.dir) {
|
232
|
+
return obj;
|
233
|
+
} else {
|
234
|
+
return null;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
else { // more than one argument : we have data !
|
239
|
+
name = this.root + name;
|
240
|
+
fileAdd.call(this, name, data, o);
|
241
|
+
}
|
242
|
+
return this;
|
243
|
+
},
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Add a directory to the zip file, or search.
|
247
|
+
* @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.
|
248
|
+
* @return {JSZip} an object with the new directory as the root, or an array containing matching folders.
|
249
|
+
*/
|
250
|
+
folder: function(arg) {
|
251
|
+
if (!arg) {
|
252
|
+
return this;
|
253
|
+
}
|
254
|
+
|
255
|
+
if (isRegExp(arg)) {
|
256
|
+
return this.filter(function(relativePath, file) {
|
257
|
+
return file.dir && arg.test(relativePath);
|
258
|
+
});
|
259
|
+
}
|
260
|
+
|
261
|
+
// else, name is a new folder
|
262
|
+
var name = this.root + arg;
|
263
|
+
var newFolder = folderAdd.call(this, name);
|
264
|
+
|
265
|
+
// Allow chaining by returning a new object with this folder as the root
|
266
|
+
var ret = this.clone();
|
267
|
+
ret.root = newFolder.name;
|
268
|
+
return ret;
|
269
|
+
},
|
270
|
+
|
271
|
+
/**
|
272
|
+
* Delete a file, or a directory and all sub-files, from the zip
|
273
|
+
* @param {string} name the name of the file to delete
|
274
|
+
* @return {JSZip} this JSZip object
|
275
|
+
*/
|
276
|
+
remove: function(name) {
|
277
|
+
name = this.root + name;
|
278
|
+
var file = this.files[name];
|
279
|
+
if (!file) {
|
280
|
+
// Look for any folders
|
281
|
+
if (name.slice(-1) !== "/") {
|
282
|
+
name += "/";
|
283
|
+
}
|
284
|
+
file = this.files[name];
|
285
|
+
}
|
286
|
+
|
287
|
+
if (file && !file.dir) {
|
288
|
+
// file
|
289
|
+
delete this.files[name];
|
290
|
+
} else {
|
291
|
+
// maybe a folder, delete recursively
|
292
|
+
var kids = this.filter(function(relativePath, file) {
|
293
|
+
return file.name.slice(0, name.length) === name;
|
294
|
+
});
|
295
|
+
for (var i = 0; i < kids.length; i++) {
|
296
|
+
delete this.files[kids[i].name];
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
return this;
|
301
|
+
},
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Generate the complete zip file
|
305
|
+
* @param {Object} options the options to generate the zip file :
|
306
|
+
* - compression, "STORE" by default.
|
307
|
+
* - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
|
308
|
+
* @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file
|
309
|
+
*/
|
310
|
+
generate: function(options) {
|
311
|
+
throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
|
312
|
+
},
|
313
|
+
|
314
|
+
/**
|
315
|
+
* Generate the complete zip file as an internal stream.
|
316
|
+
* @param {Object} options the options to generate the zip file :
|
317
|
+
* - compression, "STORE" by default.
|
318
|
+
* - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
|
319
|
+
* @return {StreamHelper} the streamed zip file.
|
320
|
+
*/
|
321
|
+
generateInternalStream: function(options) {
|
322
|
+
var worker, opts = {};
|
323
|
+
try {
|
324
|
+
opts = utils.extend(options || {}, {
|
325
|
+
streamFiles: false,
|
326
|
+
compression: "STORE",
|
327
|
+
compressionOptions : null,
|
328
|
+
type: "",
|
329
|
+
platform: "DOS",
|
330
|
+
comment: null,
|
331
|
+
mimeType: 'application/zip',
|
332
|
+
encodeFileName: utf8.utf8encode
|
333
|
+
});
|
334
|
+
|
335
|
+
opts.type = opts.type.toLowerCase();
|
336
|
+
opts.compression = opts.compression.toUpperCase();
|
337
|
+
|
338
|
+
// "binarystring" is preferred but the internals use "string".
|
339
|
+
if(opts.type === "binarystring") {
|
340
|
+
opts.type = "string";
|
341
|
+
}
|
342
|
+
|
343
|
+
if (!opts.type) {
|
344
|
+
throw new Error("No output type specified.");
|
345
|
+
}
|
346
|
+
|
347
|
+
utils.checkSupport(opts.type);
|
348
|
+
|
349
|
+
// accept nodejs `process.platform`
|
350
|
+
if(
|
351
|
+
opts.platform === 'darwin' ||
|
352
|
+
opts.platform === 'freebsd' ||
|
353
|
+
opts.platform === 'linux' ||
|
354
|
+
opts.platform === 'sunos'
|
355
|
+
) {
|
356
|
+
opts.platform = "UNIX";
|
357
|
+
}
|
358
|
+
if (opts.platform === 'win32') {
|
359
|
+
opts.platform = "DOS";
|
360
|
+
}
|
361
|
+
|
362
|
+
var comment = opts.comment || this.comment || "";
|
363
|
+
worker = generate.generateWorker(this, opts, comment);
|
364
|
+
} catch (e) {
|
365
|
+
worker = new GenericWorker("error");
|
366
|
+
worker.error(e);
|
367
|
+
}
|
368
|
+
return new StreamHelper(worker, opts.type || "string", opts.mimeType);
|
369
|
+
},
|
370
|
+
/**
|
371
|
+
* Generate the complete zip file asynchronously.
|
372
|
+
* @see generateInternalStream
|
373
|
+
*/
|
374
|
+
generateAsync: function(options, onUpdate) {
|
375
|
+
return this.generateInternalStream(options).accumulate(onUpdate);
|
376
|
+
},
|
377
|
+
/**
|
378
|
+
* Generate the complete zip file asynchronously.
|
379
|
+
* @see generateInternalStream
|
380
|
+
*/
|
381
|
+
generateNodeStream: function(options, onUpdate) {
|
382
|
+
options = options || {};
|
383
|
+
if (!options.type) {
|
384
|
+
options.type = "nodebuffer";
|
385
|
+
}
|
386
|
+
return this.generateInternalStream(options).toNodejsStream(onUpdate);
|
387
|
+
}
|
388
|
+
};
|
389
|
+
module.exports = out;
|