UNPKG

snyk

Version:

snyk library and cli utility

1,385 lines (1,218 loc) • 226 kB
exports.id = 905; exports.ids = [905]; exports.modules = { /***/ 55285: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const Utils = __webpack_require__(85173); const pth = __webpack_require__(85622); const ZipEntry = __webpack_require__(47396); const ZipFile = __webpack_require__(56333); const get_Bool = (val, def) => (typeof val === "boolean" ? val : def); const get_Str = (val, def) => (typeof val === "string" ? val : def); const defaultOptions = { // option "noSort" : if true it disables files sorting noSort: false, // read entries during load (initial loading may be slower) readEntries: false, // default method is none method: Utils.Constants.NONE, // file system fs: null }; module.exports = function (/**String*/ input, /** object */ options) { let inBuffer = null; // create object based default options, allowing them to be overwritten const opts = Object.assign(Object.create(null), defaultOptions); // test input variable if (input && "object" === typeof input) { // if value is not buffer we accept it to be object with options if (!(input instanceof Uint8Array)) { Object.assign(opts, input); input = opts.input ? opts.input : undefined; if (opts.input) delete opts.input; } // if input is buffer if (Buffer.isBuffer(input)) { inBuffer = input; opts.method = Utils.Constants.BUFFER; input = undefined; } } // assign options Object.assign(opts, options); // instanciate utils filesystem const filetools = new Utils(opts); // if input is file name we retrieve its content if (input && "string" === typeof input) { // load zip file if (filetools.fs.existsSync(input)) { opts.method = Utils.Constants.FILE; opts.filename = input; inBuffer = filetools.fs.readFileSync(input); } else { throw new Error(Utils.Errors.INVALID_FILENAME); } } // create variable const _zip = new ZipFile(inBuffer, opts); const { canonical, sanitize } = Utils; function getEntry(/**Object*/ entry) { if (entry && _zip) { var item; // If entry was given as a file name if (typeof entry === "string") item = _zip.getEntry(entry); // if entry was given as a ZipEntry object if (typeof entry === "object" && typeof entry.entryName !== "undefined" && typeof entry.header !== "undefined") item = _zip.getEntry(entry.entryName); if (item) { return item; } } return null; } function fixPath(zipPath) { const { join, normalize, sep } = pth.posix; // convert windows file separators and normalize return join(".", normalize(sep + zipPath.split("\\").join(sep) + sep)); } return { /** * Extracts the given entry from the archive and returns the content as a Buffer object * @param entry ZipEntry object or String with the full path of the entry * * @return Buffer or Null in case of error */ readFile: function (/**Object*/ entry, /*String, Buffer*/ pass) { var item = getEntry(entry); return (item && item.getData(pass)) || null; }, /** * Asynchronous readFile * @param entry ZipEntry object or String with the full path of the entry * @param callback * * @return Buffer or Null in case of error */ readFileAsync: function (/**Object*/ entry, /**Function*/ callback) { var item = getEntry(entry); if (item) { item.getDataAsync(callback); } else { callback(null, "getEntry failed for:" + entry); } }, /** * Extracts the given entry from the archive and returns the content as plain text in the given encoding * @param entry ZipEntry object or String with the full path of the entry * @param encoding Optional. If no encoding is specified utf8 is used * * @return String */ readAsText: function (/**Object*/ entry, /**String=*/ encoding) { var item = getEntry(entry); if (item) { var data = item.getData(); if (data && data.length) { return data.toString(encoding || "utf8"); } } return ""; }, /** * Asynchronous readAsText * @param entry ZipEntry object or String with the full path of the entry * @param callback * @param encoding Optional. If no encoding is specified utf8 is used * * @return String */ readAsTextAsync: function (/**Object*/ entry, /**Function*/ callback, /**String=*/ encoding) { var item = getEntry(entry); if (item) { item.getDataAsync(function (data, err) { if (err) { callback(data, err); return; } if (data && data.length) { callback(data.toString(encoding || "utf8")); } else { callback(""); } }); } else { callback(""); } }, /** * Remove the entry from the file or the entry and all it's nested directories and files if the given entry is a directory * * @param entry */ deleteFile: function (/**Object*/ entry) { // @TODO: test deleteFile var item = getEntry(entry); if (item) { _zip.deleteEntry(item.entryName); } }, /** * Adds a comment to the zip. The zip must be rewritten after adding the comment. * * @param comment */ addZipComment: function (/**String*/ comment) { // @TODO: test addZipComment _zip.comment = comment; }, /** * Returns the zip comment * * @return String */ getZipComment: function () { return _zip.comment || ""; }, /** * Adds a comment to a specified zipEntry. The zip must be rewritten after adding the comment * The comment cannot exceed 65535 characters in length * * @param entry * @param comment */ addZipEntryComment: function (/**Object*/ entry, /**String*/ comment) { var item = getEntry(entry); if (item) { item.comment = comment; } }, /** * Returns the comment of the specified entry * * @param entry * @return String */ getZipEntryComment: function (/**Object*/ entry) { var item = getEntry(entry); if (item) { return item.comment || ""; } return ""; }, /** * Updates the content of an existing entry inside the archive. The zip must be rewritten after updating the content * * @param entry * @param content */ updateFile: function (/**Object*/ entry, /**Buffer*/ content) { var item = getEntry(entry); if (item) { item.setData(content); } }, /** * Adds a file from the disk to the archive * * @param localPath File to add to zip * @param zipPath Optional path inside the zip * @param zipName Optional name for the file */ addLocalFile: function (/**String*/ localPath, /**String=*/ zipPath, /**String=*/ zipName, /**String*/ comment) { if (filetools.fs.existsSync(localPath)) { // fix ZipPath zipPath = zipPath ? fixPath(zipPath) : ""; // p - local file name var p = localPath.split("\\").join("/").split("/").pop(); // add file name into zippath zipPath += zipName ? zipName : p; // read file attributes const _attr = filetools.fs.statSync(localPath); // add file into zip file this.addFile(zipPath, filetools.fs.readFileSync(localPath), comment, _attr); } else { throw new Error(Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath)); } }, /** * Adds a local directory and all its nested files and directories to the archive * * @param localPath * @param zipPath optional path inside zip * @param filter optional RegExp or Function if files match will * be included. */ addLocalFolder: function (/**String*/ localPath, /**String=*/ zipPath, /**=RegExp|Function*/ filter) { // Prepare filter if (filter instanceof RegExp) { // if filter is RegExp wrap it filter = (function (rx) { return function (filename) { return rx.test(filename); }; })(filter); } else if ("function" !== typeof filter) { // if filter is not function we will replace it filter = function () { return true; }; } // fix ZipPath zipPath = zipPath ? fixPath(zipPath) : ""; // normalize the path first localPath = pth.normalize(localPath); if (filetools.fs.existsSync(localPath)) { const items = filetools.findFiles(localPath); const self = this; if (items.length) { items.forEach(function (filepath) { var p = pth.relative(localPath, filepath).split("\\").join("/"); //windows fix if (filter(p)) { var stats = filetools.fs.statSync(filepath); if (stats.isFile()) { self.addFile(zipPath + p, filetools.fs.readFileSync(filepath), "", stats); } else { self.addFile(zipPath + p + "/", Buffer.alloc(0), "", stats); } } }); } } else { throw new Error(Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath)); } }, /** * Asynchronous addLocalFile * @param localPath * @param callback * @param zipPath optional path inside zip * @param filter optional RegExp or Function if files match will * be included. */ addLocalFolderAsync: function (/*String*/ localPath, /*Function*/ callback, /*String*/ zipPath, /*RegExp|Function*/ filter) { if (filter instanceof RegExp) { filter = (function (rx) { return function (filename) { return rx.test(filename); }; })(filter); } else if ("function" !== typeof filter) { filter = function () { return true; }; } // fix ZipPath zipPath = zipPath ? fixPath(zipPath) : ""; // normalize the path first localPath = pth.normalize(localPath); var self = this; filetools.fs.open(localPath, "r", function (err) { if (err && err.code === "ENOENT") { callback(undefined, Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath)); } else if (err) { callback(undefined, err); } else { var items = filetools.findFiles(localPath); var i = -1; var next = function () { i += 1; if (i < items.length) { var filepath = items[i]; var p = pth.relative(localPath, filepath).split("\\").join("/"); //windows fix p = p .normalize("NFD") .replace(/[\u0300-\u036f]/g, "") .replace(/[^\x20-\x7E]/g, ""); // accent fix if (filter(p)) { filetools.fs.stat(filepath, function (er0, stats) { if (er0) callback(undefined, er0); if (stats.isFile()) { filetools.fs.readFile(filepath, function (er1, data) { if (er1) { callback(undefined, er1); } else { self.addFile(zipPath + p, data, "", stats); next(); } }); } else { self.addFile(zipPath + p + "/", Buffer.alloc(0), "", stats); next(); } }); } else { next(); } } else { callback(true, undefined); } }; next(); } }); }, /** * * @param {string} localPath - path where files will be extracted * @param {object} props - optional properties * @param {string} props.zipPath - optional path inside zip * @param {regexp, function} props.filter - RegExp or Function if files match will be included. */ addLocalFolderPromise: function (/*String*/ localPath, /* object */ props) { return new Promise((resolve, reject) => { const { filter, zipPath } = Object.assign({}, props); this.addLocalFolderAsync( localPath, (done, err) => { if (err) reject(err); if (done) resolve(this); }, zipPath, filter ); }); }, /** * Allows you to create a entry (file or directory) in the zip file. * If you want to create a directory the entryName must end in / and a null buffer should be provided. * Comment and attributes are optional * * @param {string} entryName * @param {Buffer | string} content - file content as buffer or utf8 coded string * @param {string} comment - file comment * @param {number | object} attr - number as unix file permissions, object as filesystem Stats object */ addFile: function (/**String*/ entryName, /**Buffer*/ content, /**String*/ comment, /**Number*/ attr) { let entry = getEntry(entryName); const update = entry != null; // prepare new entry if (!update) { entry = new ZipEntry(); entry.entryName = entryName; } entry.comment = comment || ""; const isStat = "object" === typeof attr && attr instanceof filetools.fs.Stats; // last modification time from file stats if (isStat) { entry.header.time = attr.mtime; } // Set file attribute var fileattr = entry.isDirectory ? 0x10 : 0; // (MS-DOS directory flag) // extended attributes field for Unix if (!Utils.isWin) { // set file type either S_IFDIR / S_IFREG let unix = entry.isDirectory ? 0x4000 : 0x8000; if (isStat) { // File attributes from file stats unix |= 0xfff & attr.mode; } else if ("number" === typeof attr) { // attr from given attr values unix |= 0xfff & attr; } else { // Default values: unix |= entry.isDirectory ? 0o755 : 0o644; // permissions (drwxr-xr-x) or (-r-wr--r--) } fileattr = (fileattr | (unix << 16)) >>> 0; // add attributes } entry.attr = fileattr; entry.setData(content); if (!update) _zip.setEntry(entry); }, /** * Returns an array of ZipEntry objects representing the files and folders inside the archive * * @return Array */ getEntries: function () { return _zip ? _zip.entries : []; }, /** * Returns a ZipEntry object representing the file or folder specified by ``name``. * * @param name * @return ZipEntry */ getEntry: function (/**String*/ name) { return getEntry(name); }, getEntryCount: function () { return _zip.getEntryCount(); }, forEach: function (callback) { return _zip.forEach(callback); }, /** * Extracts the given entry to the given targetPath * If the entry is a directory inside the archive, the entire directory and it's subdirectories will be extracted * * @param entry ZipEntry object or String with the full path of the entry * @param targetPath Target folder where to write the file * @param maintainEntryPath If maintainEntryPath is true and the entry is inside a folder, the entry folder * will be created in targetPath as well. Default is TRUE * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true. * Default is FALSE * @param keepOriginalPermission The file will be set as the permission from the entry if this is true. * Default is FALSE * @param outFileName String If set will override the filename of the extracted file (Only works if the entry is a file) * * @return Boolean */ extractEntryTo: function ( /**Object*/ entry, /**String*/ targetPath, /**Boolean*/ maintainEntryPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /**String**/ outFileName ) { overwrite = get_Bool(overwrite, false); keepOriginalPermission = get_Bool(keepOriginalPermission, false); maintainEntryPath = get_Bool(maintainEntryPath, true); outFileName = get_Str(outFileName, get_Str(keepOriginalPermission, undefined)); var item = getEntry(entry); if (!item) { throw new Error(Utils.Errors.NO_ENTRY); } var entryName = canonical(item.entryName); var target = sanitize(targetPath, outFileName && !item.isDirectory ? outFileName : maintainEntryPath ? entryName : pth.basename(entryName)); if (item.isDirectory) { var children = _zip.getEntryChildren(item); children.forEach(function (child) { if (child.isDirectory) return; var content = child.getData(); if (!content) { throw new Error(Utils.Errors.CANT_EXTRACT_FILE); } var name = canonical(child.entryName); var childName = sanitize(targetPath, maintainEntryPath ? name : pth.basename(name)); // The reverse operation for attr depend on method addFile() const fileAttr = keepOriginalPermission ? child.header.fileAttr : undefined; filetools.writeFileTo(childName, content, overwrite, fileAttr); }); return true; } var content = item.getData(); if (!content) throw new Error(Utils.Errors.CANT_EXTRACT_FILE); if (filetools.fs.existsSync(target) && !overwrite) { throw new Error(Utils.Errors.CANT_OVERRIDE); } // The reverse operation for attr depend on method addFile() const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined; filetools.writeFileTo(target, content, overwrite, fileAttr); return true; }, /** * Test the archive * */ test: function (pass) { if (!_zip) { return false; } for (var entry in _zip.entries) { try { if (entry.isDirectory) { continue; } var content = _zip.entries[entry].getData(pass); if (!content) { return false; } } catch (err) { return false; } } return true; }, /** * Extracts the entire archive to the given location * * @param targetPath Target location * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true. * Default is FALSE * @param keepOriginalPermission The file will be set as the permission from the entry if this is true. * Default is FALSE */ extractAllTo: function (/**String*/ targetPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /*String, Buffer*/ pass) { overwrite = get_Bool(overwrite, false); pass = get_Str(keepOriginalPermission, pass); keepOriginalPermission = get_Bool(keepOriginalPermission, false); if (!_zip) { throw new Error(Utils.Errors.NO_ZIP); } _zip.entries.forEach(function (entry) { var entryName = sanitize(targetPath, canonical(entry.entryName.toString())); if (entry.isDirectory) { filetools.makeDir(entryName); return; } var content = entry.getData(pass); if (!content) { throw new Error(Utils.Errors.CANT_EXTRACT_FILE); } // The reverse operation for attr depend on method addFile() const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined; filetools.writeFileTo(entryName, content, overwrite, fileAttr); try { filetools.fs.utimesSync(entryName, entry.header.time, entry.header.time); } catch (err) { throw new Error(Utils.Errors.CANT_EXTRACT_FILE); } }); }, /** * Asynchronous extractAllTo * * @param targetPath Target location * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true. * Default is FALSE * @param keepOriginalPermission The file will be set as the permission from the entry if this is true. * Default is FALSE * @param callback The callback will be executed when all entries are extracted successfully or any error is thrown. */ extractAllToAsync: function (/**String*/ targetPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /**Function*/ callback) { if (!callback) { callback = function () {}; } overwrite = get_Bool(overwrite, false); if (typeof keepOriginalPermission === "function" && !callback) callback = keepOriginalPermission; keepOriginalPermission = get_Bool(keepOriginalPermission, false); if (!_zip) { callback(new Error(Utils.Errors.NO_ZIP)); return; } targetPath = pth.resolve(targetPath); // convert entryName to const getPath = (entry) => sanitize(targetPath, pth.normalize(canonical(entry.entryName.toString()))); const getError = (msg, file) => new Error(msg + ': "' + file + '"'); // separate directories from files const dirEntries = []; const fileEntries = new Set(); _zip.entries.forEach((e) => { if (e.isDirectory) { dirEntries.push(e); } else { fileEntries.add(e); } }); // Create directory entries first synchronously // this prevents race condition and assures folders are there before writing files for (const entry of dirEntries) { const dirPath = getPath(entry); // The reverse operation for attr depend on method addFile() const dirAttr = keepOriginalPermission ? entry.header.fileAttr : undefined; try { filetools.makeDir(dirPath); if (dirAttr) filetools.fs.chmodSync(dirPath, dirAttr); // in unix timestamp will change if files are later added to folder, but still filetools.fs.utimesSync(dirPath, entry.header.time, entry.header.time); } catch (er) { callback(getError("Unable to create folder", dirPath)); } } // callback wrapper, for some house keeping const done = () => { if (fileEntries.size === 0) { callback(); } }; // Extract file entries asynchronously for (const entry of fileEntries.values()) { const entryName = pth.normalize(canonical(entry.entryName.toString())); const filePath = sanitize(targetPath, entryName); entry.getDataAsync(function (content, err_1) { if (err_1) { callback(new Error(err_1)); return; } if (!content) { callback(new Error(Utils.Errors.CANT_EXTRACT_FILE)); } else { // The reverse operation for attr depend on method addFile() const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined; filetools.writeFileToAsync(filePath, content, overwrite, fileAttr, function (succ) { if (!succ) { callback(getError("Unable to write file", filePath)); return; } filetools.fs.utimes(filePath, entry.header.time, entry.header.time, function (err_2) { if (err_2) { callback(getError("Unable to set times", filePath)); return; } fileEntries.delete(entry); // call the callback if it was last entry done(); }); }); } }); } // call the callback if fileEntries was empty done(); }, /** * Writes the newly created zip file to disk at the specified location or if a zip was opened and no ``targetFileName`` is provided, it will overwrite the opened zip * * @param targetFileName * @param callback */ writeZip: function (/**String*/ targetFileName, /**Function*/ callback) { if (arguments.length === 1) { if (typeof targetFileName === "function") { callback = targetFileName; targetFileName = ""; } } if (!targetFileName && opts.filename) { targetFileName = opts.filename; } if (!targetFileName) return; var zipData = _zip.compressToBuffer(); if (zipData) { var ok = filetools.writeFileTo(targetFileName, zipData, true); if (typeof callback === "function") callback(!ok ? new Error("failed") : null, ""); } }, writeZipPromise: function (/**String*/ targetFileName, /* object */ props) { const { overwrite, perm } = Object.assign({ overwrite: true }, props); return new Promise((resolve, reject) => { // find file name if (!targetFileName && opts.filename) targetFileName = opts.filename; if (!targetFileName) reject("ADM-ZIP: ZIP File Name Missing"); this.toBufferPromise().then((zipData) => { const ret = (done) => (done ? resolve(done) : reject("ADM-ZIP: Wasn't able to write zip file")); filetools.writeFileToAsync(targetFileName, zipData, overwrite, perm, ret); }, reject); }); }, toBufferPromise: function () { return new Promise((resolve, reject) => { _zip.toAsyncBuffer(resolve, reject); }); }, /** * Returns the content of the entire zip file as a Buffer object * * @return Buffer */ toBuffer: function (/**Function=*/ onSuccess, /**Function=*/ onFail, /**Function=*/ onItemStart, /**Function=*/ onItemEnd) { this.valueOf = 2; if (typeof onSuccess === "function") { _zip.toAsyncBuffer(onSuccess, onFail, onItemStart, onItemEnd); return null; } return _zip.compressToBuffer(); } }; }; /***/ }), /***/ 42907: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var Utils = __webpack_require__(85173), Constants = Utils.Constants; /* The central directory file header */ module.exports = function () { var _verMade = 20, // v2.0 _version = 10, // v1.0 _flags = 0, _method = 0, _time = 0, _crc = 0, _compressedSize = 0, _size = 0, _fnameLen = 0, _extraLen = 0, _comLen = 0, _diskStart = 0, _inattr = 0, _attr = 0, _offset = 0; _verMade |= Utils.isWin ? 0x0a00 : 0x0300; // Set EFS flag since filename and comment fields are all by default encoded using UTF-8. // Without it file names may be corrupted for other apps when file names use unicode chars _flags |= Constants.FLG_EFS; var _dataHeader = {}; function setTime(val) { val = new Date(val); _time = (((val.getFullYear() - 1980) & 0x7f) << 25) | // b09-16 years from 1980 ((val.getMonth() + 1) << 21) | // b05-08 month (val.getDate() << 16) | // b00-04 hour // 2 bytes time (val.getHours() << 11) | // b11-15 hour (val.getMinutes() << 5) | // b05-10 minute (val.getSeconds() >> 1); // b00-04 seconds divided by 2 } setTime(+new Date()); return { get made() { return _verMade; }, set made(val) { _verMade = val; }, get version() { return _version; }, set version(val) { _version = val; }, get flags() { return _flags; }, set flags(val) { _flags = val; }, get method() { return _method; }, set method(val) { switch (val) { case Constants.STORED: this.version = 10; case Constants.DEFLATED: default: this.version = 20; } _method = val; }, get time() { return new Date(((_time >> 25) & 0x7f) + 1980, ((_time >> 21) & 0x0f) - 1, (_time >> 16) & 0x1f, (_time >> 11) & 0x1f, (_time >> 5) & 0x3f, (_time & 0x1f) << 1); }, set time(val) { setTime(val); }, get crc() { return _crc; }, set crc(val) { _crc = Math.max(0, val) >>> 0; }, get compressedSize() { return _compressedSize; }, set compressedSize(val) { _compressedSize = Math.max(0, val) >>> 0; }, get size() { return _size; }, set size(val) { _size = Math.max(0, val) >>> 0; }, get fileNameLength() { return _fnameLen; }, set fileNameLength(val) { _fnameLen = val; }, get extraLength() { return _extraLen; }, set extraLength(val) { _extraLen = val; }, get commentLength() { return _comLen; }, set commentLength(val) { _comLen = val; }, get diskNumStart() { return _diskStart; }, set diskNumStart(val) { _diskStart = Math.max(0, val) >>> 0; }, get inAttr() { return _inattr; }, set inAttr(val) { _inattr = Math.max(0, val) >>> 0; }, get attr() { return _attr; }, set attr(val) { _attr = Math.max(0, val) >>> 0; }, // get Unix file permissions get fileAttr() { return _attr ? (((_attr >>> 0) | 0) >> 16) & 0xfff : 0; }, get offset() { return _offset; }, set offset(val) { _offset = Math.max(0, val) >>> 0; }, get encripted() { return (_flags & 1) === 1; }, get entryHeaderSize() { return Constants.CENHDR + _fnameLen + _extraLen + _comLen; }, get realDataOffset() { return _offset + Constants.LOCHDR + _dataHeader.fnameLen + _dataHeader.extraLen; }, get dataHeader() { return _dataHeader; }, loadDataHeaderFromBinary: function (/*Buffer*/ input) { var data = input.slice(_offset, _offset + Constants.LOCHDR); // 30 bytes and should start with "PK\003\004" if (data.readUInt32LE(0) !== Constants.LOCSIG) { throw new Error(Utils.Errors.INVALID_LOC); } _dataHeader = { // version needed to extract version: data.readUInt16LE(Constants.LOCVER), // general purpose bit flag flags: data.readUInt16LE(Constants.LOCFLG), // compression method method: data.readUInt16LE(Constants.LOCHOW), // modification time (2 bytes time, 2 bytes date) time: data.readUInt32LE(Constants.LOCTIM), // uncompressed file crc-32 value crc: data.readUInt32LE(Constants.LOCCRC), // compressed size compressedSize: data.readUInt32LE(Constants.LOCSIZ), // uncompressed size size: data.readUInt32LE(Constants.LOCLEN), // filename length fnameLen: data.readUInt16LE(Constants.LOCNAM), // extra field length extraLen: data.readUInt16LE(Constants.LOCEXT) }; }, loadFromBinary: function (/*Buffer*/ data) { // data should be 46 bytes and start with "PK 01 02" if (data.length !== Constants.CENHDR || data.readUInt32LE(0) !== Constants.CENSIG) { throw new Error(Utils.Errors.INVALID_CEN); } // version made by _verMade = data.readUInt16LE(Constants.CENVEM); // version needed to extract _version = data.readUInt16LE(Constants.CENVER); // encrypt, decrypt flags _flags = data.readUInt16LE(Constants.CENFLG); // compression method _method = data.readUInt16LE(Constants.CENHOW); // modification time (2 bytes time, 2 bytes date) _time = data.readUInt32LE(Constants.CENTIM); // uncompressed file crc-32 value _crc = data.readUInt32LE(Constants.CENCRC); // compressed size _compressedSize = data.readUInt32LE(Constants.CENSIZ); // uncompressed size _size = data.readUInt32LE(Constants.CENLEN); // filename length _fnameLen = data.readUInt16LE(Constants.CENNAM); // extra field length _extraLen = data.readUInt16LE(Constants.CENEXT); // file comment length _comLen = data.readUInt16LE(Constants.CENCOM); // volume number start _diskStart = data.readUInt16LE(Constants.CENDSK); // internal file attributes _inattr = data.readUInt16LE(Constants.CENATT); // external file attributes _attr = data.readUInt32LE(Constants.CENATX); // LOC header offset _offset = data.readUInt32LE(Constants.CENOFF); }, dataHeaderToBinary: function () { // LOC header size (30 bytes) var data = Buffer.alloc(Constants.LOCHDR); // "PK\003\004" data.writeUInt32LE(Constants.LOCSIG, 0); // version needed to extract data.writeUInt16LE(_version, Constants.LOCVER); // general purpose bit flag data.writeUInt16LE(_flags, Constants.LOCFLG); // compression method data.writeUInt16LE(_method, Constants.LOCHOW); // modification time (2 bytes time, 2 bytes date) data.writeUInt32LE(_time, Constants.LOCTIM); // uncompressed file crc-32 value data.writeUInt32LE(_crc, Constants.LOCCRC); // compressed size data.writeUInt32LE(_compressedSize, Constants.LOCSIZ); // uncompressed size data.writeUInt32LE(_size, Constants.LOCLEN); // filename length data.writeUInt16LE(_fnameLen, Constants.LOCNAM); // extra field length data.writeUInt16LE(_extraLen, Constants.LOCEXT); return data; }, entryHeaderToBinary: function () { // CEN header size (46 bytes) var data = Buffer.alloc(Constants.CENHDR + _fnameLen + _extraLen + _comLen); // "PK\001\002" data.writeUInt32LE(Constants.CENSIG, 0); // version made by data.writeUInt16LE(_verMade, Constants.CENVEM); // version needed to extract data.writeUInt16LE(_version, Constants.CENVER); // encrypt, decrypt flags data.writeUInt16LE(_flags, Constants.CENFLG); // compression method data.writeUInt16LE(_method, Constants.CENHOW); // modification time (2 bytes time, 2 bytes date) data.writeUInt32LE(_time, Constants.CENTIM); // uncompressed file crc-32 value data.writeUInt32LE(_crc, Constants.CENCRC); // compressed size data.writeUInt32LE(_compressedSize, Constants.CENSIZ); // uncompressed size data.writeUInt32LE(_size, Constants.CENLEN); // filename length data.writeUInt16LE(_fnameLen, Constants.CENNAM); // extra field length data.writeUInt16LE(_extraLen, Constants.CENEXT); // file comment length data.writeUInt16LE(_comLen, Constants.CENCOM); // volume number start data.writeUInt16LE(_diskStart, Constants.CENDSK); // internal file attributes data.writeUInt16LE(_inattr, Constants.CENATT); // external file attributes data.writeUInt32LE(_attr, Constants.CENATX); // LOC header offset data.writeUInt32LE(_offset, Constants.CENOFF); // fill all with data.fill(0x00, Constants.CENHDR); return data; }, toJSON: function () { const bytes = function (nr) { return nr + " bytes"; }; return { made: _verMade, version: _version, flags: _flags, method: Utils.methodToString(_method), time: this.time, crc: "0x" + _crc.toString(16).toUpperCase(), compressedSize: bytes(_compressedSize), size: bytes(_size), fileNameLength: bytes(_fnameLen), extraLength: bytes(_extraLen), commentLength: bytes(_comLen), diskNumStart: _diskStart, inAttr: _inattr, attr: _attr, offset: _offset, entryHeaderSize: bytes(Constants.CENHDR + _fnameLen + _extraLen + _comLen) }; }, toString: function () { return JSON.stringify(this.toJSON(), null, "\t"); } }; }; /***/ }), /***/ 53854: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { exports.EntryHeader = __webpack_require__(42907); exports.MainHeader = __webpack_require__(83519); /***/ }), /***/ 83519: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var Utils = __webpack_require__(85173), Constants = Utils.Constants; /* The entries in the end of central directory */ module.exports = function () { var _volumeEntries = 0, _totalEntries = 0, _size = 0, _offset = 0, _commentLength = 0; return { get diskEntries() { return _volumeEntries; }, set diskEntries(/*Number*/ val) { _volumeEntries = _totalEntries = val; }, get totalEntries() { return _totalEntries; }, set totalEntries(/*Number*/ val) { _totalEntries = _volumeEntries = val; }, get size() { return _size; }, set size(/*Number*/ val) { _size = val; }, get offset() { return _offset; }, set offset(/*Number*/ val) { _offset = val; }, get commentLength() { return _commentLength; }, set commentLength(/*Number*/ val) { _commentLength = val; }, get mainHeaderSize() { return Constants.ENDHDR + _commentLength; }, loadFromBinary: function (/*Buffer*/ data) { // data should be 22 bytes and start with "PK 05 06" // or be 56+ bytes and start with "PK 06 06" for Zip64 if ( (data.length !== Constants.ENDHDR || data.readUInt32LE(0) !== Constants.ENDSIG) && (data.length < Constants.ZIP64HDR || data.readUInt32LE(0) !== Constants.ZIP64SIG) ) { throw new Error(Utils.Errors.INVALID_END); } if (data.readUInt32LE(0) === Constants.ENDSIG) { // number of entries on this volume _volumeEntries = data.readUInt16LE(Constants.ENDSUB); // total number of entries _totalEntries = data.readUInt16LE(Constants.ENDTOT); // central directory size in bytes _size = data.readUInt32LE(Constants.ENDSIZ); // offset of first CEN header _offset = data.readUInt32LE(Constants.ENDOFF); // zip file comment length _commentLength = data.readUInt16LE(Constants.ENDCOM); } else { // number of entries on this volume _volumeEntries = Utils.readBigUInt64LE(data, Constants.ZIP64SUB); // total number of entries _totalEntries = Utils.readBigUInt64LE(data, Constants.ZIP64TOT); // central directory size in bytes _size = Utils.readBigUInt64LE(data, Constants.ZIP64SIZ); // offset of first CEN header _offset = Utils.readBigUInt64LE(data, Constants.ZIP64OFF); _commentLength = 0; } }, toBinary: function () { var b = Buffer.alloc(Constants.ENDHDR + _commentLength); // "PK 05 06" signature b.writeUInt32LE(Constants.ENDSIG, 0); b.writeUInt32LE(0, 4); // number of entries on this volume b.writeUInt16LE(_volumeEntries, Constants.ENDSUB); // total number of entries b.writeUInt16LE(_totalEntries, Constants.ENDTOT); // central directory size in bytes b.writeUInt32LE(_size, Constants.ENDSIZ); // offset of first CEN header b.writeUInt32LE(_offset, Constants.ENDOFF); // zip file comment length b.writeUInt16LE(_commentLength, Constants.ENDCOM); // fill comment memory with spaces so no garbage is left there b.fill(" ", Constants.ENDHDR); return b; }, toJSON: function () { // creates 0x0000 style output const offset = function (nr, len) { let offs = nr.toString(16).toUpperCase(); while (offs.length < len) offs = "0" + offs; return "0x" + offs; }; return { diskEntries: _volumeEntries, totalEntries: _totalEntries, size: _size + " bytes", offset: offset(_offset, 4), commentLength: _commentLength }; }, toString: function () { return JSON.stringify(this.toJSON(), null, "\t"); } }; }; /***/ }), /***/ 10278: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = function (/*Buffer*/ inbuf) { var zlib = __webpack_require__(78761); var opts = { chunkSize: (parseInt(inbuf.length / 1024) + 1) * 1024 }; return { deflate: function () { return zlib.deflateRawSync(inbuf, opts); }, deflateAsync: function (/*Function*/ callback) { var tmp = zlib.createDeflateRaw(opts), parts = [], total = 0; tmp.on("data", function (data) { parts.push(data); total += data.length; }); tmp.on("end", function () { var buf = Buffer.alloc(total), written = 0; buf.fill(0); for (var i = 0; i < parts.length; i++) { var part = parts[i]; part.copy(buf, written); written += part.length; } callback && callback(buf); }); tmp.end(inbuf); } }; }; /***/ }), /***/ 81004: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { exports.Deflater = __webpack_require__(10278); exports.Inflater = __webpack_require__(61269); exports.ZipCrypto = __webpack_require__(94729); /***/ }), /***/ 61269: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = function (/*Buffer*/ inbuf) { var zlib = __webpack_require__(78761); return { inflate: function () { return zlib.inflateRawSync(inbuf); }, inflateAsync: function (/*Function*/ callback) { var tmp = zlib.createInflateRaw(), parts = [], total = 0; tmp.on("data", function (data) { parts.push(data); total += data.length; }); tmp.on("end", function () { var buf = Buffer.alloc(total), written = 0; buf.fill(0); for (var i = 0; i < parts.length; i++) { var part = parts[i]; part.copy(buf, written); written += part.length; } callback && callback(buf); }); tmp.end(inbuf); } }; }; /***/ }), /***/ 94729: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; // node crypt, we use it for generate salt // eslint-disable-next-line node/no-unsupported-features/node-builtins const { randomFillSync } = __webpack_require__(76417); // generate CRC32 lookup table const crctable = new Uint32Array(256).map((t, crc) => { for (let j