From 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Apr 2017 03:09:25 +0200 Subject: Reorganize module loading. We now use webpack instead of SystemJS, effectively bundling modules into one file (plus commons chunks) for every entry point. This results in a much smaller extension size (almost half). Furthermore we use yarn/npm even for extension run-time dependencies. This relieves us from manually vendoring and building dependencies. It's also easier to understand for new developers familiar with node. --- .../lib/archivers/zip/constants.js | 2 +- .../lib/archivers/zip/zip-archive-entry.js | 186 ++++++++++++++++++++- .../lib/archivers/zip/zip-archive-output-stream.js | 3 +- 3 files changed, 185 insertions(+), 6 deletions(-) (limited to 'node_modules/compress-commons/lib') diff --git a/node_modules/compress-commons/lib/archivers/zip/constants.js b/node_modules/compress-commons/lib/archivers/zip/constants.js index d17b16e7b..34181ecf8 100644 --- a/node_modules/compress-commons/lib/archivers/zip/constants.js +++ b/node_modules/compress-commons/lib/archivers/zip/constants.js @@ -68,4 +68,4 @@ module.exports = { S_DOS_S: 4, // 04 System S_DOS_H: 2, // 02 Hidden S_DOS_R: 1 // 01 Read Only -}; \ No newline at end of file +}; diff --git a/node_modules/compress-commons/lib/archivers/zip/zip-archive-entry.js b/node_modules/compress-commons/lib/archivers/zip/zip-archive-entry.js index 03d2b7dcf..e5b0d69a7 100644 --- a/node_modules/compress-commons/lib/archivers/zip/zip-archive-entry.js +++ b/node_modules/compress-commons/lib/archivers/zip/zip-archive-entry.js @@ -10,6 +10,7 @@ var normalizePath = require('normalize-path'); var ArchiveEntry = require('../archive-entry'); var GeneralPurposeBit = require('./general-purpose-bit'); +var UnixStat = require('./unix-stat'); var constants = require('./constants'); var zipUtil = require('./util'); @@ -45,78 +46,173 @@ var ZipArchiveEntry = module.exports = function(name) { inherits(ZipArchiveEntry, ArchiveEntry); +/** + * Returns the extra fields related to the entry. + * + * @returns {Buffer} + */ ZipArchiveEntry.prototype.getCentralDirectoryExtra = function() { return this.getExtra(); }; +/** + * Returns the comment set for the entry. + * + * @returns {string} + */ ZipArchiveEntry.prototype.getComment = function() { return this.comment !== null ? this.comment : ''; }; +/** + * Returns the compressed size of the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getCompressedSize = function() { return this.csize; }; +/** + * Returns the CRC32 digest for the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getCrc = function() { return this.crc; }; +/** + * Returns the external file attributes for the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getExternalAttributes = function() { return this.exattr; }; +/** + * Returns the extra fields related to the entry. + * + * @returns {Buffer} + */ ZipArchiveEntry.prototype.getExtra = function() { return this.extra !== null ? this.extra : constants.EMPTY; }; +/** + * Returns the general purpose bits related to the entry. + * + * @returns {GeneralPurposeBit} + */ ZipArchiveEntry.prototype.getGeneralPurposeBit = function() { return this.gpb; }; +/** + * Returns the internal file attributes for the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getInternalAttributes = function() { return this.inattr; }; +/** + * Returns the last modified date of the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getLastModifiedDate = function() { return this.getTime(); }; +/** + * Returns the extra fields related to the entry. + * + * @returns {Buffer} + */ ZipArchiveEntry.prototype.getLocalFileDataExtra = function() { return this.getExtra(); }; +/** + * Returns the compression method used on the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getMethod = function() { return this.method; }; +/** + * Returns the filename of the entry. + * + * @returns {string} + */ ZipArchiveEntry.prototype.getName = function() { return this.name; }; +/** + * Returns the platform on which the entry was made. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getPlatform = function() { return this.platform; }; +/** + * Returns the size of the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getSize = function() { return this.size; }; +/** + * Returns a date object representing the last modified date of the entry. + * + * @returns {number|Date} + */ ZipArchiveEntry.prototype.getTime = function() { return this.time !== -1 ? zipUtil.dosToDate(this.time) : -1; }; +/** + * Returns the DOS timestamp for the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getTimeDos = function() { return this.time !== -1 ? this.time : 0; }; +/** + * Returns the UNIX file permissions for the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getUnixMode = function() { - return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK) & constants.MODE_MASK; + return this.platform !== constants.PLATFORM_UNIX ? 0 : ((this.getExternalAttributes() >> constants.SHORT_SHIFT) & constants.SHORT_MASK); }; +/** + * Returns the version of ZIP needed to extract the entry. + * + * @returns {number} + */ ZipArchiveEntry.prototype.getVersionNeededToExtract = function() { return this.minver; }; +/** + * Sets the comment of the entry. + * + * @param comment + */ ZipArchiveEntry.prototype.setComment = function(comment) { if (Buffer.byteLength(comment) !== comment.length) { this.getGeneralPurposeBit().useUTF8ForNames(true); @@ -125,6 +221,11 @@ ZipArchiveEntry.prototype.setComment = function(comment) { this.comment = comment; }; +/** + * Sets the compressed size of the entry. + * + * @param size + */ ZipArchiveEntry.prototype.setCompressedSize = function(size) { if (size < 0) { throw new Error('invalid entry compressed size'); @@ -133,6 +234,11 @@ ZipArchiveEntry.prototype.setCompressedSize = function(size) { this.csize = size; }; +/** + * Sets the checksum of the entry. + * + * @param crc + */ ZipArchiveEntry.prototype.setCrc = function(crc) { if (crc < 0) { throw new Error('invalid entry crc32'); @@ -141,14 +247,29 @@ ZipArchiveEntry.prototype.setCrc = function(crc) { this.crc = crc; }; +/** + * Sets the external file attributes of the entry. + * + * @param attr + */ ZipArchiveEntry.prototype.setExternalAttributes = function(attr) { this.exattr = attr >>> 0; }; +/** + * Sets the extra fields related to the entry. + * + * @param extra + */ ZipArchiveEntry.prototype.setExtra = function(extra) { this.extra = extra; }; +/** + * Sets the general purpose bits related to the entry. + * + * @param gpb + */ ZipArchiveEntry.prototype.setGeneralPurposeBit = function(gpb) { if (!(gpb instanceof GeneralPurposeBit)) { throw new Error('invalid entry GeneralPurposeBit'); @@ -157,10 +278,20 @@ ZipArchiveEntry.prototype.setGeneralPurposeBit = function(gpb) { this.gpb = gpb; }; +/** + * Sets the internal file attributes of the entry. + * + * @param attr + */ ZipArchiveEntry.prototype.setInternalAttributes = function(attr) { this.inattr = attr; }; +/** + * Sets the compression method of the entry. + * + * @param method + */ ZipArchiveEntry.prototype.setMethod = function(method) { if (method < 0) { throw new Error('invalid entry compression method'); @@ -169,6 +300,11 @@ ZipArchiveEntry.prototype.setMethod = function(method) { this.method = method; }; +/** + * Sets the name of the entry. + * + * @param name + */ ZipArchiveEntry.prototype.setName = function(name) { name = normalizePath(name, false).replace(/^\w+:/, '').replace(/^(\.\.\/|\/)+/, ''); @@ -179,10 +315,20 @@ ZipArchiveEntry.prototype.setName = function(name) { this.name = name; }; +/** + * Sets the platform on which the entry was made. + * + * @param platform + */ ZipArchiveEntry.prototype.setPlatform = function(platform) { this.platform = platform; }; +/** + * Sets the size of the entry. + * + * @param size + */ ZipArchiveEntry.prototype.setSize = function(size) { if (size < 0) { throw new Error('invalid entry size'); @@ -191,6 +337,12 @@ ZipArchiveEntry.prototype.setSize = function(size) { this.size = size; }; +/** + * Sets the time of the entry. + * + * @param time + * @param forceLocalTime + */ ZipArchiveEntry.prototype.setTime = function(time, forceLocalTime) { if (!(time instanceof Date)) { throw new Error('invalid entry time'); @@ -199,8 +351,12 @@ ZipArchiveEntry.prototype.setTime = function(time, forceLocalTime) { this.time = zipUtil.dateToDos(time, forceLocalTime); }; +/** + * Sets the UNIX file permissions for the entry. + * + * @param mode + */ ZipArchiveEntry.prototype.setUnixMode = function(mode) { - mode &= ~constants.S_IFMT; mode |= this.isDirectory() ? constants.S_IFDIR : constants.S_IFREG; var extattr = 0; @@ -211,18 +367,40 @@ ZipArchiveEntry.prototype.setUnixMode = function(mode) { this.platform = constants.PLATFORM_UNIX; }; +/** + * Sets the version of ZIP needed to extract this entry. + * + * @param minver + */ ZipArchiveEntry.prototype.setVersionNeededToExtract = function(minver) { this.minver = minver; }; +/** + * Returns true if this entry represents a directory. + * + * @returns {boolean} + */ ZipArchiveEntry.prototype.isDirectory = function() { return this.getName().slice(-1) === '/'; }; +/** + * Returns true if this entry represents a unix symlink, + * in which case the entry's content contains the target path + * for the symlink. + * + * @returns {boolean} + */ ZipArchiveEntry.prototype.isUnixSymlink = function() { - return (this.getUnixMode() & constants.S_IFLINK) === constants.S_IFLINK; + return (this.getUnixMode() & UnixStat.FILE_TYPE_FLAG) === UnixStat.LINK_FLAG; }; +/** + * Returns true if this entry is using the ZIP64 extension of ZIP. + * + * @returns {boolean} + */ ZipArchiveEntry.prototype.isZip64 = function() { return this.csize > constants.ZIP64_MAGIC || this.size > constants.ZIP64_MAGIC; -}; \ No newline at end of file +}; diff --git a/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js b/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js index 02cb8b36c..d74c1e770 100644 --- a/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js +++ b/node_modules/compress-commons/lib/archivers/zip/zip-archive-output-stream.js @@ -168,7 +168,8 @@ ZipArchiveOutputStream.prototype._smartStream = function(ae, callback) { var error = null; function handleStuff() { - ae.setCrc(process.digest()); + var digest = process.digest().readUInt32BE(0); + ae.setCrc(digest); ae.setSize(process.size()); ae.setCompressedSize(process.size(true)); this._afterAppend(ae); -- cgit v1.2.3