From 5221202d1de7e3b104aaf67e5670ca842865eba5 Mon Sep 17 00:00:00 2001 From: Stuart Knightley Date: Thu, 23 Jun 2022 13:58:36 -0700 Subject: [PATCH] Fix eslint errors --- .eslintrc.js | 4 +- Gruntfile.js | 72 +- documentation/.eslintrc.js | 12 + .../examples/download-zip-file.inc/blob.js | 2 + .../download-zip-file.inc/data_uri.js | 2 + .../examples/downloader.inc/downloader.js | 25 +- .../examples/downloader.inc/helpers.js | 28 +- .../get-binary-files-ajax.inc/fetch_api.js | 48 +- .../get-binary-files-ajax.inc/jszip_utils.js | 33 +- .../examples/read-local-file-api.inc/read.js | 33 +- lib/base64.js | 8 +- lib/compressedObject.js | 12 +- lib/compressions.js | 6 +- lib/crc32.js | 4 +- lib/defaults.js | 2 +- lib/external.js | 3 +- lib/flate.js | 4 +- lib/generate/ZipFileWorker.js | 73 +- lib/generate/index.js | 24 +- lib/index.js | 12 +- lib/load.js | 10 +- lib/nodejs/NodejsStreamInputAdapter.js | 44 +- lib/nodejs/NodejsStreamOutputAdapter.js | 18 +- lib/nodejsUtils.js | 2 +- lib/object.js | 124 ++- lib/readable-stream-browser.js | 1 + lib/reader/ArrayReader.js | 12 +- lib/reader/DataReader.js | 24 +- lib/reader/NodeBufferReader.js | 6 +- lib/reader/StringReader.js | 6 +- lib/reader/Uint8ArrayReader.js | 6 +- lib/reader/readerFor.js | 14 +- lib/signature.js | 2 +- lib/stream/ConvertWorker.js | 6 +- lib/stream/Crc32Probe.js | 8 +- lib/stream/DataLengthProbe.js | 6 +- lib/stream/DataWorker.js | 20 +- lib/stream/GenericWorker.js | 16 +- lib/stream/StreamHelper.js | 108 +-- lib/support.js | 6 +- lib/utf8.js | 14 +- lib/utils.js | 22 +- lib/zipEntries.js | 13 +- lib/zipEntry.js | 23 +- lib/zipObject.js | 12 +- test/.eslintrc.js | 10 + test/asserts/constructor.js | 3 +- test/asserts/delete.js | 20 +- test/asserts/deprecated.js | 9 +- test/asserts/external.js | 17 +- test/asserts/file.js | 185 ++-- test/asserts/filter.js | 7 +- test/asserts/foreach.js | 3 +- test/asserts/generate.js | 105 ++- test/asserts/load.js | 827 +++++++++--------- test/asserts/permissions.js | 77 +- test/asserts/stream.js | 191 ++-- test/asserts/unicode.js | 76 +- test/asserts/utils.js | 3 +- test/asserts/version.js | 3 +- test/helpers/browser-test-utils.js | 3 +- test/helpers/node-test-utils.js | 15 +- test/helpers/test-utils.js | 45 +- test/run.js | 6 +- 64 files changed, 1269 insertions(+), 1266 deletions(-) create mode 100644 documentation/.eslintrc.js create mode 100644 test/.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index fb1a2c38..7c3f0271 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,5 @@ +"use strict"; + module.exports = { "env": { "browser": true, @@ -9,7 +11,7 @@ module.exports = { "parserOptions": { "ecmaVersion": "latest" }, - "ignorePatterns": ["vendor/*.js", "dist/*.js"], + "ignorePatterns": ["vendor/*.js", "dist/*.js", "test/jquery-1.8.3.min.js"], "rules": { "indent": [ "error", diff --git a/Gruntfile.js b/Gruntfile.js index 4f0c2241..9f1b1b88 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,46 +1,46 @@ "use strict"; module.exports = function(grunt) { - var version = require("./package.json").version; + var version = require("./package.json").version; - grunt.initConfig({ - browserify: { - all: { - files: { - 'dist/jszip.js': ['lib/index.js'] + grunt.initConfig({ + browserify: { + all: { + files: { + "dist/jszip.js": ["lib/index.js"] + }, + options: { + browserifyOptions: { + standalone: "JSZip", + transform: ["package-json-versionify"], + insertGlobalVars: { + process: undefined, + Buffer: undefined, + __filename: undefined, + __dirname: undefined + }, + builtins: false + }, + banner: grunt.file.read("lib/license_header.js").replace(/__VERSION__/, version) + } + } }, - options: { - browserifyOptions: { - standalone: 'JSZip', - transform: ['package-json-versionify'], - insertGlobalVars: { - process: undefined, - Buffer: undefined, - __filename: undefined, - __dirname: undefined + uglify: { + options: { + mangle: true, + preserveComments: false, + banner: grunt.file.read("lib/license_header.js").replace(/__VERSION__/, version) }, - builtins: false - }, - banner: grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version) + all: { + src: "dist/jszip.js", + dest: "dist/jszip.min.js" + } } - } - }, - uglify: { - options: { - mangle: true, - preserveComments: false, - banner: grunt.file.read('lib/license_header.js').replace(/__VERSION__/, version) - }, - all: { - src: 'dist/jszip.js', - dest: 'dist/jszip.min.js' - } - } - }); + }); - grunt.loadNpmTasks('grunt-browserify'); - grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks("grunt-browserify"); + grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.registerTask("build", ["browserify", "uglify"]); - grunt.registerTask("default", ["build"]); + grunt.registerTask("build", ["browserify", "uglify"]); + grunt.registerTask("default", ["build"]); }; diff --git a/documentation/.eslintrc.js b/documentation/.eslintrc.js new file mode 100644 index 00000000..17f7a7e6 --- /dev/null +++ b/documentation/.eslintrc.js @@ -0,0 +1,12 @@ +"use strict"; + +module.exports = { + globals: { + $: false, + jQuery: false, + JSZip: false, + JSZipUtils: false, + // From FileSaver.js + saveAs: false, + }, +}; diff --git a/documentation/examples/download-zip-file.inc/blob.js b/documentation/examples/download-zip-file.inc/blob.js index d7f96792..b43939f6 100644 --- a/documentation/examples/download-zip-file.inc/blob.js +++ b/documentation/examples/download-zip-file.inc/blob.js @@ -1,3 +1,5 @@ +"use strict"; + var zip = new JSZip(); zip.file("Hello.txt", "Hello world\n"); diff --git a/documentation/examples/download-zip-file.inc/data_uri.js b/documentation/examples/download-zip-file.inc/data_uri.js index bf3c4a57..e764ff65 100644 --- a/documentation/examples/download-zip-file.inc/data_uri.js +++ b/documentation/examples/download-zip-file.inc/data_uri.js @@ -1,3 +1,5 @@ +"use strict"; + var zip = new JSZip(); zip.file("Hello.txt", "Hello world\n"); diff --git a/documentation/examples/downloader.inc/downloader.js b/documentation/examples/downloader.inc/downloader.js index 38fd8102..443ce010 100644 --- a/documentation/examples/downloader.inc/downloader.js +++ b/documentation/examples/downloader.inc/downloader.js @@ -1,8 +1,6 @@ - -var Promise = window.Promise; -if (!Promise) { - Promise = JSZip.external.Promise; -} +"use strict"; +// From helpers.js: +/* global resetMessage, showMessage, showError, updatePercent */ /** * Fetch the content and return the associated promise. @@ -21,8 +19,7 @@ function urlToPromise(url) { }); } -var $form = $("#download_form").on("submit", function () { - +$("#download_form").on("submit", function () { resetMessage(); var zip = new JSZip(); @@ -44,15 +41,15 @@ var $form = $("#download_form").on("submit", function () { showMessage(msg); updatePercent(metadata.percent|0); }) - .then(function callback(blob) { + .then(function callback(blob) { - // see FileSaver.js - saveAs(blob, "example.zip"); + // see FileSaver.js + saveAs(blob, "example.zip"); - showMessage("done !"); - }, function (e) { - showError(e); - }); + showMessage("done !"); + }, function (e) { + showError(e); + }); return false; }); diff --git a/documentation/examples/downloader.inc/helpers.js b/documentation/examples/downloader.inc/helpers.js index b51aa60d..63966577 100644 --- a/documentation/examples/downloader.inc/helpers.js +++ b/documentation/examples/downloader.inc/helpers.js @@ -1,20 +1,23 @@ +"use strict"; + /** * Reset the message. */ function resetMessage () { $("#result") - .removeClass() - .text(""); + .removeClass() + .text(""); } /** * show a successful message. * @param {String} text the text to show. */ +// eslint-disable-next-line no-unused-vars function showMessage(text) { resetMessage(); $("#result") - .addClass("alert alert-success") - .text(text); + .addClass("alert alert-success") + .text(text); } /** * show an error message. @@ -23,24 +26,23 @@ function showMessage(text) { function showError(text) { resetMessage(); $("#result") - .addClass("alert alert-danger") - .text(text); + .addClass("alert alert-danger") + .text(text); } /** * Update the progress bar. * @param {Integer} percent the current percent */ +// eslint-disable-next-line no-unused-vars function updatePercent(percent) { $("#progress_bar").removeClass("hide") - .find(".progress-bar") - .attr("aria-valuenow", percent) - .css({ - width : percent + "%" - }); + .find(".progress-bar") + .attr("aria-valuenow", percent) + .css({ + width : percent + "%" + }); } if(!JSZip.support.blob) { showError("This demo works only with a recent browser !"); - return; } - diff --git a/documentation/examples/get-binary-files-ajax.inc/fetch_api.js b/documentation/examples/get-binary-files-ajax.inc/fetch_api.js index fd56fccd..777a89ab 100644 --- a/documentation/examples/get-binary-files-ajax.inc/fetch_api.js +++ b/documentation/examples/get-binary-files-ajax.inc/fetch_api.js @@ -1,23 +1,25 @@ -fetch('{{site.baseurl}}/test/ref/text.zip') // 1) fetch the url -.then(function (response) { // 2) filter on 200 OK - if (response.status === 200 || response.status === 0) { - return Promise.resolve(response.blob()); - } else { - return Promise.reject(new Error(response.statusText)); - } -}) -.then(JSZip.loadAsync) // 3) chain with the zip promise -.then(function (zip) { - return zip.file("Hello.txt").async("string"); // 4) chain with the text content promise -}) -.then(function success(text) { // 5) display the result - $("#fetch").append($("

", { - "class": "alert alert-success", - text: "loaded, content = " + text - })); -}, function error(e) { - $("#fetch").append($("

", { - "class": "alert alert-danger", - text: e - })); -}); +"use strict"; + +fetch("{{site.baseurl}}/test/ref/text.zip") // 1) fetch the url + .then(function (response) { // 2) filter on 200 OK + if (response.status === 200 || response.status === 0) { + return Promise.resolve(response.blob()); + } else { + return Promise.reject(new Error(response.statusText)); + } + }) + .then(JSZip.loadAsync) // 3) chain with the zip promise + .then(function (zip) { + return zip.file("Hello.txt").async("string"); // 4) chain with the text content promise + }) + .then(function success(text) { // 5) display the result + $("#fetch").append($("

", { + "class": "alert alert-success", + text: "loaded, content = " + text + })); + }, function error(e) { + $("#fetch").append($("

", { + "class": "alert alert-danger", + text: e + })); + }); diff --git a/documentation/examples/get-binary-files-ajax.inc/jszip_utils.js b/documentation/examples/get-binary-files-ajax.inc/jszip_utils.js index ea4191be..cae1da18 100644 --- a/documentation/examples/get-binary-files-ajax.inc/jszip_utils.js +++ b/documentation/examples/get-binary-files-ajax.inc/jszip_utils.js @@ -1,6 +1,8 @@ +"use strict"; + // 1) get a promise of the content var promise = new JSZip.external.Promise(function (resolve, reject) { - JSZipUtils.getBinaryContent('{{site.baseurl}}/test/ref/text.zip', function(err, data) { + JSZipUtils.getBinaryContent("{{site.baseurl}}/test/ref/text.zip", function(err, data) { if (err) { reject(err); } else { @@ -10,18 +12,17 @@ var promise = new JSZip.external.Promise(function (resolve, reject) { }); promise.then(JSZip.loadAsync) // 2) chain with the zip promise -.then(function(zip) { - return zip.file("Hello.txt").async("string"); // 3) chain with the text content promise -}) -.then(function success(text) { // 4) display the result - $("#jszip_utils").append($("

", { - "class": "alert alert-success", - text: "loaded, content = " + text - })); -}, function error(e) { - $("#jszip_utils").append($("

", { - "class": "alert alert-danger", - text: e - })); -}); - + .then(function(zip) { + return zip.file("Hello.txt").async("string"); // 3) chain with the text content promise + }) + .then(function success(text) { // 4) display the result + $("#jszip_utils").append($("

", { + "class": "alert alert-success", + text: "loaded, content = " + text + })); + }, function error(e) { + $("#jszip_utils").append($("

", { + "class": "alert alert-danger", + text: e + })); + }); diff --git a/documentation/examples/read-local-file-api.inc/read.js b/documentation/examples/read-local-file-api.inc/read.js index 3c559580..3481ae30 100644 --- a/documentation/examples/read-local-file-api.inc/read.js +++ b/documentation/examples/read-local-file-api.inc/read.js @@ -1,3 +1,5 @@ +"use strict"; + var $result = $("#result"); $("#file").on("change", function(evt) { // remove content @@ -16,24 +18,24 @@ $("#file").on("change", function(evt) { var dateBefore = new Date(); JSZip.loadAsync(f) // 1) read the Blob - .then(function(zip) { - var dateAfter = new Date(); - $title.append($("", { - "class": "small", - text:" (loaded in " + (dateAfter - dateBefore) + "ms)" - })); + .then(function(zip) { + var dateAfter = new Date(); + $title.append($("", { + "class": "small", + text:" (loaded in " + (dateAfter - dateBefore) + "ms)" + })); - zip.forEach(function (relativePath, zipEntry) { // 2) print entries - $fileContent.append($("

  • ", { - text : zipEntry.name + zip.forEach(function (relativePath, zipEntry) { // 2) print entries + $fileContent.append($("
  • ", { + text : zipEntry.name + })); + }); + }, function (e) { + $result.append($("
    ", { + "class" : "alert alert-danger", + text : "Error reading " + f.name + ": " + e.message })); }); - }, function (e) { - $result.append($("
    ", { - "class" : "alert alert-danger", - text : "Error reading " + f.name + ": " + e.message - })); - }); } var files = evt.target.files; @@ -41,4 +43,3 @@ $("#file").on("change", function(evt) { handleFile(files[i]); } }); - diff --git a/lib/base64.js b/lib/base64.js index 75d7e3ce..6f46deaa 100644 --- a/lib/base64.js +++ b/lib/base64.js @@ -1,6 +1,6 @@ -'use strict'; -var utils = require('./utils'); -var support = require('./support'); +"use strict"; +var utils = require("./utils"); +var support = require("./support"); // private property var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; @@ -55,7 +55,7 @@ exports.decode = function(input) { throw new Error("Invalid base64 input, it looks like a data url."); } - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + input = input.replace(/[^A-Za-z0-9+/=]/g, ""); var totalLength = input.length * 3 / 4; if(input.charAt(input.length - 1) === _keyStr.charAt(64)) { diff --git a/lib/compressedObject.js b/lib/compressedObject.js index 7b86a575..0acd4c42 100644 --- a/lib/compressedObject.js +++ b/lib/compressedObject.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; var external = require("./external"); -var DataWorker = require('./stream/DataWorker'); -var Crc32Probe = require('./stream/Crc32Probe'); -var DataLengthProbe = require('./stream/DataLengthProbe'); +var DataWorker = require("./stream/DataWorker"); +var Crc32Probe = require("./stream/Crc32Probe"); +var DataLengthProbe = require("./stream/DataLengthProbe"); /** * Represent a compressed object, with everything needed to decompress it. @@ -34,7 +34,7 @@ CompressedObject.prototype = { var that = this; worker.on("end", function () { - if (this.streamInfo['data_length'] !== that.uncompressedSize) { + if (this.streamInfo["data_length"] !== that.uncompressedSize) { throw new Error("Bug : uncompressed data size mismatch"); } }); @@ -50,7 +50,7 @@ CompressedObject.prototype = { .withStreamInfo("uncompressedSize", this.uncompressedSize) .withStreamInfo("crc32", this.crc32) .withStreamInfo("compression", this.compression) - ; + ; } }; diff --git a/lib/compressions.js b/lib/compressions.js index 1e81ea94..81c67b4e 100644 --- a/lib/compressions.js +++ b/lib/compressions.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict"; var GenericWorker = require("./stream/GenericWorker"); exports.STORE = { magic: "\x00\x00", - compressWorker : function (compressionOptions) { + compressWorker : function () { return new GenericWorker("STORE compression"); }, uncompressWorker : function () { return new GenericWorker("STORE decompression"); } }; -exports.DEFLATE = require('./flate'); +exports.DEFLATE = require("./flate"); diff --git a/lib/crc32.js b/lib/crc32.js index 62a0d52b..fc111e9b 100644 --- a/lib/crc32.js +++ b/lib/crc32.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -var utils = require('./utils'); +var utils = require("./utils"); /** * The following functions come from pako, from pako/lib/zlib/crc32.js diff --git a/lib/defaults.js b/lib/defaults.js index 41800c3f..8fb6c1e7 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; exports.base64 = false; exports.binary = false; exports.dir = false; diff --git a/lib/external.js b/lib/external.js index 8803e55f..c846f5fa 100644 --- a/lib/external.js +++ b/lib/external.js @@ -1,5 +1,4 @@ -/* global Promise */ -'use strict'; +"use strict"; // load the global object first: // - it should be better integrated in the system (unhandledRejection in node) diff --git a/lib/flate.js b/lib/flate.js index a078f6fe..cd9e062c 100644 --- a/lib/flate.js +++ b/lib/flate.js @@ -1,5 +1,5 @@ -'use strict'; -var USE_TYPEDARRAY = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && (typeof Uint32Array !== 'undefined'); +"use strict"; +var USE_TYPEDARRAY = (typeof Uint8Array !== "undefined") && (typeof Uint16Array !== "undefined") && (typeof Uint32Array !== "undefined"); var pako = require("pako"); var utils = require("./utils"); diff --git a/lib/generate/ZipFileWorker.js b/lib/generate/ZipFileWorker.js index 4c7a6112..a86d46aa 100644 --- a/lib/generate/ZipFileWorker.js +++ b/lib/generate/ZipFileWorker.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -var utils = require('../utils'); -var GenericWorker = require('../stream/GenericWorker'); -var utf8 = require('../utf8'); -var crc32 = require('../crc32'); -var signature = require('../signature'); +var utils = require("../utils"); +var GenericWorker = require("../stream/GenericWorker"); +var utf8 = require("../utf8"); +var crc32 = require("../crc32"); +var signature = require("../signature"); /** * Transform an integer into a string in hexadecimal. @@ -62,8 +62,7 @@ var generateUnixExternalFileAttr = function (unixPermissions, isDir) { * Bit 4 Directory * Bit 5 Archive */ -var generateDosExternalFileAttr = function (dosPermissions, isDir) { - +var generateDosExternalFileAttr = function (dosPermissions) { // the dir flag is already set for compatibility return (dosPermissions || 0) & 0x3F; }; @@ -79,23 +78,23 @@ var generateDosExternalFileAttr = function (dosPermissions, isDir) { * @return {Object} the zip parts. */ var generateZipParts = function(streamInfo, streamedContent, streamingEnded, offset, platform, encodeFileName) { - var file = streamInfo['file'], - compression = streamInfo['compression'], - useCustomEncoding = encodeFileName !== utf8.utf8encode, - encodedFileName = utils.transformTo("string", encodeFileName(file.name)), - utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)), - comment = file.comment, - encodedComment = utils.transformTo("string", encodeFileName(comment)), - utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)), - useUTF8ForFileName = utfEncodedFileName.length !== file.name.length, - useUTF8ForComment = utfEncodedComment.length !== comment.length, - dosTime, - dosDate, - extraFields = "", - unicodePathExtraField = "", - unicodeCommentExtraField = "", - dir = file.dir, - date = file.date; + var file = streamInfo["file"], + compression = streamInfo["compression"], + useCustomEncoding = encodeFileName !== utf8.utf8encode, + encodedFileName = utils.transformTo("string", encodeFileName(file.name)), + utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)), + comment = file.comment, + encodedComment = utils.transformTo("string", encodeFileName(comment)), + utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)), + useUTF8ForFileName = utfEncodedFileName.length !== file.name.length, + useUTF8ForComment = utfEncodedComment.length !== comment.length, + dosTime, + dosDate, + extraFields = "", + unicodePathExtraField = "", + unicodeCommentExtraField = "", + dir = file.dir, + date = file.date; var dataInfo = { @@ -107,9 +106,9 @@ var generateZipParts = function(streamInfo, streamedContent, streamingEnded, off // if the content is streamed, the sizes/crc32 are only available AFTER // the end of the stream. if (!streamedContent || streamingEnded) { - dataInfo.crc32 = streamInfo['crc32']; - dataInfo.compressedSize = streamInfo['compressedSize']; - dataInfo.uncompressedSize = streamInfo['uncompressedSize']; + dataInfo.crc32 = streamInfo["crc32"]; + dataInfo.compressedSize = streamInfo["compressedSize"]; + dataInfo.uncompressedSize = streamInfo["uncompressedSize"]; } var bitflag = 0; @@ -301,11 +300,11 @@ var generateDataDescriptors = function (streamInfo) { var descriptor = ""; descriptor = signature.DATA_DESCRIPTOR + // crc-32 4 bytes - decToHex(streamInfo['crc32'], 4) + + decToHex(streamInfo["crc32"], 4) + // compressed size 4 bytes - decToHex(streamInfo['compressedSize'], 4) + + decToHex(streamInfo["compressedSize"], 4) + // uncompressed size 4 bytes - decToHex(streamInfo['uncompressedSize'], 4); + decToHex(streamInfo["uncompressedSize"], 4); return descriptor; }; @@ -384,9 +383,9 @@ ZipFileWorker.prototype.push = function (chunk) { */ ZipFileWorker.prototype.openedSource = function (streamInfo) { this.currentSourceOffset = this.bytesWritten; - this.currentFile = streamInfo['file'].name; + this.currentFile = streamInfo["file"].name; - var streamedContent = this.streamFiles && !streamInfo['file'].dir; + var streamedContent = this.streamFiles && !streamInfo["file"].dir; // don't stream folders (because they don't have any content) if(streamedContent) { @@ -407,7 +406,7 @@ ZipFileWorker.prototype.openedSource = function (streamInfo) { */ ZipFileWorker.prototype.closedSource = function (streamInfo) { this.accumulate = false; - var streamedContent = this.streamFiles && !streamInfo['file'].dir; + var streamedContent = this.streamFiles && !streamInfo["file"].dir; var record = generateZipParts(streamInfo, streamedContent, true, this.currentSourceOffset, this.zipPlatform, this.encodeFileName); this.dirRecords.push(record.dirRecord); @@ -473,10 +472,10 @@ ZipFileWorker.prototype.registerPrevious = function (previous) { this._sources.push(previous); var self = this; - previous.on('data', function (chunk) { + previous.on("data", function (chunk) { self.processChunk(chunk); }); - previous.on('end', function () { + previous.on("end", function () { self.closedSource(self.previous.streamInfo); if(self._sources.length) { self.prepareNextSource(); @@ -484,7 +483,7 @@ ZipFileWorker.prototype.registerPrevious = function (previous) { self.end(); } }); - previous.on('error', function (e) { + previous.on("error", function (e) { self.error(e); }); return this; diff --git a/lib/generate/index.js b/lib/generate/index.js index 083ddeb1..2b3f7d67 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -var compressions = require('../compressions'); -var ZipFileWorker = require('./ZipFileWorker'); +var compressions = require("../compressions"); +var ZipFileWorker = require("./ZipFileWorker"); /** * Find the compression to use. @@ -38,15 +38,15 @@ exports.generateWorker = function (zip, options, comment) { var dir = file.dir, date = file.date; file._compressWorker(compression, compressionOptions) - .withStreamInfo("file", { - name : relativePath, - dir : dir, - date : date, - comment : file.comment || "", - unixPermissions : file.unixPermissions, - dosPermissions : file.dosPermissions - }) - .pipe(zipFileWorker); + .withStreamInfo("file", { + name : relativePath, + dir : dir, + date : date, + comment : file.comment || "", + unixPermissions : file.unixPermissions, + dosPermissions : file.dosPermissions + }) + .pipe(zipFileWorker); }); zipFileWorker.entriesCount = entriesCount; } catch (e) { diff --git a/lib/index.js b/lib/index.js index 8cab905d..50eb5a70 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; /** * Representation a of zip file in js * @constructor */ function JSZip() { - // if this constructor is used without `new`, it adds `new` before itself: + // if this constructor is used without `new`, it adds `new` before itself: if(!(this instanceof JSZip)) { return new JSZip(); } @@ -38,10 +38,10 @@ function JSZip() { return newObj; }; } -JSZip.prototype = require('./object'); -JSZip.prototype.loadAsync = require('./load'); -JSZip.support = require('./support'); -JSZip.defaults = require('./defaults'); +JSZip.prototype = require("./object"); +JSZip.prototype.loadAsync = require("./load"); +JSZip.support = require("./support"); +JSZip.defaults = require("./defaults"); // TODO find a better way to handle this version, // a require('package.json').version doesn't work with webpack, see #327 diff --git a/lib/load.js b/lib/load.js index 389aafe5..69fa2694 100644 --- a/lib/load.js +++ b/lib/load.js @@ -1,9 +1,9 @@ -'use strict'; -var utils = require('./utils'); +"use strict"; +var utils = require("./utils"); var external = require("./external"); -var utf8 = require('./utf8'); -var ZipEntries = require('./zipEntries'); -var Crc32Probe = require('./stream/Crc32Probe'); +var utf8 = require("./utf8"); +var ZipEntries = require("./zipEntries"); +var Crc32Probe = require("./stream/Crc32Probe"); var nodejsUtils = require("./nodejsUtils"); /** diff --git a/lib/nodejs/NodejsStreamInputAdapter.js b/lib/nodejs/NodejsStreamInputAdapter.js index 0ef320c8..635c5047 100644 --- a/lib/nodejs/NodejsStreamInputAdapter.js +++ b/lib/nodejs/NodejsStreamInputAdapter.js @@ -1,7 +1,7 @@ "use strict"; -var utils = require('../utils'); -var GenericWorker = require('../stream/GenericWorker'); +var utils = require("../utils"); +var GenericWorker = require("../stream/GenericWorker"); /** * A worker that use a nodejs stream as source. @@ -27,28 +27,28 @@ NodejsStreamInputAdapter.prototype._bindStream = function (stream) { this._stream = stream; stream.pause(); stream - .on("data", function (chunk) { - self.push({ - data: chunk, - meta : { - percent : 0 + .on("data", function (chunk) { + self.push({ + data: chunk, + meta : { + percent : 0 + } + }); + }) + .on("error", function (e) { + if(self.isPaused) { + this.generatedError = e; + } else { + self.error(e); + } + }) + .on("end", function () { + if(self.isPaused) { + self._upstreamEnded = true; + } else { + self.end(); } }); - }) - .on("error", function (e) { - if(self.isPaused) { - this.generatedError = e; - } else { - self.error(e); - } - }) - .on("end", function () { - if(self.isPaused) { - self._upstreamEnded = true; - } else { - self.end(); - } - }); }; NodejsStreamInputAdapter.prototype.pause = function () { if(!GenericWorker.prototype.pause.call(this)) { diff --git a/lib/nodejs/NodejsStreamOutputAdapter.js b/lib/nodejs/NodejsStreamOutputAdapter.js index 3757cdf9..e6aafb9b 100644 --- a/lib/nodejs/NodejsStreamOutputAdapter.js +++ b/lib/nodejs/NodejsStreamOutputAdapter.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; -var Readable = require('readable-stream').Readable; +var Readable = require("readable-stream").Readable; -var utils = require('../utils'); +var utils = require("../utils"); utils.inherits(NodejsStreamOutputAdapter, Readable); /** @@ -26,12 +26,12 @@ function NodejsStreamOutputAdapter(helper, options, updateCb) { updateCb(meta); } }) - .on("error", function(e) { - self.emit('error', e); - }) - .on("end", function () { - self.push(null); - }); + .on("error", function(e) { + self.emit("error", e); + }) + .on("end", function () { + self.push(null); + }); } diff --git a/lib/nodejsUtils.js b/lib/nodejsUtils.js index 83001064..6d9b3c3f 100644 --- a/lib/nodejsUtils.js +++ b/lib/nodejsUtils.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; module.exports = { /** diff --git a/lib/object.js b/lib/object.js index c71faa57..0e979778 100644 --- a/lib/object.js +++ b/lib/object.js @@ -1,11 +1,11 @@ -'use strict'; -var utf8 = require('./utf8'); -var utils = require('./utils'); -var GenericWorker = require('./stream/GenericWorker'); -var StreamHelper = require('./stream/StreamHelper'); -var defaults = require('./defaults'); -var CompressedObject = require('./compressedObject'); -var ZipObject = require('./zipObject'); +"use strict"; +var utf8 = require("./utf8"); +var utils = require("./utils"); +var GenericWorker = require("./stream/GenericWorker"); +var StreamHelper = require("./stream/StreamHelper"); +var defaults = require("./defaults"); +var CompressedObject = require("./compressedObject"); +var ZipObject = require("./zipObject"); var generate = require("./generate"); var nodejsUtils = require("./nodejsUtils"); var NodejsStreamInputAdapter = require("./nodejs/NodejsStreamInputAdapter"); @@ -107,10 +107,10 @@ var fileAdd = function(name, data, originalOptions) { * @return {string} the parent folder, or "" */ var parentFolder = function (path) { - if (path.slice(-1) === '/') { + if (path.slice(-1) === "/") { path = path.substring(0, path.length - 1); } - var lastSlash = path.lastIndexOf('/'); + var lastSlash = path.lastIndexOf("/"); return (lastSlash > 0) ? path.substring(0, lastSlash) : ""; }; @@ -137,7 +137,7 @@ var forceTrailingSlash = function(path) { * @return {Object} the new folder. */ var folderAdd = function(name, createFolders) { - createFolders = (typeof createFolders !== 'undefined') ? createFolders : defaults.createFolders; + createFolders = (typeof createFolders !== "undefined") ? createFolders : defaults.createFolders; name = forceTrailingSlash(name); @@ -300,13 +300,9 @@ var out = { }, /** - * Generate the complete zip file - * @param {Object} options the options to generate the zip file : - * - compression, "STORE" by default. - * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob. - * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file + * @deprecated This method has been removed in JSZip 3.0, please check the upgrade guide. */ - generate: function(options) { + generate: function() { throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide."); }, @@ -318,53 +314,53 @@ var out = { * @return {StreamHelper} the streamed zip file. */ generateInternalStream: function(options) { - var worker, opts = {}; - try { - opts = utils.extend(options || {}, { - streamFiles: false, - compression: "STORE", - compressionOptions : null, - type: "", - platform: "DOS", - comment: null, - mimeType: 'application/zip', - encodeFileName: utf8.utf8encode - }); - - opts.type = opts.type.toLowerCase(); - opts.compression = opts.compression.toUpperCase(); - - // "binarystring" is preferred but the internals use "string". - if(opts.type === "binarystring") { - opts.type = "string"; - } - - if (!opts.type) { - throw new Error("No output type specified."); - } - - utils.checkSupport(opts.type); - - // accept nodejs `process.platform` - if( - opts.platform === 'darwin' || - opts.platform === 'freebsd' || - opts.platform === 'linux' || - opts.platform === 'sunos' - ) { - opts.platform = "UNIX"; - } - if (opts.platform === 'win32') { - opts.platform = "DOS"; - } - - var comment = opts.comment || this.comment || ""; - worker = generate.generateWorker(this, opts, comment); - } catch (e) { - worker = new GenericWorker("error"); - worker.error(e); - } - return new StreamHelper(worker, opts.type || "string", opts.mimeType); + var worker, opts = {}; + try { + opts = utils.extend(options || {}, { + streamFiles: false, + compression: "STORE", + compressionOptions : null, + type: "", + platform: "DOS", + comment: null, + mimeType: "application/zip", + encodeFileName: utf8.utf8encode + }); + + opts.type = opts.type.toLowerCase(); + opts.compression = opts.compression.toUpperCase(); + + // "binarystring" is preferred but the internals use "string". + if(opts.type === "binarystring") { + opts.type = "string"; + } + + if (!opts.type) { + throw new Error("No output type specified."); + } + + utils.checkSupport(opts.type); + + // accept nodejs `process.platform` + if( + opts.platform === "darwin" || + opts.platform === "freebsd" || + opts.platform === "linux" || + opts.platform === "sunos" + ) { + opts.platform = "UNIX"; + } + if (opts.platform === "win32") { + opts.platform = "DOS"; + } + + var comment = opts.comment || this.comment || ""; + worker = generate.generateWorker(this, opts, comment); + } catch (e) { + worker = new GenericWorker("error"); + worker.error(e); + } + return new StreamHelper(worker, opts.type || "string", opts.mimeType); }, /** * Generate the complete zip file asynchronously. diff --git a/lib/readable-stream-browser.js b/lib/readable-stream-browser.js index 49410a46..a07d91ab 100644 --- a/lib/readable-stream-browser.js +++ b/lib/readable-stream-browser.js @@ -1,3 +1,4 @@ +"use strict"; /* * This file is used by module bundlers (browserify/webpack/etc) when * including a stream implementation. We use "readable-stream" to get a diff --git a/lib/reader/ArrayReader.js b/lib/reader/ArrayReader.js index 3e9e4eb3..32a9569b 100644 --- a/lib/reader/ArrayReader.js +++ b/lib/reader/ArrayReader.js @@ -1,12 +1,12 @@ -'use strict'; -var DataReader = require('./DataReader'); -var utils = require('../utils'); +"use strict"; +var DataReader = require("./DataReader"); +var utils = require("../utils"); function ArrayReader(data) { DataReader.call(this, data); - for(var i = 0; i < this.data.length; i++) { - data[i] = data[i] & 0xFF; - } + for(var i = 0; i < this.data.length; i++) { + data[i] = data[i] & 0xFF; + } } utils.inherits(ArrayReader, DataReader); /** diff --git a/lib/reader/DataReader.js b/lib/reader/DataReader.js index c4e1e03b..b61b839b 100644 --- a/lib/reader/DataReader.js +++ b/lib/reader/DataReader.js @@ -1,5 +1,5 @@ -'use strict'; -var utils = require('../utils'); +"use strict"; +var utils = require("../utils"); function DataReader(data) { this.data = data; // type : see implementation @@ -48,7 +48,7 @@ DataReader.prototype = { * @param {number} i the index to use. * @return {number} a byte. */ - byteAt: function(i) { + byteAt: function() { // see implementations }, /** @@ -79,7 +79,7 @@ DataReader.prototype = { * @param {number} size the number of bytes to read. * @return {Object} the raw data, implementation specific. */ - readData: function(size) { + readData: function() { // see implementations }, /** @@ -87,7 +87,7 @@ DataReader.prototype = { * @param {string} sig the signature to find. * @return {number} the index of the last occurrence, -1 if not found. */ - lastIndexOfSignature: function(sig) { + lastIndexOfSignature: function() { // see implementations }, /** @@ -95,7 +95,7 @@ DataReader.prototype = { * @param {string} sig the expected signature * @return {boolean} true if the signature matches, false otherwise. */ - readAndCheckSignature: function(sig) { + readAndCheckSignature: function() { // see implementations }, /** @@ -105,12 +105,12 @@ DataReader.prototype = { readDate: function() { var dostime = this.readInt(4); return new Date(Date.UTC( - ((dostime >> 25) & 0x7f) + 1980, // year - ((dostime >> 21) & 0x0f) - 1, // month - (dostime >> 16) & 0x1f, // day - (dostime >> 11) & 0x1f, // hour - (dostime >> 5) & 0x3f, // minute - (dostime & 0x1f) << 1)); // second + ((dostime >> 25) & 0x7f) + 1980, // year + ((dostime >> 21) & 0x0f) - 1, // month + (dostime >> 16) & 0x1f, // day + (dostime >> 11) & 0x1f, // hour + (dostime >> 5) & 0x3f, // minute + (dostime & 0x1f) << 1)); // second } }; module.exports = DataReader; diff --git a/lib/reader/NodeBufferReader.js b/lib/reader/NodeBufferReader.js index 5d4d3cb3..cbedf258 100644 --- a/lib/reader/NodeBufferReader.js +++ b/lib/reader/NodeBufferReader.js @@ -1,6 +1,6 @@ -'use strict'; -var Uint8ArrayReader = require('./Uint8ArrayReader'); -var utils = require('../utils'); +"use strict"; +var Uint8ArrayReader = require("./Uint8ArrayReader"); +var utils = require("../utils"); function NodeBufferReader(data) { Uint8ArrayReader.call(this, data); diff --git a/lib/reader/StringReader.js b/lib/reader/StringReader.js index e64e58ab..fc90784a 100644 --- a/lib/reader/StringReader.js +++ b/lib/reader/StringReader.js @@ -1,6 +1,6 @@ -'use strict'; -var DataReader = require('./DataReader'); -var utils = require('../utils'); +"use strict"; +var DataReader = require("./DataReader"); +var utils = require("../utils"); function StringReader(data) { DataReader.call(this, data); diff --git a/lib/reader/Uint8ArrayReader.js b/lib/reader/Uint8ArrayReader.js index c753dc47..2bf2bdcf 100644 --- a/lib/reader/Uint8ArrayReader.js +++ b/lib/reader/Uint8ArrayReader.js @@ -1,6 +1,6 @@ -'use strict'; -var ArrayReader = require('./ArrayReader'); -var utils = require('../utils'); +"use strict"; +var ArrayReader = require("./ArrayReader"); +var utils = require("../utils"); function Uint8ArrayReader(data) { ArrayReader.call(this, data); diff --git a/lib/reader/readerFor.js b/lib/reader/readerFor.js index c089ea0f..7558eb4f 100644 --- a/lib/reader/readerFor.js +++ b/lib/reader/readerFor.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -var utils = require('../utils'); -var support = require('../support'); -var ArrayReader = require('./ArrayReader'); -var StringReader = require('./StringReader'); -var NodeBufferReader = require('./NodeBufferReader'); -var Uint8ArrayReader = require('./Uint8ArrayReader'); +var utils = require("../utils"); +var support = require("../support"); +var ArrayReader = require("./ArrayReader"); +var StringReader = require("./StringReader"); +var NodeBufferReader = require("./NodeBufferReader"); +var Uint8ArrayReader = require("./Uint8ArrayReader"); /** * Create a reader adapted to the data. diff --git a/lib/signature.js b/lib/signature.js index 4ee817b8..a799611f 100644 --- a/lib/signature.js +++ b/lib/signature.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; exports.LOCAL_FILE_HEADER = "PK\x03\x04"; exports.CENTRAL_FILE_HEADER = "PK\x01\x02"; exports.CENTRAL_DIRECTORY_END = "PK\x05\x06"; diff --git a/lib/stream/ConvertWorker.js b/lib/stream/ConvertWorker.js index ab7ee84d..22d27b0b 100644 --- a/lib/stream/ConvertWorker.js +++ b/lib/stream/ConvertWorker.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -var GenericWorker = require('./GenericWorker'); -var utils = require('../utils'); +var GenericWorker = require("./GenericWorker"); +var utils = require("../utils"); /** * A worker which convert chunks to a specified type. diff --git a/lib/stream/Crc32Probe.js b/lib/stream/Crc32Probe.js index 93f0ad38..59c3da0b 100644 --- a/lib/stream/Crc32Probe.js +++ b/lib/stream/Crc32Probe.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; -var GenericWorker = require('./GenericWorker'); -var crc32 = require('../crc32'); -var utils = require('../utils'); +var GenericWorker = require("./GenericWorker"); +var crc32 = require("../crc32"); +var utils = require("../utils"); /** * A worker which calculate the crc32 of the data flowing through. diff --git a/lib/stream/DataLengthProbe.js b/lib/stream/DataLengthProbe.js index c6915cdb..12356926 100644 --- a/lib/stream/DataLengthProbe.js +++ b/lib/stream/DataLengthProbe.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -var utils = require('../utils'); -var GenericWorker = require('./GenericWorker'); +var utils = require("../utils"); +var GenericWorker = require("./GenericWorker"); /** * A worker which calculate the total length of the data flowing through. diff --git a/lib/stream/DataWorker.js b/lib/stream/DataWorker.js index 5e3fa3a2..ffb99bdd 100644 --- a/lib/stream/DataWorker.js +++ b/lib/stream/DataWorker.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -var utils = require('../utils'); -var GenericWorker = require('./GenericWorker'); +var utils = require("../utils"); +var GenericWorker = require("./GenericWorker"); // the size of the generated chunks // TODO expose this as a public variable @@ -92,15 +92,15 @@ DataWorker.prototype._tick = function() { return this.end(); } else { switch(this.type) { - case "string": - data = this.data.substring(this.index, nextIndex); + case "string": + data = this.data.substring(this.index, nextIndex); break; - case "uint8array": - data = this.data.subarray(this.index, nextIndex); + case "uint8array": + data = this.data.subarray(this.index, nextIndex); break; - case "array": - case "nodebuffer": - data = this.data.slice(this.index, nextIndex); + case "array": + case "nodebuffer": + data = this.data.slice(this.index, nextIndex); break; } this.index = nextIndex; diff --git a/lib/stream/GenericWorker.js b/lib/stream/GenericWorker.js index cc3f8fac..4b283101 100644 --- a/lib/stream/GenericWorker.js +++ b/lib/stream/GenericWorker.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * A worker that does nothing but passing chunks to the next one. This is like @@ -31,9 +31,9 @@ function GenericWorker(name) { this.isLocked = false; // the event listeners this._listeners = { - 'data':[], - 'end':[], - 'error':[] + "data":[], + "end":[], + "error":[] }; // the previous worker, if any this.previous = null; @@ -150,13 +150,13 @@ GenericWorker.prototype = { this.mergeStreamInfo(); this.previous = previous; var self = this; - previous.on('data', function (chunk) { + previous.on("data", function (chunk) { self.processChunk(chunk); }); - previous.on('end', function () { + previous.on("end", function () { self.end(); }); - previous.on('error', function (e) { + previous.on("error", function (e) { self.error(e); }); return this; @@ -225,7 +225,7 @@ GenericWorker.prototype = { */ mergeStreamInfo : function () { for(var key in this.extraStreamInfo) { - if (!this.extraStreamInfo.hasOwnProperty(key)) { + if (!Object.prototype.hasOwnProperty.call(this.extraStreamInfo, key)) { continue; } this.streamInfo[key] = this.extraStreamInfo[key]; diff --git a/lib/stream/StreamHelper.js b/lib/stream/StreamHelper.js index 09958deb..64575132 100644 --- a/lib/stream/StreamHelper.js +++ b/lib/stream/StreamHelper.js @@ -1,17 +1,19 @@ -'use strict'; +"use strict"; -var utils = require('../utils'); -var ConvertWorker = require('./ConvertWorker'); -var GenericWorker = require('./GenericWorker'); -var base64 = require('../base64'); +var utils = require("../utils"); +var ConvertWorker = require("./ConvertWorker"); +var GenericWorker = require("./GenericWorker"); +var base64 = require("../base64"); var support = require("../support"); var external = require("../external"); var NodejsStreamOutputAdapter = null; if (support.nodestream) { try { - NodejsStreamOutputAdapter = require('../nodejs/NodejsStreamOutputAdapter'); - } catch(e) {} + NodejsStreamOutputAdapter = require("../nodejs/NodejsStreamOutputAdapter"); + } catch(e) { + // ignore + } } /** @@ -25,12 +27,12 @@ if (support.nodestream) { */ function transformZipOutput(type, content, mimeType) { switch(type) { - case "blob" : - return utils.newBlob(utils.transformTo("arraybuffer", content), mimeType); - case "base64" : - return base64.encode(content); - default : - return utils.transformTo(type, content); + case "blob" : + return utils.newBlob(utils.transformTo("arraybuffer", content), mimeType); + case "base64" : + return base64.encode(content); + default : + return utils.transformTo(type, content); } } @@ -47,21 +49,21 @@ function concat (type, dataArray) { totalLength += dataArray[i].length; } switch(type) { - case "string": - return dataArray.join(""); - case "array": - return Array.prototype.concat.apply([], dataArray); - case "uint8array": - res = new Uint8Array(totalLength); - for(i = 0; i < dataArray.length; i++) { - res.set(dataArray[i], index); - index += dataArray[i].length; - } - return res; - case "nodebuffer": - return Buffer.concat(dataArray); - default: - throw new Error("concat : unsupported type '" + type + "'"); + case "string": + return dataArray.join(""); + case "array": + return Array.prototype.concat.apply([], dataArray); + case "uint8array": + res = new Uint8Array(totalLength); + for(i = 0; i < dataArray.length; i++) { + res.set(dataArray[i], index); + index += dataArray[i].length; + } + return res; + case "nodebuffer": + return Buffer.concat(dataArray); + default: + throw new Error("concat : unsupported type '" + type + "'"); } } @@ -81,26 +83,26 @@ function accumulate(helper, updateCallback) { resultType = helper._outputType, mimeType = helper._mimeType; helper - .on('data', function (data, meta) { - dataArray.push(data); - if(updateCallback) { - updateCallback(meta); - } - }) - .on('error', function(err) { - dataArray = []; - reject(err); - }) - .on('end', function (){ - try { - var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType); - resolve(result); - } catch (e) { - reject(e); - } - dataArray = []; - }) - .resume(); + .on("data", function (data, meta) { + dataArray.push(data); + if(updateCallback) { + updateCallback(meta); + } + }) + .on("error", function(err) { + dataArray = []; + reject(err); + }) + .on("end", function (){ + try { + var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType); + resolve(result); + } catch (e) { + reject(e); + } + dataArray = []; + }) + .resume(); }); } @@ -114,12 +116,12 @@ function accumulate(helper, updateCallback) { function StreamHelper(worker, outputType, mimeType) { var internalType = outputType; switch(outputType) { - case "blob": - case "arraybuffer": - internalType = "uint8array"; + case "blob": + case "arraybuffer": + internalType = "uint8array"; break; - case "base64": - internalType = "string"; + case "base64": + internalType = "string"; break; } diff --git a/lib/support.js b/lib/support.js index 9a18aafd..ef60feaa 100644 --- a/lib/support.js +++ b/lib/support.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; exports.base64 = true; exports.array = true; @@ -23,7 +23,7 @@ else { var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder; var builder = new Builder(); builder.append(buffer); - exports.blob = builder.getBlob('application/zip').size === 0; + exports.blob = builder.getBlob("application/zip").size === 0; } catch (e) { exports.blob = false; @@ -32,7 +32,7 @@ else { } try { - exports.nodestream = !!require('readable-stream').Readable; + exports.nodestream = !!require("readable-stream").Readable; } catch(e) { exports.nodestream = false; } diff --git a/lib/utf8.js b/lib/utf8.js index 5c1380f3..18e8f829 100644 --- a/lib/utf8.js +++ b/lib/utf8.js @@ -1,9 +1,9 @@ -'use strict'; +"use strict"; -var utils = require('./utils'); -var support = require('./support'); -var nodejsUtils = require('./nodejsUtils'); -var GenericWorker = require('./stream/GenericWorker'); +var utils = require("./utils"); +var support = require("./support"); +var nodejsUtils = require("./nodejsUtils"); +var GenericWorker = require("./stream/GenericWorker"); /** * The following functions come from pako, from pako/lib/utils/strings @@ -15,7 +15,7 @@ var GenericWorker = require('./stream/GenericWorker'); // because max possible codepoint is 0x10ffff var _utf8len = new Array(256); for (var i=0; i<256; i++) { - _utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1); + _utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1); } _utf8len[254]=_utf8len[254]=1; // Invalid sequence start @@ -106,7 +106,7 @@ var utf8border = function(buf, max) { // convert array to string var buf2string = function (buf) { - var str, i, out, c, c_len; + var i, out, c, c_len; var len = buf.length; // Reserve max possible length (2 words per char) diff --git a/lib/utils.js b/lib/utils.js index 68ad18da..fe585f40 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -var support = require('./support'); -var base64 = require('./base64'); -var nodejsUtils = require('./nodejsUtils'); +var support = require("./support"); +var base64 = require("./base64"); +var nodejsUtils = require("./nodejsUtils"); var external = require("./external"); -require('setimmediate'); +require("setimmediate"); /** @@ -17,9 +17,9 @@ require('setimmediate'); function string2binary(str) { var result = null; if (support.uint8array) { - result = new Uint8Array(str.length); + result = new Uint8Array(str.length); } else { - result = new Array(str.length); + result = new Array(str.length); } return stringToArrayLike(str, result); } @@ -387,11 +387,11 @@ exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is pa * @return {string} a pretty string. */ exports.pretty = function(str) { - var res = '', + var res = "", code, i; for (i = 0; i < (str || "").length; i++) { code = str.charCodeAt(i); - res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase(); + res += "\\x" + (code < 16 ? "0" : "") + code.toString(16).toUpperCase(); } return res; }; @@ -429,7 +429,7 @@ exports.extend = function() { var result = {}, i, attr; for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers for (attr in arguments[i]) { - if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") { + if (Object.prototype.hasOwnProperty.call(arguments[i], attr) && typeof result[attr] === "undefined") { result[attr] = arguments[i][attr]; } } @@ -452,7 +452,7 @@ exports.prepareContent = function(name, inputData, isBinary, isOptimizedBinarySt var promise = external.Promise.resolve(inputData).then(function(data) { - var isBlob = support.blob && (data instanceof Blob || ['[object File]', '[object Blob]'].indexOf(Object.prototype.toString.call(data)) !== -1); + var isBlob = support.blob && (data instanceof Blob || ["[object File]", "[object Blob]"].indexOf(Object.prototype.toString.call(data)) !== -1); if (isBlob && typeof FileReader !== "undefined") { return new external.Promise(function (resolve, reject) { diff --git a/lib/zipEntries.js b/lib/zipEntries.js index 2e3aba90..13cb4777 100644 --- a/lib/zipEntries.js +++ b/lib/zipEntries.js @@ -1,10 +1,9 @@ -'use strict'; -var readerFor = require('./reader/readerFor'); -var utils = require('./utils'); -var sig = require('./signature'); -var ZipEntry = require('./zipEntry'); -var utf8 = require('./utf8'); -var support = require('./support'); +"use strict"; +var readerFor = require("./reader/readerFor"); +var utils = require("./utils"); +var sig = require("./signature"); +var ZipEntry = require("./zipEntry"); +var support = require("./support"); // class ZipEntries {{{ /** * All the entries in the zip file. diff --git a/lib/zipEntry.js b/lib/zipEntry.js index f204524e..2d2565f4 100644 --- a/lib/zipEntry.js +++ b/lib/zipEntry.js @@ -1,11 +1,11 @@ -'use strict'; -var readerFor = require('./reader/readerFor'); -var utils = require('./utils'); -var CompressedObject = require('./compressedObject'); -var crc32fn = require('./crc32'); -var utf8 = require('./utf8'); -var compressions = require('./compressions'); -var support = require('./support'); +"use strict"; +var readerFor = require("./reader/readerFor"); +var utils = require("./utils"); +var CompressedObject = require("./compressedObject"); +var crc32fn = require("./crc32"); +var utf8 = require("./utf8"); +var compressions = require("./compressions"); +var support = require("./support"); var MADE_BY_DOS = 0x00; var MADE_BY_UNIX = 0x03; @@ -17,7 +17,7 @@ var MADE_BY_UNIX = 0x03; */ var findCompression = function(compressionMethod) { for (var method in compressions) { - if (!compressions.hasOwnProperty(method)) { + if (!Object.prototype.hasOwnProperty.call(compressions, method)) { continue; } if (compressions[method].magic === compressionMethod) { @@ -153,7 +153,7 @@ ZipEntry.prototype = { } // fail safe : if the name ends with a / it probably means a folder - if (!this.dir && this.fileNameStr.slice(-1) === '/') { + if (!this.dir && this.fileNameStr.slice(-1) === "/") { this.dir = true; } }, @@ -162,8 +162,7 @@ ZipEntry.prototype = { * Parse the ZIP64 extra field and merge the info in the current ZipEntry. * @param {DataReader} reader the reader to use. */ - parseZIP64ExtraField: function(reader) { - + parseZIP64ExtraField: function() { if (!this.extraFields[0x0001]) { return; } diff --git a/lib/zipObject.js b/lib/zipObject.js index 04d7b618..8d709d2c 100644 --- a/lib/zipObject.js +++ b/lib/zipObject.js @@ -1,10 +1,10 @@ -'use strict'; +"use strict"; -var StreamHelper = require('./stream/StreamHelper'); -var DataWorker = require('./stream/DataWorker'); -var utf8 = require('./utf8'); -var CompressedObject = require('./compressedObject'); -var GenericWorker = require('./stream/GenericWorker'); +var StreamHelper = require("./stream/StreamHelper"); +var DataWorker = require("./stream/DataWorker"); +var utf8 = require("./utf8"); +var CompressedObject = require("./compressedObject"); +var GenericWorker = require("./stream/GenericWorker"); /** * A simple object representing a file in the zip file. diff --git a/test/.eslintrc.js b/test/.eslintrc.js new file mode 100644 index 00000000..b997d8c1 --- /dev/null +++ b/test/.eslintrc.js @@ -0,0 +1,10 @@ +"use strict"; + +module.exports = { + globals: { + JSZip: false, + JSZipUtils: false, + JSZipTestUtils: false, + QUnit: false, + }, +}; diff --git a/test/asserts/constructor.js b/test/asserts/constructor.js index 3f0f3e30..c3b12c6a 100644 --- a/test/asserts/constructor.js +++ b/test/asserts/constructor.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("constructor"); diff --git a/test/asserts/delete.js b/test/asserts/delete.js index abd3ac8b..0e089c4f 100644 --- a/test/asserts/delete.js +++ b/test/asserts/delete.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("delete"); @@ -12,7 +11,7 @@ JSZipTestUtils.testZipFile("Delete file", "ref/text.zip", function(assert, expec zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete file in folder", "ref/folder.zip", function(assert, expected) { @@ -23,7 +22,7 @@ JSZipTestUtils.testZipFile("Delete file in folder", "ref/folder.zip", function(a zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete file in folder, with a relative path", "ref/folder.zip", function(assert, expected) { @@ -35,7 +34,7 @@ JSZipTestUtils.testZipFile("Delete file in folder, with a relative path", "ref/f zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete folder", "ref/text.zip", function(assert, expected) { @@ -47,7 +46,7 @@ JSZipTestUtils.testZipFile("Delete folder", "ref/text.zip", function(assert, exp zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete folder with a final /", "ref/text.zip", function(assert, expected) { @@ -59,7 +58,7 @@ JSZipTestUtils.testZipFile("Delete folder with a final /", "ref/text.zip", funct zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete unknown path", "ref/text.zip", function(assert, expected) { @@ -71,7 +70,7 @@ JSZipTestUtils.testZipFile("Delete unknown path", "ref/text.zip", function(asser zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete nested folders", "ref/text.zip", function(assert, expected) { @@ -85,7 +84,7 @@ JSZipTestUtils.testZipFile("Delete nested folders", "ref/text.zip", function(ass zip.generateAsync({type:"binarystring"}).then(function(actual) { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Delete nested folders from relative path", "ref/folder.zip", function(assert, expected) { @@ -98,6 +97,5 @@ JSZipTestUtils.testZipFile("Delete nested folders from relative path", "ref/fold assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); - diff --git a/test/asserts/deprecated.js b/test/asserts/deprecated.js index 2080cc11..72ebc66e 100644 --- a/test/asserts/deprecated.js +++ b/test/asserts/deprecated.js @@ -1,10 +1,8 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("deprecated"); QUnit.test("Removed load method throws an exception", function(assert) { - var file = JSZipTestUtils.createZipAll().file("Hello.txt"); assert.throws( function() { new JSZip().load(""); @@ -14,10 +12,10 @@ QUnit.test("Removed load method throws an exception", function(assert) { ); }); QUnit.test("Removed constructor with data throws an exception", function(assert) { - var file = JSZipTestUtils.createZipAll().file("Hello.txt"); assert.throws( function() { - var zip = new JSZip(""); + // eslint-disable-next-line no-new + new JSZip(""); }, /upgrade guide/, "new JSZip(data) throws an exception" @@ -34,7 +32,6 @@ QUnit.test("Removed asText method throws an exception", function(assert) { ); }); QUnit.test("Removed generate method throws an exception", function(assert) { - var file = JSZipTestUtils.createZipAll().file("Hello.txt"); assert.throws( function() { new JSZip().generate({type:"string"}); diff --git a/test/asserts/external.js b/test/asserts/external.js index 083565ad..613da0c9 100644 --- a/test/asserts/external.js +++ b/test/asserts/external.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils,Promise */ -'use strict'; +"use strict"; QUnit.module("external"); @@ -24,7 +23,7 @@ function createPromiseProxy(OriginalPromise) { return new MyShinyPromise(this._promise.then(onFulfilled, onRejected)); }, "catch": function (onRejected) { - return new MyShinyPromise(this._promise['catch'](onRejected)); + return new MyShinyPromise(this._promise["catch"](onRejected)); }, isACustomImplementation: true }; @@ -63,11 +62,11 @@ QUnit.test("external.Promise can be replaced in .async()", function (assert) { JSZip.external.Promise = MyShinyPromise; - var promise = JSZipTestUtils.createZipAll().file("Hello.txt").async("string").then(function (result) { + var promise = JSZipTestUtils.createZipAll().file("Hello.txt").async("string").then(function () { assert.ok(MyShinyPromise.calls > 0, "at least 1 call of the new Promise"); JSZip.external.Promise = OriginalPromise; done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); assert.ok(promise.isACustomImplementation, "the custom implementation is used"); }); @@ -79,11 +78,11 @@ QUnit.test("external.Promise can be replaced in .generateAsync()", function (ass JSZip.external.Promise = MyShinyPromise; - var promise = JSZipTestUtils.createZipAll().generateAsync({type:"string"}).then(function (result) { + var promise = JSZipTestUtils.createZipAll().generateAsync({type:"string"}).then(function () { assert.ok(MyShinyPromise.calls > 0, "at least 1 call of the new Promise"); JSZip.external.Promise = OriginalPromise; done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); assert.ok(promise.isACustomImplementation, "the custom implementation is used"); }); @@ -95,11 +94,11 @@ JSZipTestUtils.testZipFile("external.Promise can be replaced in .loadAsync()", " JSZip.external.Promise = MyShinyPromise; - var promise = JSZip.loadAsync(all).then(function (result) { + var promise = JSZip.loadAsync(all).then(function () { assert.ok(MyShinyPromise.calls > 0, "at least 1 call of the new Promise"); JSZip.external.Promise = OriginalPromise; done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); assert.ok(promise.isACustomImplementation, "the custom implementation is used"); }); diff --git a/test/asserts/file.js b/test/asserts/file.js index 6b406be8..1d36ff0f 100644 --- a/test/asserts/file.js +++ b/test/asserts/file.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils,Promise */ -'use strict'; +"use strict"; QUnit.module("file", function () { @@ -30,7 +29,7 @@ QUnit.module("file", function () { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Zip text, folder and image", "ref/all.zip", function(assert, expected) { @@ -42,7 +41,7 @@ QUnit.module("file", function () { assert.ok(JSZipTestUtils.similar(actual, expected, 3 * JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Add a file to overwrite", "ref/text.zip", function(assert, expected) { @@ -55,7 +54,7 @@ QUnit.module("file", function () { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Zip text file with date", "ref/text.zip", function(assert, expected) { @@ -74,7 +73,7 @@ QUnit.module("file", function () { assert.ok(JSZipTestUtils.similar(actual, expected, 10) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); @@ -86,7 +85,7 @@ QUnit.module("file", function () { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("add file: from XHR (with bytes > 255)", "ref/text.zip", function(assert, textZip) { @@ -97,17 +96,17 @@ QUnit.module("file", function () { // high-order byte is discarded and won't mess up the result JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("add file: wrong string as base64", function(assert) { var zip = new JSZip(); zip.file("text.txt", "a random string", {base64:true}); var done = assert.async(); - zip.generateAsync({type:"binarystring"}).then(function(actual) { + zip.generateAsync({type:"binarystring"}).then(function() { assert.ok(false, "generateAsync should fail"); done(); - })['catch'](function (e) { + })["catch"](function (e) { assert.equal(e.message, "Invalid base64 input, bad content length.", "triggers the correct error"); done(); }); @@ -117,10 +116,10 @@ QUnit.module("file", function () { var zip = new JSZip(); zip.file("text.txt", "data:image/png;base64,YmFzZTY0", {base64:true}); var done = assert.async(); - zip.generateAsync({type:"binarystring"}).then(function(actual) { + zip.generateAsync({type:"binarystring"}).then(function() { assert.ok(false, "generateAsync should fail"); done(); - })['catch'](function (e) { + })["catch"](function (e) { assert.equal(e.message, "Invalid base64 input, it looks like a data url.", "triggers the correct error"); done(); }); @@ -144,29 +143,29 @@ QUnit.module("file", function () { var done = assert.async(); opts.zip.generateAsync({type:"binarystring"}) - .then(JSZip.loadAsync) - .then(function(zip) { - var reloaded = { - name : "(reloaded) " + opts.name, - zip : zip, - textData : opts.textData, - rawData : opts.rawData - }; - _actualTestFileDataGetters.testGetter(assert, reloaded, "string"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "text"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "base64"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "array"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "binarystring"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "arraybuffer"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "uint8array"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "nodebuffer"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "blob"); - _actualTestFileDataGetters.testGetter(assert, reloaded, "unknown"); - _actualTestFileDataGetters.testGetter(assert, reloaded, null); - - opts.zip.file("file.txt", "changing the content after the call won't change the result"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(JSZip.loadAsync) + .then(function(zip) { + var reloaded = { + name : "(reloaded) " + opts.name, + zip : zip, + textData : opts.textData, + rawData : opts.rawData + }; + _actualTestFileDataGetters.testGetter(assert, reloaded, "string"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "text"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "base64"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "array"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "binarystring"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "arraybuffer"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "uint8array"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "nodebuffer"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "blob"); + _actualTestFileDataGetters.testGetter(assert, reloaded, "unknown"); + _actualTestFileDataGetters.testGetter(assert, reloaded, null); + + opts.zip.file("file.txt", "changing the content after the call won't change the result"); + done(); + })["catch"](JSZipTestUtils.assertNoError); opts.zip.file("file.txt", "changing the content after the call won't change the result"); } @@ -175,8 +174,6 @@ QUnit.module("file", function () { testGetter : function (assert, opts, askedType) { var asyncTestName = "[test = " + opts.name + "] [method = async(" + askedType + ")] "; - var err = null, content = null; - var stream = opts.zip.file("file.txt").internalStream(askedType); JSZipTestUtils.checkBasicStreamBehavior(assert, stream, asyncTestName); @@ -345,16 +342,16 @@ QUnit.module("file", function () { zip.file("test.txt", new Date()); zip.file("test.txt") - .async("string") + .async("string") // XXX zip.file(name, data) returns a ZipObject for chaining, // we need to try to get the value to get the error - .then(function () { - assert.ok(false, "An unsupported object was added, but no exception thrown"); - done(); - }, function (e) { - assert.ok(e.message.match("Is it in a supported JavaScript type"), "the error message is useful"); - done(); - }); + .then(function () { + assert.ok(false, "An unsupported object was added, but no exception thrown"); + done(); + }, function (e) { + assert.ok(e.message.match("Is it in a supported JavaScript type"), "the error message is useful"); + done(); + }); }); if (JSZip.support.uint8array) { @@ -422,7 +419,7 @@ QUnit.module("file", function () { if (typeof Promise !== "undefined") { QUnit.test("add file: file(name, native Promise)", function (assert) { var str2promise = function (str) { - return new Promise(function(resolve, reject) { + return new Promise(function(resolve) { setTimeout(function () { resolve(str); }, 10); @@ -444,7 +441,7 @@ QUnit.module("file", function () { QUnit.test("add file: file(name, polyfill Promise[string] as binary)", function (assert) { var str2promise = function (str) { - return new JSZip.external.Promise(function(resolve, reject) { + return new JSZip.external.Promise(function(resolve) { setTimeout(function () { resolve(str); }, 10); @@ -457,7 +454,7 @@ QUnit.module("file", function () { QUnit.test("add file: file(name, polyfill Promise[string] force text)", function (assert) { var str2promise = function (str) { - return new JSZip.external.Promise(function(resolve, reject) { + return new JSZip.external.Promise(function(resolve) { setTimeout(function () { resolve(str); }, 10); @@ -496,7 +493,7 @@ QUnit.module("file", function () { if (JSZip.support.blob) { QUnit.test("add file: file(name, polyfill Promise[Blob])", function (assert) { var str2promiseOfBlob = function (str) { - return new JSZip.external.Promise(function(resolve, reject) { + return new JSZip.external.Promise(function(resolve) { setTimeout(function () { resolve(str2blob(str)); }, 10); @@ -560,7 +557,7 @@ QUnit.module("file", function () { assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("file() creates a folder with dir:true", function (assert) { @@ -568,7 +565,7 @@ QUnit.module("file", function () { zip.file("folder", null, { dir : true }); - assert.ok(zip.files['folder/'].dir, "the folder with options is marked as a folder"); + assert.ok(zip.files["folder/"].dir, "the folder with options is marked as a folder"); }); QUnit.test("file() creates a folder with the right unix permissions", function (assert) { @@ -576,7 +573,7 @@ QUnit.module("file", function () { zip.file("folder", null, { unixPermissions : parseInt("40500", 8) }); - assert.ok(zip.files['folder/'].dir, "the folder with options is marked as a folder"); + assert.ok(zip.files["folder/"].dir, "the folder with options is marked as a folder"); }); QUnit.test("file() creates a folder with the right dos permissions", function (assert) { @@ -584,7 +581,7 @@ QUnit.module("file", function () { zip.file("folder", null, { dosPermissions : parseInt("010000", 2) }); - assert.ok(zip.files['folder/'].dir, "the folder with options is marked as a folder"); + assert.ok(zip.files["folder/"].dir, "the folder with options is marked as a folder"); }); QUnit.test("A folder stays a folder when created with file", function (assert) { @@ -598,23 +595,23 @@ QUnit.module("file", function () { unixPermissions : parseInt("40500", 8) }); - assert.ok(zip.files['folder/'].dir, "the folder with options is marked as a folder"); - assert.equal(zip.files['folder/'].date.getTime(), referenceDate.getTime(), "the folder with options has the correct date"); - assert.equal(zip.files['folder/'].comment, referenceComment, "the folder with options has the correct comment"); - assert.equal(zip.files['folder/'].unixPermissions.toString(8), "40500", "the folder with options has the correct UNIX permissions"); + assert.ok(zip.files["folder/"].dir, "the folder with options is marked as a folder"); + assert.equal(zip.files["folder/"].date.getTime(), referenceDate.getTime(), "the folder with options has the correct date"); + assert.equal(zip.files["folder/"].comment, referenceComment, "the folder with options has the correct comment"); + assert.equal(zip.files["folder/"].unixPermissions.toString(8), "40500", "the folder with options has the correct UNIX permissions"); var done = assert.async(); zip.generateAsync({type:"string", platform:"UNIX"}) - .then(JSZip.loadAsync) - .then(function (reloaded) { - assert.ok(reloaded.files['folder/'].dir, "the folder with options is marked as a folder"); - - assert.ok(reloaded.files['folder/'].dir, "the folder with options is marked as a folder"); - assert.equal(reloaded.files['folder/'].date.getTime(), referenceDate.getTime(), "the folder with options has the correct date"); - assert.equal(reloaded.files['folder/'].comment, referenceComment, "the folder with options has the correct comment"); - assert.equal(reloaded.files['folder/'].unixPermissions.toString(8), "40500", "the folder with options has the correct UNIX permissions"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(JSZip.loadAsync) + .then(function (reloaded) { + assert.ok(reloaded.files["folder/"].dir, "the folder with options is marked as a folder"); + + assert.ok(reloaded.files["folder/"].dir, "the folder with options is marked as a folder"); + assert.equal(reloaded.files["folder/"].date.getTime(), referenceDate.getTime(), "the folder with options has the correct date"); + assert.equal(reloaded.files["folder/"].comment, referenceComment, "the folder with options has the correct comment"); + assert.equal(reloaded.files["folder/"].unixPermissions.toString(8), "40500", "the folder with options has the correct UNIX permissions"); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); @@ -626,8 +623,8 @@ QUnit.module("file", function () { zip.file("folder_with_slash/", null, { dir : true }); - assert.ok(zip.files['folder_without_slash/'], "added a slash if not provided"); - assert.ok(zip.files['folder_with_slash/'], "keep the existing slash"); + assert.ok(zip.files["folder_without_slash/"], "added a slash if not provided"); + assert.ok(zip.files["folder_with_slash/"], "keep the existing slash"); }); QUnit.test("folder() doesn't overwrite existing entries", function (assert) { @@ -642,8 +639,8 @@ QUnit.module("file", function () { // calling folder() doesn't override it zip.folder("folder"); - assert.equal(zip.files['folder/'].comment, referenceComment, "the folder with options has the correct comment"); - assert.equal(zip.files['folder/'].unixPermissions.toString(8), "40500", "the folder with options has the correct UNIX permissions"); + assert.equal(zip.files["folder/"].comment, referenceComment, "the folder with options has the correct comment"); + assert.equal(zip.files["folder/"].unixPermissions.toString(8), "40500", "the folder with options has the correct UNIX permissions"); }); QUnit.test("createFolders works on a file", function (assert) { @@ -676,17 +673,17 @@ QUnit.module("file", function () { QUnit.test("A folder stays a folder", function (assert) { var zip = new JSZip(); zip.folder("folder/"); - assert.ok(zip.files['folder/'].dir, "the folder is marked as a folder"); + assert.ok(zip.files["folder/"].dir, "the folder is marked as a folder"); var done = assert.async(); zip.generateAsync({type:"binarystring"}) - .then(JSZip.loadAsync) - .then(function (reloaded) { - assert.ok(reloaded.files['folder/'].dir, "the folder is marked as a folder"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(JSZip.loadAsync) + .then(function (reloaded) { + assert.ok(reloaded.files["folder/"].dir, "the folder is marked as a folder"); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("Folders are created by default", function (assert) { @@ -716,7 +713,7 @@ QUnit.module("file", function () { zip.file("Readme.French").async("string").then(function (content) { assert.equal(content, "Bonjour tout le monde!\n", "Exact match found"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); assert.equal(zip.file("Readme.Deutsch"), null, "Match exactly nothing"); assert.equal(zip.file(/Readme\../).length, 2, "Match regex free text"); assert.equal(zip.file(/pirate/i).length, 1, "Match regex 1 result"); @@ -732,15 +729,15 @@ QUnit.module("file", function () { zip.file("files/translation/Readme.French").async("string").then(function (content) { assert.equal(content, "Bonjour tout le monde!\n", "finding file with the full path"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); zip.folder("files").file("translation/Readme.French").async("string").then(function (content) { assert.equal(content, "Bonjour tout le monde!\n", "finding file with a relative path"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); zip.folder("files/translation").file("Readme.French").async("string").then(function (content) { assert.equal(content, "Bonjour tout le monde!\n", "finding file with a relative path"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("Finding files (regex) with a relative folder", function (assert) { @@ -798,12 +795,12 @@ QUnit.module("file", function () { zipObjectsAssertions(assert, zip.files["Hello.txt"]); var done = assert.async(); zip.generateAsync({type:"binarystring"}) - .then(JSZip.loadAsync) - .then(function(reloaded) { - zipObjectsAssertions(assert, reloaded.file("Hello.txt")); - zipObjectsAssertions(assert, reloaded.files["Hello.txt"]); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(JSZip.loadAsync) + .then(function(reloaded) { + zipObjectsAssertions(assert, reloaded.file("Hello.txt")); + zipObjectsAssertions(assert, reloaded.files["Hello.txt"]); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("generate uses updated ZipObject date attribute", function (assert) { var date = new Date("July 17, 2009 14:36:57"); @@ -812,14 +809,12 @@ QUnit.module("file", function () { zip.files["Hello.txt"].date = date; var done = assert.async(); zip.generateAsync({type:"binarystring"}) - .then(JSZip.loadAsync) - .then(function(reloaded) { - zipObjectsAssertions(assert, reloaded.file("Hello.txt")); - zipObjectsAssertions(assert, reloaded.files["Hello.txt"]); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(JSZip.loadAsync) + .then(function(reloaded) { + zipObjectsAssertions(assert, reloaded.file("Hello.txt")); + zipObjectsAssertions(assert, reloaded.files["Hello.txt"]); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); }); - - diff --git a/test/asserts/filter.js b/test/asserts/filter.js index 935c8ed3..d1be9692 100644 --- a/test/asserts/filter.js +++ b/test/asserts/filter.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("filter"); @@ -8,7 +7,7 @@ QUnit.test("Filtering a zip", function(assert) { zip.file("1.txt", "1\n"); zip.file("2.txt", "2\n"); zip.file("3.log", "3\n"); - var result = zip.filter(function(relativeFilename, file) { + var result = zip.filter(function(relativeFilename) { return relativeFilename.indexOf(".txt") !== -1; }); assert.equal(result.length, 2, "filter has filtered"); @@ -26,7 +25,7 @@ QUnit.test("Filtering a zip from a relative path", function(assert) { zip.file("3.log", "3\n"); var count = 0; - var result = zip.folder("foo").filter(function(relativeFilename, file) { + var result = zip.folder("foo").filter(function(relativeFilename) { count++; return relativeFilename.indexOf("3") !== -1; }); diff --git a/test/asserts/foreach.js b/test/asserts/foreach.js index d058719a..5392ab40 100644 --- a/test/asserts/foreach.js +++ b/test/asserts/foreach.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("forEach"); diff --git a/test/asserts/generate.js b/test/asserts/generate.js index 4830be82..7b794fc2 100644 --- a/test/asserts/generate.js +++ b/test/asserts/generate.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("generate"); @@ -13,31 +12,31 @@ function testGenerateFor(testCases, fn) { function testGenerate(assert, options) { var done = assert.async(); var triggeredCallback = false; - new JSZip.external.Promise(function(resolve, reject) { + new JSZip.external.Promise(function(resolve) { resolve(options.prepare()); }) - .then(function (zip) { - JSZipTestUtils.checkBasicStreamBehavior(assert, zip.generateInternalStream(options.options)); - return zip; - }) - .then(function(zip) { - var promise = zip.generateAsync(options.options); - zip.file("Hello.txt", "updating the zip file after the call won't change the result"); - return promise; - }) - .then(function(result) { - triggeredCallback = true; - options.assertions(null, result); - - if (!options.skipReloadTest) { - JSZipTestUtils.checkGenerateStability(assert, result, options.options); - } - done(); - }, function (err) { - triggeredCallback = true; - options.assertions(err, null); - done(); - }); + .then(function (zip) { + JSZipTestUtils.checkBasicStreamBehavior(assert, zip.generateInternalStream(options.options)); + return zip; + }) + .then(function(zip) { + var promise = zip.generateAsync(options.options); + zip.file("Hello.txt", "updating the zip file after the call won't change the result"); + return promise; + }) + .then(function(result) { + triggeredCallback = true; + options.assertions(null, result); + + if (!options.skipReloadTest) { + JSZipTestUtils.checkGenerateStability(assert, result, options.options); + } + done(); + }, function (err) { + triggeredCallback = true; + options.assertions(err, null); + done(); + }); assert.ok(!triggeredCallback, "the async callback is async"); } @@ -62,7 +61,7 @@ testGenerateFor([{ } }); }); - JSZipTestUtils.testZipFile("generate : type:base64. " + testName, file, function(assert, expected) { + JSZipTestUtils.testZipFile("generate : type:base64. " + testName, file, function(assert) { testGenerate(assert, { prepare : function () { // fix date to get a predictable output @@ -238,11 +237,11 @@ JSZipTestUtils.testZipFile("STORE is the default method", "ref/text.zip", functi var zip = new JSZip(); zip.file("Hello.txt", "Hello World\n"); var done = assert.async(); - zip.generateAsync({type:"binarystring", compression:'STORE'}).then(function(content) { + zip.generateAsync({type:"binarystring", compression:"STORE"}).then(function(content) { // no difference with the "Zip text file" test. assert.ok(JSZipTestUtils.similar(content, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); @@ -257,11 +256,11 @@ function testLazyDecompression(assert, from, to) { }, skipReloadTest : true, options : {type:"binarystring", compression:to}, - assertions : function (err, result) { + assertions : function (err) { assert.equal(err, null, from + " -> " + to + " : no error"); } }); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); } QUnit.test("Lazy decompression works", function(assert) { testLazyDecompression(assert, "STORE", "STORE"); @@ -289,7 +288,7 @@ JSZipTestUtils.testZipFile("empty zip", "ref/empty.zip", function(assert, expect QUnit.test("unknown compression throws an exception", function (assert) { testGenerate(assert, { prepare : JSZipTestUtils.createZipAll, - options : {type:"string",compression:'MAYBE'}, + options : {type:"string",compression:"MAYBE"}, assertions : function (err, result) { assert.equal(result, null, "no data"); assert.ok(err.message.match("not a valid compression"), "the error message is useful"); @@ -316,16 +315,16 @@ QUnit.test("generateAsync uses the current folder level", function (assert) { zip.folder("root1"); zip.folder("root2").file("leaf1", "a"); zip.folder("root2") - .generateAsync({type:"string"}) - .then(JSZip.loadAsync) - .then(function(zip) { - assert.ok(!zip.file("file1"), "root files are not present"); - assert.ok(!zip.file("root1"), "root folders are not present"); - assert.ok(!zip.file("root2"), "root folders are not present"); - assert.ok(zip.file("leaf1"), "leaves are present"); - - done(); - })['catch'](JSZipTestUtils.assertNoError); + .generateAsync({type:"string"}) + .then(JSZip.loadAsync) + .then(function(zip) { + assert.ok(!zip.file("file1"), "root files are not present"); + assert.ok(!zip.file("root1"), "root folders are not present"); + assert.ok(!zip.file("root2"), "root folders are not present"); + assert.ok(zip.file("leaf1"), "leaves are present"); + + done(); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("generateAsync keep the explicit / folder", function (assert) { @@ -335,32 +334,32 @@ QUnit.test("generateAsync keep the explicit / folder", function (assert) { zip.file("/file1", "a"); zip.file("/root1/file2", "b"); zip.generateAsync({type:"string"}) - .then(JSZip.loadAsync) - .then(function(zip) { - assert.ok(zip.file("/file1"), "root files are present"); - assert.ok(zip.file("/root1/file2"), "root folders are present"); + .then(JSZip.loadAsync) + .then(function(zip) { + assert.ok(zip.file("/file1"), "root files are present"); + assert.ok(zip.file("/root1/file2"), "root folders are present"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("generate with promises as files", "ref/all.zip", function (assert, expected) { var done = assert.async(); var zip = new JSZip(); - zip.file("Hello.txt", new JSZip.external.Promise(function (resolve, reject) { + zip.file("Hello.txt", new JSZip.external.Promise(function (resolve) { setTimeout(function () { resolve("Hello World\n"); }, 50); })); - zip.folder("images").file("smile.gif", new JSZip.external.Promise(function (resolve, reject) { + zip.folder("images").file("smile.gif", new JSZip.external.Promise(function (resolve) { setTimeout(function () { resolve("R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs="); }, 100); }), {base64: true}); zip.generateAsync({type:"string"}) - .then(function (result) { - assert.ok(JSZipTestUtils.similar(result, expected, 3 * JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "generated ZIP matches reference ZIP"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (result) { + assert.ok(JSZipTestUtils.similar(result, expected, 3 * JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "generated ZIP matches reference ZIP"); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); diff --git a/test/asserts/load.js b/test/asserts/load.js index ce073cc3..395ec720 100644 --- a/test/asserts/load.js +++ b/test/asserts/load.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("load", function () { @@ -8,26 +7,26 @@ QUnit.module("load", function () { var done = assert.async(); assert.ok(typeof file === "string"); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }) - .then(function(result) { - assert.equal(result, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }) + .then(function(result) { + assert.equal(result, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Load files which shadow Object prototype methods", "ref/pollution.zip", function(assert, file) { var done = assert.async(); assert.ok(typeof file === "string"); JSZip.loadAsync(file) - .then(function (zip) { - assert.notEqual(Object.getPrototypeOf(zip.files), zip.files.__proto__); - return zip.file("__proto__").async("string"); }) - .then(function(result) { - assert.equal(result, "hello\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + assert.notEqual(Object.getPrototypeOf(zip.files), zip.files.__proto__); + return zip.file("__proto__").async("string"); }) + .then(function(result) { + assert.equal(result, "hello\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("load(string) handles bytes > 255", "ref/all.zip", function(assert, file) { @@ -40,13 +39,13 @@ QUnit.module("load", function () { } JSZip.loadAsync(updatedFile) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); @@ -57,13 +56,13 @@ QUnit.module("load", function () { updatedFile[i] = file.charCodeAt(i); } JSZip.loadAsync(updatedFile) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "This a looong file : we need to see the difference between the different compression methods.\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "This a looong file : we need to see the difference between the different compression methods.\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("load(array) handles bytes > 255", "ref/deflate.zip", function(assert, file) { @@ -73,13 +72,13 @@ QUnit.module("load", function () { updatedFile[i] = file.charCodeAt(i) + 0x4200; } JSZip.loadAsync(updatedFile) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "This a looong file : we need to see the difference between the different compression methods.\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "This a looong file : we need to see the difference between the different compression methods.\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); if (JSZip.support.arraybuffer) { @@ -96,28 +95,28 @@ QUnit.module("load", function () { // when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array. // if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file). JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("arraybuffer"); - }).then(function (content){ - assert.equal(content.byteLength, 12, "don't get the original buffer"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("arraybuffer"); + }).then(function (content){ + assert.equal(content.byteLength, 12, "don't get the original buffer"); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("uint8array"); - }).then(function (content){ - assert.equal(content.buffer.byteLength, 12, "don't get a view of the original buffer"); - done(); - }); + .then(function (zip) { + return zip.file("Hello.txt").async("uint8array"); + }).then(function (content){ + assert.equal(content.buffer.byteLength, 12, "don't get a view of the original buffer"); + done(); + }); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - }); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + }); }); } @@ -130,12 +129,12 @@ QUnit.module("load", function () { } JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - }); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + }); }); } @@ -152,28 +151,28 @@ QUnit.module("load", function () { // when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array. // if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file). JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("arraybuffer"); - }).then(function (content){ - assert.equal(content.byteLength, 12, "don't get the original buffer"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("arraybuffer"); + }).then(function (content){ + assert.equal(content.byteLength, 12, "don't get the original buffer"); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("uint8array"); - }).then(function (content){ - assert.equal(content.buffer.byteLength, 12, "don't get a view of the original buffer"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("uint8array"); + }).then(function (content){ + assert.equal(content.buffer.byteLength, 12, "don't get a view of the original buffer"); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); } @@ -181,26 +180,26 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("zip with DEFLATE", "ref/deflate.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "This a looong file : we need to see the difference between the different compression methods.\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "This a looong file : we need to see the difference between the different compression methods.\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // zip -0 -X -z -c archive_comment.zip Hello.txt JSZipTestUtils.testZipFile("read zip with comment", "ref/archive_comment.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - assert.equal(zip.comment, "file comment", "the archive comment was correctly read."); - assert.equal(zip.file("Hello.txt").comment, "entry comment", "the entry comment was correctly read."); - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + assert.equal(zip.comment, "file comment", "the archive comment was correctly read."); + assert.equal(zip.file("Hello.txt").comment, "entry comment", "the entry comment was correctly read."); + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("generate zip with comment", "ref/archive_comment.zip", function(assert, file) { var zip = new JSZip(); @@ -210,19 +209,19 @@ QUnit.module("load", function () { assert.ok(JSZipTestUtils.similar(generated, file, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, generated); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); // zip -0 extra_attributes.zip Hello.txt JSZipTestUtils.testZipFile("zip with extra attributes", "ref/extra_attributes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // use -fz to force use of Zip64 format @@ -230,12 +229,12 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("zip 64", "ref/zip64.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // use -fd to force data descriptors as if streaming @@ -243,12 +242,12 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("zip with data descriptor", "ref/data_descriptor.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // combo of zip64 and data descriptors : @@ -260,56 +259,56 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("nested zip", "ref/nested.zip", function(assert, file) { var done = assert.async(2); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("zip_within_zip.zip").async("binarystring"); - }) - .then(JSZip.loadAsync) - .then(function (innerZip) { - return innerZip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the inner zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("zip_within_zip.zip").async("binarystring"); + }) + .then(JSZip.loadAsync) + .then(function (innerZip) { + return innerZip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the inner zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // zip -fd -0 nested_data_descriptor.zip data_descriptor.zip JSZipTestUtils.testZipFile("nested zip with data descriptors", "ref/nested_data_descriptor.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("data_descriptor.zip").async("binarystring"); - }) - .then(JSZip.loadAsync) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the inner zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("data_descriptor.zip").async("binarystring"); + }) + .then(JSZip.loadAsync) + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the inner zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // zip -fz -0 nested_zip64.zip zip64.zip JSZipTestUtils.testZipFile("nested zip 64", "ref/nested_zip64.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("zip64.zip").async("binarystring"); - }) - .then(JSZip.loadAsync) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the inner zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("zip64.zip").async("binarystring"); + }) + .then(JSZip.loadAsync) + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the inner zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // nested zip 64 with data descriptors @@ -321,23 +320,23 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("Zip text file with UTF-8 characters in filename", "ref/utf8_in_name.zip", function(assert, file) { var done = assert.async(2); JSZip.loadAsync(file) - .then(function (zip){ - assert.ok(zip.file("€15.txt") !== null, "the utf8 file is here."); - return zip.file("€15.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "€15\n", "the utf8 content was correctly read (with file().async)."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip){ + assert.ok(zip.file("€15.txt") !== null, "the utf8 file is here."); + return zip.file("€15.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "€15\n", "the utf8 content was correctly read (with file().async)."); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function (zip){ - return zip.files["€15.txt"].async("string"); - }) - .then(function (content) { - assert.equal(content, "€15\n", "the utf8 content was correctly read (with files[].async)."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip){ + return zip.files["€15.txt"].async("string"); + }) + .then(function (content) { + assert.equal(content, "€15\n", "the utf8 content was correctly read (with files[].async)."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // Created with winrar @@ -345,109 +344,109 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("Zip text file with UTF-8 characters in filename and windows compatibility", "ref/winrar_utf8_in_name.zip", function(assert, file) { var done = assert.async(2); JSZip.loadAsync(file) - .then(function (zip){ - assert.ok(zip.file("€15.txt") !== null, "the utf8 file is here."); - return zip.file("€15.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "€15\n", "the utf8 content was correctly read (with file().async)."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip){ + assert.ok(zip.file("€15.txt") !== null, "the utf8 file is here."); + return zip.file("€15.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "€15\n", "the utf8 content was correctly read (with file().async)."); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function (zip){ - return zip.files["€15.txt"].async("string"); - }) - .then(function (content) { - assert.equal(content, "€15\n", "the utf8 content was correctly read (with files[].async)."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip){ + return zip.files["€15.txt"].async("string"); + }) + .then(function (content) { + assert.equal(content, "€15\n", "the utf8 content was correctly read (with files[].async)."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // zip backslash.zip -0 -X Hel\\lo.txt JSZipTestUtils.testZipFile("Zip text file with backslash in filename", "ref/backslash.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip){ - return zip.file("Hel\\lo.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "Hello World\n", "the utf8 content was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip){ + return zip.file("Hel\\lo.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "Hello World\n", "the utf8 content was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // use izarc to generate a zip file on windows JSZipTestUtils.testZipFile("Zip text file from windows with \\ in central dir", "ref/slashes_and_izarc.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip){ - return zip.folder("test").file("Hello.txt").async("string"); - }) - .then(function (content) { - assert.equal(content, "Hello world\r\n", "the content was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip){ + return zip.folder("test").file("Hello.txt").async("string"); + }) + .then(function (content) { + assert.equal(content, "Hello world\r\n", "the content was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // cat Hello.txt all.zip > all_prepended_bytes.zip JSZipTestUtils.testZipFile("zip file with prepended bytes", "ref/all_prepended_bytes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success(zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function success(zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // cat all.zip Hello.txt > all_appended_bytes.zip JSZipTestUtils.testZipFile("zip file with appended bytes", "ref/all_appended_bytes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success(zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function success(zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // cat Hello.txt zip64.zip > zip64_prepended_bytes.zip JSZipTestUtils.testZipFile("zip64 file with extra bytes", "ref/zip64_prepended_bytes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success(zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function success(zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // cat zip64.zip Hello.txt > zip64_appended_bytes.zip JSZipTestUtils.testZipFile("zip64 file with extra bytes", "ref/zip64_appended_bytes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success(zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content) { - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function success(zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content) { + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("load(promise) works", "ref/all.zip", function(assert, fileAsString) { var done = assert.async(); JSZip.loadAsync(JSZip.external.Promise.resolve(fileAsString)) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); if (JSZip.support.blob) { @@ -469,40 +468,40 @@ QUnit.module("load", function () { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }).then(function (content){ - assert.equal(content, "Hello World\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }).then(function (content){ + assert.equal(content, "Hello World\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); } JSZipTestUtils.testZipFile("valid crc32", "ref/all.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {checkCRC32:true}) - .then(function success() { - assert.ok(true, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(false, "An exception were thrown: " + e.message); - done(); - }); + .then(function success() { + assert.ok(true, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(false, "An exception were thrown: " + e.message); + done(); + }); }); JSZipTestUtils.testZipFile("loading in a sub folder", "ref/all.zip", function(assert, file) { var done = assert.async(); var zip = new JSZip(); zip.folder("sub").loadAsync(file) - .then(function success(zip) { - assert.ok(zip.file("Hello.txt"), "the zip was correctly read."); - assert.equal(zip.file("Hello.txt").name, "sub/Hello.txt", "the zip was read in a sub folder"); - assert.equal(zip.root, "sub/", "the promise contains the correct folder level"); - done(); - }, function failure(e) { - assert.ok(false, "An exception were thrown: " + e.message); - done(); - }); + .then(function success(zip) { + assert.ok(zip.file("Hello.txt"), "the zip was correctly read."); + assert.equal(zip.file("Hello.txt").name, "sub/Hello.txt", "the zip was read in a sub folder"); + assert.equal(zip.root, "sub/", "the promise contains the correct folder level"); + done(); + }, function failure(e) { + assert.ok(false, "An exception were thrown: " + e.message); + done(); + }); }); JSZipTestUtils.testZipFile("loading overwrite files", "ref/all.zip", function(assert, file) { @@ -511,21 +510,21 @@ QUnit.module("load", function () { zip.file("Hello.txt", "bonjour à tous"); zip.file("Bye.txt", "au revoir"); zip.loadAsync(file) - .then(function success(zip) { - return JSZip.external.Promise.all([ - zip.file("Hello.txt").async("text"), - zip.file("Bye.txt").async("text") - ]); - }).then(function (result) { - var hello = result[0]; - var bye = result[1]; - assert.equal(hello, "Hello World\n", "conflicting content was overwritten."); - assert.equal(bye, "au revoir", "other content was kept."); - done(); - }, function failure(e) { - assert.ok(false, "An exception were thrown: " + e.message); - done(); - }); + .then(function success(zip) { + return JSZip.external.Promise.all([ + zip.file("Hello.txt").async("text"), + zip.file("Bye.txt").async("text") + ]); + }).then(function (result) { + var hello = result[0]; + var bye = result[1]; + assert.equal(hello, "Hello World\n", "conflicting content was overwritten."); + assert.equal(bye, "au revoir", "other content was kept."); + done(); + }, function failure(e) { + assert.ok(false, "An exception were thrown: " + e.message); + done(); + }); }); QUnit.module("not supported features"); @@ -534,13 +533,13 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("basic encryption", "ref/encrypted.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success() { - assert.ok(false, "Encryption is not supported, but no exception were thrown"); - done(); - }, function failure(e) { - assert.equal(e.message, "Encrypted zip are not supported", "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "Encryption is not supported, but no exception were thrown"); + done(); + }, function failure(e) { + assert.equal(e.message, "Encrypted zip are not supported", "the error message is useful"); + done(); + }); }); QUnit.module("corrupted zip"); @@ -548,148 +547,148 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("bad compression method", "ref/invalid/compression.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success() { - assert.ok(false, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); + done(); + }); }); // dd if=all.zip of=all_missing_bytes.zip bs=32 skip=1 JSZipTestUtils.testZipFile("zip file with missing bytes", "ref/all_missing_bytes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success() { - assert.ok(false, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); + done(); + }); }); // dd if=zip64.zip of=zip64_missing_bytes.zip bs=32 skip=1 JSZipTestUtils.testZipFile("zip64 file with missing bytes", "ref/zip64_missing_bytes.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success() { - assert.ok(false, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); + done(); + }); }); JSZipTestUtils.testZipFile("zip file with extra field is Non-standard", "ref/extra_filed_non_standard.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function success() { - assert.ok(true, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(false, "An exception were thrown: " + e.message); - done(); - }); + .then(function success() { + assert.ok(true, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(false, "An exception were thrown: " + e.message); + done(); + }); }); QUnit.test("not a zip file", function(assert) { var done = assert.async(); JSZip.loadAsync("this is not a zip file") - .then(function success() { - assert.ok(false, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(e.message.match("stuk.github.io/jszip/documentation"), "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(e.message.match("stuk.github.io/jszip/documentation"), "the error message is useful"); + done(); + }); }); QUnit.test("truncated zip file", function(assert) { var done = assert.async(); JSZip.loadAsync("PK\x03\x04\x0A\x00\x00\x00") - .then(function success() { - done(); - assert.ok(false, "no exception were thrown"); - }, function failure(e) { - assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); - done(); - }); + .then(function success() { + done(); + assert.ok(false, "no exception were thrown"); + }, function failure(e) { + assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); + done(); + }); }); JSZipTestUtils.testZipFile("invalid crc32 but no check", "ref/invalid/crc32.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {checkCRC32:false}) - .then(function success() { - assert.ok(true, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(false, "An exception were thrown but the check should have been disabled."); - done(); - }); + .then(function success() { + assert.ok(true, "no exception were thrown"); + done(); + }, function failure() { + assert.ok(false, "An exception were thrown but the check should have been disabled."); + done(); + }); }); JSZipTestUtils.testZipFile("invalid crc32", "ref/invalid/crc32.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {checkCRC32:true}) - .then(function success() { - assert.ok(false, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); + done(); + }); }); JSZipTestUtils.testZipFile("bad offset", "ref/invalid/bad_offset.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {checkCRC32:false}) - .then(function success() { - assert.ok(false, "no exception were thrown"); - done(); - }, function failure(e) { - assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); - done(); - }); + .then(function success() { + assert.ok(false, "no exception were thrown"); + done(); + }, function failure(e) { + assert.ok(e.message.match("Corrupted zip"), "the error message is useful"); + done(); + }); }); JSZipTestUtils.testZipFile("bad decompressed size, read a file", "ref/invalid/bad_decompressed_size.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { - return zip.file("Hello.txt").async("string"); - }) - .then(function success() { - assert.ok(false, "successful result in an error test"); - done(); - }, function failure(e) { - assert.ok(e.message.match("size mismatch"), "async call : the error message is useful"); - done(); - }); + .then(function (zip) { + return zip.file("Hello.txt").async("string"); + }) + .then(function success() { + assert.ok(false, "successful result in an error test"); + done(); + }, function failure(e) { + assert.ok(e.message.match("size mismatch"), "async call : the error message is useful"); + done(); + }); }); JSZipTestUtils.testZipFile("bad decompressed size, generate a zip", "ref/invalid/bad_decompressed_size.zip", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file) - .then(function (zip) { + .then(function (zip) { - // add other files to be sure to trigger the right code path - zip.file("zz", "zz"); + // add other files to be sure to trigger the right code path + zip.file("zz", "zz"); - return zip.generateAsync({ - type:"string", - compression:"DEFLATE" // a different compression to force a read + return zip.generateAsync({ + type:"string", + compression:"DEFLATE" // a different compression to force a read + }); + }) + .then(function success() { + assert.ok(false, "successful result in an error test"); + done(); + }, function failure(e) { + assert.ok(e.message.match("size mismatch"), "async call : the error message is useful"); + done(); }); - }) - .then(function success() { - assert.ok(false, "successful result in an error test"); - done(); - }, function failure(e) { - assert.ok(e.message.match("size mismatch"), "async call : the error message is useful"); - done(); - }); }); QUnit.module("complex files"); @@ -700,24 +699,24 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("Franz Kafka - The Metamorphosis.epub", "ref/complex_files/Franz Kafka - The Metamorphosis.epub", function(assert, file) { var done = assert.async(2); JSZip.loadAsync(file) - .then(function(zip) { - assert.equal(zip.filter(function(){return true;}).length, 26, "the zip contains the good number of elements."); - return zip.file("mimetype").async("string"); - }) - .then(function (content) { - assert.equal(content, "application/epub+zip\r\n", "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function(zip) { + assert.equal(zip.filter(function(){return true;}).length, 26, "the zip contains the good number of elements."); + return zip.file("mimetype").async("string"); + }) + .then(function (content) { + assert.equal(content, "application/epub+zip\r\n", "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(file) - .then(function(zip) { - return zip.file("OPS/main0.xml").async("string"); - }) - .then(function (content) { + .then(function(zip) { + return zip.file("OPS/main0.xml").async("string"); + }) + .then(function (content) { // the .ncx file tells us that the first chapter is in the main0.xml file. - assert.ok(content.indexOf("One morning, as Gregor Samsa was waking up from anxious dreams") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.ok(content.indexOf("One morning, as Gregor Samsa was waking up from anxious dreams") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // a showcase in http://msdn.microsoft.com/en-us/windows/hardware/gg463429 @@ -725,30 +724,30 @@ QUnit.module("load", function () { var done = assert.async(); JSZip.loadAsync(file, {createFolders: false}) - .then(function(zip) { + .then(function(zip) { // the zip file contains 15 entries. - assert.equal(zip.filter(function(){return true;}).length, 15, "the zip contains the good number of elements."); - return zip.file("[Content_Types].xml").async("string"); - }) - .then(function (content) { - assert.ok(content.indexOf("application/vnd.ms-package.xps-fixeddocument+xml") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.equal(zip.filter(function(){return true;}).length, 15, "the zip contains the good number of elements."); + return zip.file("[Content_Types].xml").async("string"); + }) + .then(function (content) { + assert.ok(content.indexOf("application/vnd.ms-package.xps-fixeddocument+xml") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // Same test as above, but with createFolders option set to true JSZipTestUtils.testZipFile("Outlook2007_Calendar.xps, createFolders: true", "ref/complex_files/Outlook2007_Calendar.xps", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {createFolders: true}) - .then(function(zip) { + .then(function(zip) { // the zip file contains 15 entries, but we get 23 when creating all the sub-folders. - assert.equal(zip.filter(function(){return true;}).length, 23, "the zip contains the good number of elements."); - return zip.file("[Content_Types].xml").async("string"); - }) - .then(function (content) { - assert.ok(content.indexOf("application/vnd.ms-package.xps-fixeddocument+xml") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.equal(zip.filter(function(){return true;}).length, 23, "the zip contains the good number of elements."); + return zip.file("[Content_Types].xml").async("string"); + }) + .then(function (content) { + assert.ok(content.indexOf("application/vnd.ms-package.xps-fixeddocument+xml") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // an example file in http://cheeso.members.winisp.net/srcview.aspx?dir=js-unzip @@ -756,58 +755,58 @@ QUnit.module("load", function () { JSZipTestUtils.testZipFile("AntarcticaTemps.xlsx, createFolders: false", "ref/complex_files/AntarcticaTemps.xlsx", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {createFolders: false}) - .then(function(zip) { + .then(function(zip) { // the zip file contains 17 entries. - assert.equal(zip.filter(function(){return true;}).length, 17, "the zip contains the good number of elements."); - return zip.file("[Content_Types].xml").async("string"); - }).then(function (content) { - assert.ok(content.indexOf("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.equal(zip.filter(function(){return true;}).length, 17, "the zip contains the good number of elements."); + return zip.file("[Content_Types].xml").async("string"); + }).then(function (content) { + assert.ok(content.indexOf("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // Same test as above, but with createFolders option set to true JSZipTestUtils.testZipFile("AntarcticaTemps.xlsx, createFolders: true", "ref/complex_files/AntarcticaTemps.xlsx", function(assert, file) { var done = assert.async(); JSZip.loadAsync(file, {createFolders: true}) - .then(function(zip) { + .then(function(zip) { // the zip file contains 16 entries, but we get 27 when creating all the sub-folders. - assert.equal(zip.filter(function(){return true;}).length, 27, "the zip contains the good number of elements."); - return zip.file("[Content_Types].xml").async("string"); - }).then(function (content) { - assert.ok(content.indexOf("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.equal(zip.filter(function(){return true;}).length, 27, "the zip contains the good number of elements."); + return zip.file("[Content_Types].xml").async("string"); + }).then(function (content) { + assert.ok(content.indexOf("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // same as two up, but in the Open Document format JSZipTestUtils.testZipFile("AntarcticaTemps.ods, createFolders: false", "ref/complex_files/AntarcticaTemps.ods", function (assert, file) { var done = assert.async(); JSZip.loadAsync(file, {createFolders: false}) - .then(function(zip) { + .then(function(zip) { // the zip file contains 20 entries. - assert.equal(zip.filter(function () {return true;}).length, 20, "the zip contains the good number of elements."); - return zip.file("META-INF/manifest.xml").async("string"); - }) - .then(function (content) { - assert.ok(content.indexOf("application/vnd.oasis.opendocument.spreadsheet") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.equal(zip.filter(function () {return true;}).length, 20, "the zip contains the good number of elements."); + return zip.file("META-INF/manifest.xml").async("string"); + }) + .then(function (content) { + assert.ok(content.indexOf("application/vnd.oasis.opendocument.spreadsheet") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // same as above, but in the Open Document format JSZipTestUtils.testZipFile("AntarcticaTemps.ods, createFolders: true", "ref/complex_files/AntarcticaTemps.ods", function (assert, file) { var done = assert.async(); JSZip.loadAsync(file, {createFolders: true}) - .then(function(zip) { + .then(function(zip) { // the zip file contains 19 entries, but we get 27 when creating all the sub-folders. - assert.equal(zip.filter(function () {return true;}).length, 27, "the zip contains the good number of elements."); - return zip.file("META-INF/manifest.xml").async("string"); - }) - .then(function (content) { - assert.ok(content.indexOf("application/vnd.oasis.opendocument.spreadsheet") !== -1, "the zip was correctly read."); - done(); - })['catch'](JSZipTestUtils.assertNoError); + assert.equal(zip.filter(function () {return true;}).length, 27, "the zip contains the good number of elements."); + return zip.file("META-INF/manifest.xml").async("string"); + }) + .then(function (content) { + assert.ok(content.indexOf("application/vnd.oasis.opendocument.spreadsheet") !== -1, "the zip was correctly read."); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); } }); diff --git a/test/asserts/permissions.js b/test/asserts/permissions.js index d959e614..9afa1cea 100644 --- a/test/asserts/permissions.js +++ b/test/asserts/permissions.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("permissions", function () { @@ -23,16 +22,16 @@ QUnit.module("permissions", function () { var done = assert.async(); JSZip.loadAsync(file, {createFolders:false}) - .then(function(zip) { - doAsserts(zip, "dir_777/", true, "40777"); - doAsserts(zip, "dir_755/", true, "40755"); - doAsserts(zip, "dir_500/", true, "40500"); - doAsserts(zip, "file_666", false, "100666"); - doAsserts(zip, "file_640", false, "100640"); - doAsserts(zip, "file_400", false, "100400"); - doAsserts(zip, "file_755", false, "100755"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function(zip) { + doAsserts(zip, "dir_777/", true, "40777"); + doAsserts(zip, "dir_755/", true, "40755"); + doAsserts(zip, "dir_500/", true, "40500"); + doAsserts(zip, "file_666", false, "100666"); + doAsserts(zip, "file_640", false, "100640"); + doAsserts(zip, "file_400", false, "100400"); + doAsserts(zip, "file_755", false, "100755"); + done(); + })["catch"](JSZipTestUtils.assertNoError); } function assertDosPermissions(assert, file){ @@ -45,42 +44,42 @@ QUnit.module("permissions", function () { var done = assert.async(); JSZip.loadAsync(file, {createFolders:false}) - .then(function(zip) { - if (zip.files["dir/"]) { - doAsserts(zip, "dir/", true, "010000"); - } - if (zip.files["dir_hidden/"]) { - doAsserts(zip, "dir_hidden/", true, "010010"); - } - doAsserts(zip, "file", false, "100000"); - doAsserts(zip, "file_ro", false, "100001"); - doAsserts(zip, "file_hidden", false, "100010"); - doAsserts(zip, "file_ro_hidden", false, "100011"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function(zip) { + if (zip.files["dir/"]) { + doAsserts(zip, "dir/", true, "010000"); + } + if (zip.files["dir_hidden/"]) { + doAsserts(zip, "dir_hidden/", true, "010010"); + } + doAsserts(zip, "file", false, "100000"); + doAsserts(zip, "file_ro", false, "100001"); + doAsserts(zip, "file_hidden", false, "100010"); + doAsserts(zip, "file_ro_hidden", false, "100011"); + done(); + })["catch"](JSZipTestUtils.assertNoError); } function reloadAndAssertUnixPermissions(assert, file){ var done = assert.async(); JSZip.loadAsync(file, {createFolders:false}) - .then(function (zip) { - return zip.generateAsync({type:"string", platform:"UNIX"}); - }) - .then(function (content) { - assertUnixPermissions(assert, content); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.generateAsync({type:"string", platform:"UNIX"}); + }) + .then(function (content) { + assertUnixPermissions(assert, content); + done(); + })["catch"](JSZipTestUtils.assertNoError); } function reloadAndAssertDosPermissions(assert, file){ var done = assert.async(); JSZip.loadAsync(file, {createFolders:false}) - .then(function (zip) { - return zip.generateAsync({type:"string", platform:"DOS"}); - }) - .then(function (content) { - assertDosPermissions(assert, content); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + return zip.generateAsync({type:"string", platform:"DOS"}); + }) + .then(function (content) { + assertDosPermissions(assert, content); + done(); + })["catch"](JSZipTestUtils.assertNoError); } JSZipTestUtils.testZipFile("permissions on linux : file created by zip", "ref/permissions/linux_zip.zip", assertUnixPermissions); JSZipTestUtils.testZipFile("permissions on linux : file created by zip, reloaded", "ref/permissions/linux_zip.zip", reloadAndAssertUnixPermissions); diff --git a/test/asserts/stream.js b/test/asserts/stream.js index 2e9a8d7e..1880ae83 100644 --- a/test/asserts/stream.js +++ b/test/asserts/stream.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("stream", function () { @@ -19,54 +18,64 @@ QUnit.module("stream", function () { var helper = zip.generateInternalStream({streamFiles:true, type:"binarystring"}); helper - .on("data", function () { - chunkCount++; - assert.equal(allowChunks, true, "be sure to get chunks only when allowed"); + .on("data", function () { + chunkCount++; + assert.equal(allowChunks, true, "be sure to get chunks only when allowed"); - /* + /* * We stop at ~ half of chunks. * A setTimeout aside this stream is not reliable and can be * triggered *after* the completion of the stream. */ - if (chunkCount === 20) { - - allowChunks = false; - helper.pause(); - setTimeout(function () { - allowChunks = true; - helper.resume(); - }, 50); - } - }) - .on("error", function (e) { - done(); - assert.ok(false, e.message); - }) - .on("end", function () { - done(); - }); + if (chunkCount === 20) { + + allowChunks = false; + helper.pause(); + setTimeout(function () { + allowChunks = true; + helper.resume(); + }, 50); + } + }) + .on("error", function (e) { + done(); + assert.ok(false, e.message); + }) + .on("end", function () { + done(); + }); helper.resume(); }); QUnit.module("nodejs"); if (JSZip.support.nodestream) { - var fs = require('fs'); + var fs = require("fs"); } - function generateStreamTest(name, ref, createFunction, generateOptions, updateStream) { + function generateStreamTest(name, ref, createFunction, generateOptions) { JSZipTestUtils.testZipFile(name,ref, function(assert, expected) { var done = assert.async(); - var tempFile = require('tmp').tmpNameSync({postfix:".zip"}); + var tempFile = require("tmp").tmpNameSync({postfix:".zip"}); var zip = createFunction(); zip.generateNodeStream(generateOptions) - .pipe(fs.createWriteStream(tempFile)) - .on("close", function () { - fs.readFile(tempFile, function (e, data) { - var actual = JSZipTestUtils.toString(data); - assert.ok(JSZipTestUtils.similar(actual, expected, 3 * JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "generated ZIP matches reference ZIP"); + .pipe(fs.createWriteStream(tempFile)) + .on("close", function () { + fs.readFile(tempFile, function (e, data) { + var actual = JSZipTestUtils.toString(data); + assert.ok(JSZipTestUtils.similar(actual, expected, 3 * JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "generated ZIP matches reference ZIP"); + fs.unlink(tempFile, function (err) { + if (err) { + assert.ok(false, err); + } + done(); + }); + }); + }) + .on("error", function (e) { + assert.ok(false, e.message); fs.unlink(tempFile, function (err) { if (err) { assert.ok(false, err); @@ -74,27 +83,27 @@ QUnit.module("stream", function () { done(); }); }); - }) - .on("error", function (e) { - assert.ok(false, e.message); - fs.unlink(tempFile, function (err) { - if (err) { - assert.ok(false, err); - } - done(); - }); - }); }); } function zipObjectStreamTest(name, createFunction) { QUnit.test(name, function(assert) { - var tempFile = require('tmp').tmpNameSync({postfix:".txt"}); + var tempFile = require("tmp").tmpNameSync({postfix:".txt"}); var done = assert.async(); createFunction().pipe(fs.createWriteStream(tempFile)) - .on("close", function () { - fs.readFile(tempFile, function (e, data) { - var actual = JSZipTestUtils.toString(data); - assert.equal(actual, "Hello World\n", "the generated content is ok"); + .on("close", function () { + fs.readFile(tempFile, function (e, data) { + var actual = JSZipTestUtils.toString(data); + assert.equal(actual, "Hello World\n", "the generated content is ok"); + fs.unlink(tempFile, function (err) { + if (err) { + assert.ok(false, err); + } + done(); + }); + }); + }) + .on("error", function (e) { + assert.ok(false, e.message); fs.unlink(tempFile, function (err) { if (err) { assert.ok(false, err); @@ -102,16 +111,6 @@ QUnit.module("stream", function () { done(); }); }); - }) - .on("error", function (e) { - assert.ok(false, e.message); - fs.unlink(tempFile, function (err) { - if (err) { - assert.ok(false, err); - } - done(); - }); - }); }); } @@ -120,7 +119,7 @@ QUnit.module("stream", function () { generateStreamTest( "generateNodeStream(type:nodebuffer / !streamFiles) generates a working stream", "ref/all.zip", JSZipTestUtils.createZipAll, - {type:'nodebuffer',streamFiles:false} + {type:"nodebuffer",streamFiles:false} ); generateStreamTest( "generateNodeStream(type: / !streamFiles) generates a working stream", "ref/all.zip", @@ -134,7 +133,7 @@ QUnit.module("stream", function () { generateStreamTest( "generateNodeStream(type:nodebuffer / streamFiles) generates a working stream", "ref/all-stream.zip", JSZipTestUtils.createZipAll, - {type:'nodebuffer',streamFiles:true} + {type:"nodebuffer",streamFiles:true} ); generateStreamTest( "generateNodeStream(type: / streamFiles) generates a working stream", "ref/all-stream.zip", @@ -153,7 +152,7 @@ QUnit.module("stream", function () { return zip; }, - {type:'nodebuffer',streamFiles:false} + {type:"nodebuffer",streamFiles:false} ); generateStreamTest( "generateNodeStream(type:nodebuffer / streamFiles) generates a working stream from other streams", "ref/all-stream.zip", @@ -166,13 +165,13 @@ QUnit.module("stream", function () { return zip; }, - {type:'nodebuffer',streamFiles:true} + {type:"nodebuffer",streamFiles:true} ); zipObjectStreamTest("ZipObject#nodeStream generates a working stream[nodebuffer]", function() { var zip = JSZipTestUtils.createZipAll(); - return zip.file("Hello.txt").nodeStream('nodebuffer'); + return zip.file("Hello.txt").nodeStream("nodebuffer"); }); zipObjectStreamTest("ZipObject#nodeStream generates a working stream[default]", function() { var zip = JSZipTestUtils.createZipAll(); @@ -187,7 +186,7 @@ QUnit.module("stream", function () { zip.file("Hello.txt").async("text").then(function(actual) { assert.equal(actual, "Hello World\n", "the stream has been read correctly"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("a ZipObject containing a stream can't be read with async 2 times", function(assert) { @@ -201,13 +200,13 @@ QUnit.module("stream", function () { zip.file("Hello.txt").async("text"); // second time, it shouldn't work zip.file("Hello.txt").async("text") - .then(function (data) { - assert.ok(false, "calling 2 times a stream should generate an error"); - done(); - }, function ko(e) { - assert.ok(e.message.match("has already been used"), "the error message is useful"); - done(); - }); + .then(function () { + assert.ok(false, "calling 2 times a stream should generate an error"); + done(); + }, function ko(e) { + assert.ok(e.message.match("has already been used"), "the error message is useful"); + done(); + }); }); QUnit.test("a ZipObject containing a stream can't be read with nodeStream 2 times", function(assert) { @@ -221,15 +220,15 @@ QUnit.module("stream", function () { zip.file("Hello.txt").nodeStream().resume(); // second time, it shouldn't work zip.file("Hello.txt").nodeStream() - .on("error", function (e) { - assert.ok(e.message.match("has already been used"), "the error message is useful"); - done(); - }) - .on ("end", function () { - assert.ok(false, "calling 2 times a stream should generate an error"); - done(); - }) - .resume(); + .on("error", function (e) { + assert.ok(e.message.match("has already been used"), "the error message is useful"); + done(); + }) + .on ("end", function () { + assert.ok(false, "calling 2 times a stream should generate an error"); + done(); + }) + .resume(); }); QUnit.test("generateAsync with a stream can't be read 2 times", function(assert) { @@ -243,13 +242,13 @@ QUnit.module("stream", function () { zip.generateAsync({type:"string"}); // second time, it shouldn't work zip.generateAsync({type:"string"}) - .then(function (data) { - assert.ok(false, "calling 2 times a stream should generate an error"); - done(); - }, function ko(e) { - assert.ok(e.message.match("has already been used"), "the error message is useful"); - done(); - }); + .then(function () { + assert.ok(false, "calling 2 times a stream should generate an error"); + done(); + }, function ko(e) { + assert.ok(e.message.match("has already been used"), "the error message is useful"); + done(); + }); }); QUnit.test("generateNodeStream with a stream can't be read 2 times", function(assert) { @@ -263,15 +262,15 @@ QUnit.module("stream", function () { zip.generateNodeStream().resume(); // second time, it shouldn't work zip.generateNodeStream() - .on("error", function (e) { - assert.ok(e.message.match("has already been used"), "the error message is useful"); - done(); - }) - .on ("end", function () { - assert.ok(false, "calling 2 times a stream should generate an error"); - done(); - }) - .resume(); + .on("error", function (e) { + assert.ok(e.message.match("has already been used"), "the error message is useful"); + done(); + }) + .on ("end", function () { + assert.ok(false, "calling 2 times a stream should generate an error"); + done(); + }) + .resume(); }); QUnit.test("loadAsync ends with an error when called with a stream", function(assert) { @@ -291,7 +290,7 @@ QUnit.module("stream", function () { QUnit.test("generateNodeStream generates an error", function(assert) { try { var zip = new JSZip(); - zip.generateNodeStream({type:'nodebuffer',streamFiles:true}); + zip.generateNodeStream({type:"nodebuffer",streamFiles:true}); assert.ok(false, "generateNodeStream should generate an error"); } catch(err) { assert.ok(err.message.match("not supported by this platform"), "the error message is useful"); @@ -301,7 +300,7 @@ QUnit.module("stream", function () { QUnit.test("ZipObject#nodeStream generates an error", function(assert) { try { var zip = JSZipTestUtils.createZipAll(); - zip.file("Hello.txt").nodeStream('nodebuffer'); + zip.file("Hello.txt").nodeStream("nodebuffer"); assert.ok(false, "nodeStream should generate an error"); } catch(err) { assert.ok(err.message.match("not supported by this platform"), "the error message is useful"); diff --git a/test/asserts/unicode.js b/test/asserts/unicode.js index 4bb7eac1..c4dfd60a 100644 --- a/test/asserts/unicode.js +++ b/test/asserts/unicode.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("unicode"); @@ -12,7 +11,7 @@ JSZipTestUtils.testZipFile("Zip text file with UTF-8 characters", "ref/utf8.zip" assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); QUnit.test("Text file with long unicode string", function(assert) { @@ -24,18 +23,18 @@ QUnit.test("Text file with long unicode string", function(assert) { zip.file("amount.txt", expected); var done = assert.async(); zip.generateAsync({type:"binarystring"}) - .then(JSZip.loadAsync) - .then(function (zip) { - var file = zip.file("amount.txt"); - return file.async("string"); - }).then(function (fileContent){ - assert.equal(fileContent, expected, "Generated ZIP can be parsed"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(JSZip.loadAsync) + .then(function (zip) { + var file = zip.file("amount.txt"); + return file.async("string"); + }).then(function (fileContent){ + assert.equal(fileContent, expected, "Generated ZIP can be parsed"); + done(); + })["catch"](JSZipTestUtils.assertNoError); }); // zip -X -0 utf8_in_name.zip €15.txt -JSZipTestUtils.testZipFile("Zip text file with UTF-8 characters in filename", "ref/utf8_in_name.zip", function(assert, expected) { +JSZipTestUtils.testZipFile("Zip text file with UTF-8 characters in filename", "ref/utf8_in_name.zip", function(assert) { var zip = new JSZip(); zip.file("€15.txt", "€15\n"); var done = assert.async(); @@ -47,7 +46,7 @@ JSZipTestUtils.testZipFile("Zip text file with UTF-8 characters in filename", "r // assert.ok(JSZipTestUtils.similar(actual, expected, JSZipTestUtils.MAX_BYTES_DIFFERENCE_PER_ZIP_ENTRY) , "Generated ZIP matches reference ZIP"); JSZipTestUtils.checkGenerateStability(assert, actual); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Zip text file with non unicode characters in filename: loadAsync without decodeFileName", "ref/local_encoding_in_name.zip", function(assert, content) { @@ -57,7 +56,7 @@ JSZipTestUtils.testZipFile("Zip text file with non unicode characters in filenam assert.ok(!zipUnicode.files["Новая папка/"], "default : the folder is not found"); assert.ok(!zipUnicode.files["Новая папка/Новый текстовый документ.txt"], "default : the file is not found"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); @@ -82,7 +81,7 @@ JSZipTestUtils.testZipFile("Zip text file with non unicode characters in filenam assert.ok(zipCP866.files["Новая папка/"], "with decodeFileName : the folder has been correctly read"); assert.ok(zipCP866.files["Новая папка/Новый текстовый документ.txt"], "with decodeFileName : the file has been correctly read"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); JSZipTestUtils.testZipFile("Zip text file with non unicode characters in filename: generateAsync with encodeassert, fileName", "ref/local_encoding_in_name.zip", function(assert, content) { @@ -122,7 +121,7 @@ JSZipTestUtils.testZipFile("Zip text file with non unicode characters in filenam assert.ok(zipCP866.files["Новая папка/"], "with decodeFileName : the folder has been correctly read"); assert.ok(zipCP866.files["Новая папка/Новый текстовый документ.txt"], "with decodeFileName : the file has been correctly read"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); // zip --entry-comments --archive-comment -X -0 pile_of_poo.zip Iñtërnâtiônàlizætiøn☃$'\360\237\222\251'.txt @@ -132,7 +131,7 @@ JSZipTestUtils.testZipFile("Zip text file and UTF-8, Pile Of Poo test", "ref/pil // see http://mathiasbynens.be/notes/javascript-unicode // but escaped, to avoid troubles // thanks http://mothereff.in/js-escapes#1I%C3%B1t%C3%ABrn%C3%A2ti%C3%B4n%C3%A0liz%C3%A6ti%C3%B8n%E2%98%83%F0%9F%92%A9 - var text = 'I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\u2603\uD83D\uDCA9'; + var text = "I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\u2603\uD83D\uDCA9"; zip.file(text + ".txt", text, {comment : text}); var done = assert.async(3); zip.generateAsync({type:"binarystring", comment : text}).then(function(actual) { @@ -140,31 +139,30 @@ JSZipTestUtils.testZipFile("Zip text file and UTF-8, Pile Of Poo test", "ref/pil JSZipTestUtils.checkGenerateStability(assert, actual); JSZip.loadAsync(expected) - .then(function (zip) { - var file = zip.file(text + ".txt"); - assert.ok(file, "JSZip finds the unicode file name on the external file"); - assert.equal(file.comment, text, "JSZip can decode the external file comment"); - return file.async("string"); - }) - .then(function (content) { - assert.equal(content, text, "JSZip can decode the external file"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + var file = zip.file(text + ".txt"); + assert.ok(file, "JSZip finds the unicode file name on the external file"); + assert.equal(file.comment, text, "JSZip can decode the external file comment"); + return file.async("string"); + }) + .then(function (content) { + assert.equal(content, text, "JSZip can decode the external file"); + done(); + })["catch"](JSZipTestUtils.assertNoError); JSZip.loadAsync(actual) - .then(function (zip) { - var file = zip.file(text + ".txt"); - assert.ok(file, "JSZip finds the unicode file name on its own file"); - assert.equal(file.comment, text, "JSZip can decode its own file comment"); - return file.async("string"); - }) - .then(function (content) { - assert.equal(content, text, "JSZip can decode its own file"); - done(); - })['catch'](JSZipTestUtils.assertNoError); + .then(function (zip) { + var file = zip.file(text + ".txt"); + assert.ok(file, "JSZip finds the unicode file name on its own file"); + assert.equal(file.comment, text, "JSZip can decode its own file comment"); + return file.async("string"); + }) + .then(function (content) { + assert.equal(content, text, "JSZip can decode its own file"); + done(); + })["catch"](JSZipTestUtils.assertNoError); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }); - diff --git a/test/asserts/utils.js b/test/asserts/utils.js index b9438e1d..6d8c5355 100644 --- a/test/asserts/utils.js +++ b/test/asserts/utils.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; // These tests only run in Node var utils = require("../../lib/utils"); diff --git a/test/asserts/version.js b/test/asserts/version.js index ee050f65..ee1efdde 100644 --- a/test/asserts/version.js +++ b/test/asserts/version.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; QUnit.module("version"); diff --git a/test/helpers/browser-test-utils.js b/test/helpers/browser-test-utils.js index f1d5db3a..add57eb8 100644 --- a/test/helpers/browser-test-utils.js +++ b/test/helpers/browser-test-utils.js @@ -1,5 +1,4 @@ -/* global JSZip,JSZipUtils,JSZipTestUtils */ -'use strict'; +"use strict"; JSZipTestUtils.loadZipFile = function (name, callback) { JSZipUtils.getBinaryContent(name + "?_=" + ( new Date() ).getTime(), callback); }; diff --git a/test/helpers/node-test-utils.js b/test/helpers/node-test-utils.js index b415b7a7..9dc22eea 100644 --- a/test/helpers/node-test-utils.js +++ b/test/helpers/node-test-utils.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; var fs = require("fs"); var path = require("path"); @@ -9,12 +8,12 @@ global.JSZip = require("../../lib/index"); global.JSZipTestUtils.loadZipFile = function(name, callback) { fs.readFile(path.join("test", name), "binary", callback); }; -process.on('uncaughtException', function(err) { - console.log('uncaughtException: ' + err, err.stack); - process.exit(1); +process.on("uncaughtException", function(err) { + console.log("uncaughtException: " + err, err.stack); + process.exit(1); }); -process.on('unhandledRejection', function(err) { - console.log('unhandledRejection: ' + err, err.stack); - process.exit(1); +process.on("unhandledRejection", function(err) { + console.log("unhandledRejection: " + err, err.stack); + process.exit(1); }); diff --git a/test/helpers/test-utils.js b/test/helpers/test-utils.js index 77543948..ef7528d2 100644 --- a/test/helpers/test-utils.js +++ b/test/helpers/test-utils.js @@ -1,5 +1,4 @@ -/* global QUnit,JSZip,JSZipTestUtils */ -'use strict'; +"use strict"; (function (global) { // Expose assert object globally @@ -64,7 +63,7 @@ }).then(function (content) { assert.ok(JSZipTestUtils.similar(bytesStream, content, 0), "generate stability : stable"); done(); - })['catch'](JSZipTestUtils.assertNoError); + })["catch"](JSZipTestUtils.assertNoError); }; JSZipTestUtils.checkBasicStreamBehavior = function checkBasicStreamBehavior(assert, stream, testName) { @@ -74,26 +73,26 @@ } var triggeredStream = false; stream - .on("data", function (data, metadata) { + .on("data", function (data, metadata) { // triggering a lot of passing checks makes the result unreadable - if (!data) { - assert.ok(data, testName + "basic check stream, data event handler, data is defined"); - } - if(!metadata) { - assert.ok(metadata, testName + "basic check stream, data event handler, metadata is defined"); - } - triggeredStream = true; - }) - .on("error", function (e) { - assert.ok(e, testName + "basic check stream, error event handler, error is defined"); - triggeredStream = true; - done(); - }) - .on("end", function () { - triggeredStream = true; - done(); - }) - .resume() + if (!data) { + assert.ok(data, testName + "basic check stream, data event handler, data is defined"); + } + if(!metadata) { + assert.ok(metadata, testName + "basic check stream, data event handler, metadata is defined"); + } + triggeredStream = true; + }) + .on("error", function (e) { + assert.ok(e, testName + "basic check stream, error event handler, error is defined"); + triggeredStream = true; + done(); + }) + .on("end", function () { + triggeredStream = true; + done(); + }) + .resume() ; assert.ok(!triggeredStream, testName + "basic check stream, the stream callback is async"); }; @@ -189,7 +188,7 @@ var base64Dict = { "": "", - "\xE2\x82\xAC15\n": "4oKsMTUK", + "\xE2\x82\xAC15\n": "4oKsMTUK", "test\r\ntest\r\n": "dGVzdA0KdGVzdA0K", "all.zip.base64,stream=false": "UEsDBAoAAAAAAO+7TTrj5ZWwDAAAAAwAAAAJAAAASGVsbG8udHh0SGVsbG8gV29ybGQKUEsDBAoAAAAAAA9qUToAAAAAAAAAAAAAAAAHAAAAaW1hZ2VzL1BLAwQKAAAAAACZoEg6PD/riikAAAApAAAAEAAAAGltYWdlcy9zbWlsZS5naWZHSUY4N2EFAAUAgAIAAAAA/94ALAAAAAAFAAUAAAIIjA+RZ6sKUgEAO1BLAQIUAAoAAAAAAO+7TTrj5ZWwDAAAAAwAAAAJAAAAAAAAAAAAAAAAAAAAAABIZWxsby50eHRQSwECFAAKAAAAAAAPalE6AAAAAAAAAAAAAAAABwAAAAAAAAAAABAAAAAzAAAAaW1hZ2VzL1BLAQIUAAoAAAAAAJmgSDo8P+uKKQAAACkAAAAQAAAAAAAAAAAAAAAAAFgAAABpbWFnZXMvc21pbGUuZ2lmUEsFBgAAAAADAAMAqgAAAK8AAAAAAA==", "all.zip.base64,stream=true": "UEsDBAoACAAAAO+7TToAAAAAAAAAAAAAAAAJAAAASGVsbG8udHh0SGVsbG8gV29ybGQKUEsHCOPllbAMAAAADAAAAFBLAwQKAAAAAAAPalE6AAAAAAAAAAAAAAAABwAAAGltYWdlcy9QSwMECgAIAAAAmaBIOgAAAAAAAAAAAAAAABAAAABpbWFnZXMvc21pbGUuZ2lmR0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADtQSwcIPD/riikAAAApAAAAUEsBAhQACgAIAAAA77tNOuPllbAMAAAADAAAAAkAAAAAAAAAAAAAAAAAAAAAAEhlbGxvLnR4dFBLAQIUAAoAAAAAAA9qUToAAAAAAAAAAAAAAAAHAAAAAAAAAAAAEAAAAEMAAABpbWFnZXMvUEsBAhQACgAIAAAAmaBIOjw/64opAAAAKQAAABAAAAAAAAAAAAAAAAAAaAAAAGltYWdlcy9zbWlsZS5naWZQSwUGAAAAAAMAAwCqAAAAzwAAAAAA" diff --git a/test/run.js b/test/run.js index 9c5c7c8d..fe52d6de 100644 --- a/test/run.js +++ b/test/run.js @@ -1,3 +1,5 @@ +"use strict"; + const path = require("path"); const playwright = require("playwright"); const createServer = require("http-server").createServer; @@ -27,14 +29,14 @@ async function run(browserType) { const context = await browser.newContext(); const page = await context.newPage(); - await page.goto(`http://127.0.0.1:8080/test/index.html?hidepassed`); + await page.goto("http://127.0.0.1:8080/test/index.html?hidepassed"); let result; do { result = await page.evaluate(() => { return window.global_test_results; }); - } while (!result) + } while (!result); console.log("Closing", browserType); await browser.close();