File size: 105,671 Bytes
55282a7 | 1 2 3 4 5 6 7 | {"id": "patchbench-js-real-0081", "repo": "cthackers/adm-zip", "base_commit": "1cd32f7e0ad3c540142a76609bb538a5cda2292f", "status": "verified", "verify_status": "verified", "error": null, "timing": {"setup": 0.8, "pre_test_0": 2.6, "pre_test_1": 0.6, "post_test_0": 1.3, "post_test_1": 0.6, "total": 6.0}, "test_cmds": ["mkdir -p reports; npx mocha --reporter json > reports/mocha-results.json"], "rebuild_cmds": [], "print_cmds": [], "f2p_pre_ok": true, "pre_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 87}, "p2p_env_dropped_count": 0, "f2p_post_ok": true, "p2p_post_ok": true, "post_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 87}, "raw_tail": " \"duration\": 0,\n \"currentRetry\": 0,\n \"speed\": \"fast\",\n \"err\": {}\n },\n {\n \"title\": \"centralHeader date if date is specified\",\n \"fullTitle\": \"headers central-header centralHeader date if date is specified\",\n \"file\": \"/tmp/cache/repos/cthackers__adm-zip/test/header.js\",\n \"duration\": 0,\n \"currentRetry\": 0,\n \"speed\": \"fast\",\n \"err\": {}\n },\n {\n \"title\": \"compare binary header values with predetermined values\",\n \"fullTitle\": \"headers central-header local-header compare binary header values with predetermined values\",\n \"file\": \"/tmp/cache/repos/cthackers__adm-zip/test/header.js\",\n \"duration\": 0,\n \"currentRetry\": 0,\n \"speed\": \"fast\",\n \"err\": {}\n },\n {\n \"title\": \"read binary and create new binary from it, they have to be equal\",\n \"fullTitle\": \"headers central-header local-header read binary and create new binary from it, they have to be equal\",\n \"file\": \"/tmp/cache/repos/cthackers__adm-zip/test/header.js\",\n \"duration\": 0,\n \"currentRetry\": 0,\n \"speed\": \"fast\",\n \"err\": {}\n },\n {\n \"title\": \"construct header by values and compare binaries have to be equal\",\n \"fullTitle\": \"headers central-header local-header construct header by values and compare binaries have to be equal\",\n \"file\": \"/tmp/cache/repos/cthackers__adm-zip/test/header.js\",\n \"duration\": 0,\n \"currentRetry\": 0,\n \"speed\": \"fast\",\n \"err\": {}\n }\n ]\n}\n", "context_files": [{"path": "zipEntry.js", "content": "var Utils = require(\"./util\"),\n Headers = require(\"./headers\"),\n Constants = Utils.Constants,\n Methods = require(\"./methods\");\n\nmodule.exports = function (/** object */ options, /*Buffer*/ input) {\n var _centralHeader = new Headers.EntryHeader(),\n _entryName = Buffer.alloc(0),\n _comment = Buffer.alloc(0),\n _isDirectory = false,\n uncompressedData = null,\n _extra = Buffer.alloc(0),\n _extralocal = Buffer.alloc(0),\n _efs = true;\n\n // assign options\n const opts = options;\n\n const decoder = typeof opts.decoder === \"object\" ? opts.decoder : Utils.decoder;\n _efs = decoder.hasOwnProperty(\"efs\") ? decoder.efs : false;\n\n function getCompressedDataFromZip() {\n //if (!input || !Buffer.isBuffer(input)) {\n if (!input || !(input instanceof Uint8Array)) {\n return Buffer.alloc(0);\n }\n _extralocal = _centralHeader.loadLocalHeaderFromBinary(input);\n return input.slice(_centralHeader.realDataOffset, _centralHeader.realDataOffset + _centralHeader.compressedSize);\n }\n\n function crc32OK(data) {\n // if bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the local header is written\n if (!_centralHeader.flags_desc && !_centralHeader.localHeader.flags_desc) {\n if (Utils.crc32(data) !== _centralHeader.localHeader.crc) {\n return false;\n }\n } else {\n const descriptor = {};\n const dataEndOffset = _centralHeader.realDataOffset + _centralHeader.compressedSize;\n // no descriptor after compressed data, instead new local header\n if (input.readUInt32LE(dataEndOffset) == Constants.LOCSIG || input.readUInt32LE(dataEndOffset) == Constants.CENSIG) {\n throw Utils.Errors.DESCRIPTOR_NOT_EXIST();\n }\n\n // get decriptor data\n if (input.readUInt32LE(dataEndOffset) == Constants.EXTSIG) {\n // descriptor with signature\n descriptor.crc = input.readUInt32LE(dataEndOffset + Constants.EXTCRC);\n descriptor.compressedSize = input.readUInt32LE(dataEndOffset + Constants.EXTSIZ);\n descriptor.size = input.readUInt32LE(dataEndOffset + Constants.EXTLEN);\n } else if (input.readUInt16LE(dataEndOffset + 12) === 0x4b50) {\n // descriptor without signature (we check is new header starting where we expect)\n descriptor.crc = input.readUInt32LE(dataEndOffset + Constants.EXTCRC - 4);\n descriptor.compressedSize = input.readUInt32LE(dataEndOffset + Constants.EXTSIZ - 4);\n descriptor.size = input.readUInt32LE(dataEndOffset + Constants.EXTLEN - 4);\n } else {\n throw Utils.Errors.DESCRIPTOR_UNKNOWN();\n }\n\n // check data integrity\n if (descriptor.compressedSize !== _centralHeader.compressedSize || descriptor.size !== _centralHeader.size || descriptor.crc !== _centralHeader.crc) {\n throw Utils.Errors.DESCRIPTOR_FAULTY();\n }\n if (Utils.crc32(data) !== descriptor.crc) {\n return false;\n }\n\n // @TODO: zip64 bit descriptor fields\n // if bit 3 is set and any value in local header \"zip64 Extended information\" extra field are set 0 (place holder)\n // then 64-bit descriptor format is used instead of 32-bit\n // central header - \"zip64 Extended information\" extra field should store real values and not place holders\n }\n return true;\n }\n\n function decompress(/*Boolean*/ async, /*Function*/ callback, /*String, Buffer*/ pass) {\n if (typeof callback === \"undefined\" && typeof async === \"string\") {\n pass = async;\n async = void 0;\n }\n if (_isDirectory) {\n if (async && callback) {\n callback(Buffer.alloc(0), Utils.Errors.DIRECTORY_CONTENT_ERROR()); //si added error.\n }\n return Buffer.alloc(0);\n }\n\n var compressedData = getCompressedDataFromZip();\n\n if (compressedData.length === 0) {\n // File is empty, nothing to decompress.\n if (async && callback) callback(compressedData);\n return compressedData;\n }\n\n if (_centralHeader.encrypted) {\n if (\"string\" !== typeof pass && !Buffer.isBuffer(pass)) {\n throw Utils.Errors.INVALID_PASS_PARAM();\n }\n compressedData = Methods.ZipCrypto.decrypt(compressedData, _centralHeader, pass);\n }\n\n var data = Buffer.alloc(_centralHeader.size);\n\n switch (_centralHeader.method) {\n case Utils.Constants.STORED:\n compressedData.copy(data);\n if (!crc32OK(data)) {\n if (async && callback) callback(data, Utils.Errors.BAD_CRC()); //si added error\n throw Utils.Errors.BAD_CRC();\n } else {\n //si added otherwise did not seem to return data.\n if (async && callback) callback(data);\n return data;\n }\n case Utils.Constants.DEFLATED:\n var inflater = new Methods.Inflater(compressedData, _centralHeader.size);\n if (!async) {\n const result = inflater.inflate(data);\n result.copy(data, 0);\n if (!crc32OK(data)) {\n throw Utils.Errors.BAD_CRC(`\"${decoder.decode(_entryName)}\"`);\n }\n return data;\n } else {\n inflater.inflateAsync(function (result) {\n result.copy(result, 0);\n if (callback) {\n if (!crc32OK(result)) {\n callback(result, Utils.Errors.BAD_CRC()); //si added error\n } else {\n callback(result);\n }\n }\n });\n }\n break;\n default:\n if (async && callback) callback(Buffer.alloc(0), Utils.Errors.UNKNOWN_METHOD());\n throw Utils.Errors.UNKNOWN_METHOD();\n }\n }\n\n function compress(/*Boolean*/ async, /*Function*/ callback) {\n if ((!uncompressedData || !uncompressedData.length) && Buffer.isBuffer(input)) {\n // no data set or the data wasn't changed to require recompression\n if (async && callback) callback(getCompressedDataFromZip());\n return getCompressedDataFromZip();\n }\n\n if (uncompressedData.length && !_isDirectory) {\n var compressedData;\n // Local file header\n switch (_centralHeader.method) {\n case Utils.Constants.STORED:\n _centralHeader.compressedSize = _centralHeader.size;\n\n compressedData = Buffer.alloc(uncompressedData.length);\n uncompressedData.copy(compressedData);\n\n if (async && callback) callback(compressedData);\n return compressedData;\n default:\n case Utils.Constants.DEFLATED:\n var deflater = new Methods.Deflater(uncompressedData);\n if (!async) {\n var deflated = deflater.deflate();\n _centralHeader.compressedSize = deflated.length;\n return deflated;\n } else {\n deflater.deflateAsync(function (data) {\n compressedData = Buffer.alloc(data.length);\n _centralHeader.compressedSize = data.length;\n data.copy(compressedData);\n callback && callback(compressedData);\n });\n }\n deflater = null;\n break;\n }\n } else if (async && callback) {\n callback(Buffer.alloc(0));\n } else {\n return Buffer.alloc(0);\n }\n }\n\n function readUInt64LE(buffer, offset) {\n return (buffer.readUInt32LE(offset + 4) << 4) + buffer.readUInt32LE(offset);\n }\n\n function parseExtra(data) {\n try {\n var offset = 0;\n var signature, size, part;\n while (offset + 4 < data.length) {\n signature = data.readUInt16LE(offset);\n offset += 2;\n size = data.readUInt16LE(offset);\n offset += 2;\n part = data.slice(offset, offset + size);\n offset += size;\n if (Constants.ID_ZIP64 === signature) {\n parseZip64ExtendedInformation(part);\n }\n }\n } catch (error) {\n throw Utils.Errors.EXTRA_FIELD_PARSE_ERROR();\n }\n }\n\n //Override header field values with values from the ZIP64 extra field\n function parseZip64ExtendedInformation(data) {\n var size, compressedSize, offset, diskNumStart;\n\n if (data.length >= Constants.EF_ZIP64_SCOMP) {\n size = readUInt64LE(data, Constants.EF_ZIP64_SUNCOMP);\n if (_centralHeader.size === Constants.EF_ZIP64_OR_32) {\n _centralHeader.size = size;\n }\n }\n if (data.length >= Constants.EF_ZIP64_RHO) {\n compressedSize = readUInt64LE(data, Constants.EF_ZIP64_SCOMP);\n if (_centralHeader.compressedSize === Constants.EF_ZIP64_OR_32) {\n _centralHeader.compressedSize = compressedSize;\n }\n }\n if (data.length >= Constants.EF_ZIP64_DSN) {\n offset = readUInt64LE(data, Constants.EF_ZIP64_RHO);\n if (_centralHeader.offset === Constants.EF_ZIP64_OR_32) {\n _centralHeader.offset = offset;\n }\n }\n if (data.length >= Constants.EF_ZIP64_DSN + 4) {\n diskNumStart = data.readUInt32LE(Constants.EF_ZIP64_DSN);\n if (_centralHeader.diskNumStart === Constants.EF_ZIP64_OR_16) {\n _centralHeader.diskNumStart = diskNumStart;\n }\n }\n }\n\n return {\n get entryName() {\n return decoder.decode(_entryName);\n },\n get rawEntryName() {\n return _entryName;\n },\n set entryName(val) {\n _entryName = Utils.toBuffer(val, decoder.encode);\n var lastChar = _entryName[_entryName.length - 1];\n _isDirectory = lastChar === 47 || lastChar === 92;\n _centralHeader.fileNameLength = _entryName.length;\n },\n\n get efs() {\n if (typeof _efs === \"function\") {\n return _efs(this.entryName);\n } else {\n return _efs;\n }\n },\n\n get extra() {\n return _extra;\n },\n set extra(val) {\n _extra = val;\n _centralHeader.extraLength = val.length;\n parseExtra(val);\n },\n\n get comment() {\n return decoder.decode(_comment);\n },\n set comment(val) {\n _comment = Utils.toBuffer(val, decoder.encode);\n _centralHeader.commentLength = _comment.length;\n if (_comment.length > 0xffff) throw Utils.Errors.COMMENT_TOO_LONG();\n },\n\n get name() {\n var n = decoder.decode(_entryName);\n return _isDirectory\n ? n\n .substr(n.length - 1)\n .split(\"/\")\n .pop()\n : n.split(\"/\").pop();\n },\n get isDirectory() {\n return _isDirectory;\n },\n\n getCompressedData: function () {\n return compress(false, null);\n },\n\n getCompressedDataAsync: function (/*Function*/ callback) {\n compress(true, callback);\n },\n\n setData: function (value) {\n uncompressedData = Utils.toBuffer(value, Utils.decoder.encode);\n if (!_isDirectory && uncompressedData.length) {\n _centralHeader.size = uncompressedData.length;\n _centralHeader.method = Utils.Constants.DEFLATED;\n _centralHeader.crc = Utils.crc32(value);\n _centralHeader.changed = true;\n } else {\n // folders and blank files should be stored\n _centralHeader.method = Utils.Constants.STORED;\n }\n },\n\n getData: function (pass) {\n if (_centralHeader.changed) {\n return uncompressedData;\n } else {\n return decompress(false, null, pass);\n }\n },\n\n getDataAsync: function (/*Function*/ callback, pass) {\n if (_centralHeader.changed) {\n callback(uncompressedData);\n } else {\n decompress(true, callback, pass);\n }\n },\n\n set attr(attr) {\n _centralHeader.attr = attr;\n },\n get attr() {\n return _centralHeader.attr;\n },\n\n set header(/*Buffer*/ data) {\n _centralHeader.loadFromBinary(data);\n },\n\n get header() {\n return _centralHeader;\n },\n\n packCentralHeader: function () {\n _centralHeader.flags_efs = this.efs;\n _centralHeader.extraLength = _extra.length;\n // 1. create header (buffer)\n var header = _centralHeader.centralHeaderToBinary();\n var addpos = Utils.Constants.CENHDR;\n // 2. add file name\n _entryName.copy(header, addpos);\n addpos += _entryName.length;\n // 3. add extra data\n _extra.copy(header, addpos);\n addpos += _centralHeader.extraLength;\n // 4. add file comment\n _comment.copy(header, addpos);\n return header;\n },\n\n packLocalHeader: function () {\n let addpos = 0;\n _centralHeader.flags_efs = this.efs;\n _centralHeader.extraLocalLength = _extralocal.length;\n // 1. construct local header Buffer\n const localHeaderBuf = _centralHeader.localHeaderToBinary();\n // 2. localHeader - crate header buffer\n const localHeader = Buffer.alloc(localHeaderBuf.length + _entryName.length + _centralHeader.extraLocalLength);\n // 2.1 add localheader\n localHeaderBuf.copy(localHeader, addpos);\n addpos += localHeaderBuf.length;\n // 2.2 add file name\n _entryName.copy(localHeader, addpos);\n addpos += _entryName.length;\n // 2.3 add extra field\n _extralocal.copy(localHeader, addpos);\n addpos += _extralocal.length;\n\n return localHeader;\n },\n\n toJSON: function () {\n const bytes = function (nr) {\n return \"<\" + ((nr && nr.length + \" bytes buffer\") || \"null\") + \">\";\n };\n\n return {\n entryName: this.entryName,\n name: this.name,\n comment: this.comment,\n isDirectory: this.isDirectory,\n header: _centralHeader.toJSON(),\n compressedData: bytes(input),\n data: bytes(uncompressedData)\n };\n },\n\n toString: function () {\n return JSON.stringify(this.toJSON(), null, \"\\t\");\n }\n };\n};\n"}, {"path": "zipFile.js", "content": "const ZipEntry = require(\"./zipEntry\");\nconst Headers = require(\"./headers\");\nconst Utils = require(\"./util\");\n\nmodule.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {\n var entryList = [],\n entryTable = {},\n _comment = Buffer.alloc(0),\n mainHeader = new Headers.MainHeader(),\n loadedEntries = false;\n var password = null;\n const temporary = new Set();\n\n // assign options\n const opts = options;\n\n const { noSort, decoder } = opts;\n\n if (inBuffer) {\n // is a memory buffer\n readMainHeader(opts.readEntries);\n } else {\n // none. is a new file\n loadedEntries = true;\n }\n\n function makeTemporaryFolders() {\n const foldersList = new Set();\n\n // Make list of all folders in file\n for (const elem of Object.keys(entryTable)) {\n const elements = elem.split(\"/\");\n elements.pop(); // filename\n if (!elements.length) continue; // no folders\n for (let i = 0; i < elements.length; i++) {\n const sub = elements.slice(0, i + 1).join(\"/\") + \"/\";\n foldersList.add(sub);\n }\n }\n\n // create missing folders as temporary\n for (const elem of foldersList) {\n if (!(elem in entryTable)) {\n const tempfolder = new ZipEntry(opts);\n tempfolder.entryName = elem;\n tempfolder.attr = 0x10;\n tempfolder.temporary = true;\n entryList.push(tempfolder);\n entryTable[tempfolder.entryName] = tempfolder;\n temporary.add(tempfolder);\n }\n }\n }\n\n function readEntries() {\n loadedEntries = true;\n entryTable = {};\n if (mainHeader.diskEntries > (inBuffer.length - mainHeader.offset) / Utils.Constants.CENHDR) {\n throw Utils.Errors.DISK_ENTRY_TOO_LARGE();\n }\n entryList = new Array(mainHeader.diskEntries); // total number of entries\n var index = mainHeader.offset; // offset of first CEN header\n for (var i = 0; i < entryList.length; i++) {\n var tmp = index,\n entry = new ZipEntry(opts, inBuffer);\n entry.header = inBuffer.slice(tmp, (tmp += Utils.Constants.CENHDR));\n\n entry.entryName = inBuffer.slice(tmp, (tmp += entry.header.fileNameLength));\n\n if (entry.header.extraLength) {\n entry.extra = inBuffer.slice(tmp, (tmp += entry.header.extraLength));\n }\n\n if (entry.header.commentLength) entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);\n\n index += entry.header.centralHeaderSize;\n\n entryList[i] = entry;\n entryTable[entry.entryName] = entry;\n }\n temporary.clear();\n makeTemporaryFolders();\n }\n\n function readMainHeader(/*Boolean*/ readNow) {\n var i = inBuffer.length - Utils.Constants.ENDHDR, // END header size\n max = Math.max(0, i - 0xffff), // 0xFFFF is the max zip file comment length\n n = max,\n endStart = inBuffer.length,\n endOffset = -1, // Start offset of the END header\n commentEnd = 0;\n\n // option to search header form entire file\n const trailingSpace = typeof opts.trailingSpace === \"boolean\" ? opts.trailingSpace : false;\n if (trailingSpace) max = 0;\n\n for (i; i >= n; i--) {\n if (inBuffer[i] !== 0x50) continue; // quick check that the byte is 'P'\n if (inBuffer.readUInt32LE(i) === Utils.Constants.ENDSIG) {\n // \"PK\\005\\006\"\n endOffset = i;\n commentEnd = i;\n endStart = i + Utils.Constants.ENDHDR;\n // We already found a regular signature, let's look just a bit further to check if there's any zip64 signature\n n = i - Utils.Constants.END64HDR;\n continue;\n }\n\n if (inBuffer.readUInt32LE(i) === Utils.Constants.END64SIG) {\n // Found a zip64 signature, let's continue reading the whole zip64 record\n n = max;\n continue;\n }\n\n if (inBuffer.readUInt32LE(i) === Utils.Constants.ZIP64SIG) {\n // Found the zip64 record, let's determine it's size\n endOffset = i;\n endStart = i + Utils.readBigUInt64LE(inBuffer, i + Utils.Constants.ZIP64SIZE) + Utils.Constants.ZIP64LEAD;\n break;\n }\n }\n\n if (endOffset == -1) throw Utils.Errors.INVALID_FORMAT();\n\n mainHeader.loadFromBinary(inBuffer.slice(endOffset, endStart));\n if (mainHeader.commentLength) {\n _comment = inBuffer.slice(commentEnd + Utils.Constants.ENDHDR);\n }\n if (readNow) readEntries();\n }\n\n function sortEntries() {\n if (entryList.length > 1 && !noSort) {\n entryList.sort((a, b) => a.entryName.toLowerCase().localeCompare(b.entryName.toLowerCase()));\n }\n }\n\n return {\n /**\n * Returns an array of ZipEntry objects existent in the current opened archive\n * @return Array\n */\n get entries() {\n if (!loadedEntries) {\n readEntries();\n }\n return entryList.filter((e) => !temporary.has(e));\n },\n\n /**\n * Archive comment\n * @return {String}\n */\n get comment() {\n return decoder.decode(_comment);\n },\n set comment(val) {\n _comment = Utils.toBuffer(val, decoder.encode);\n mainHeader.commentLength = _comment.length;\n },\n\n getEntryCount: function () {\n if (!loadedEntries) {\n return mainHeader.diskEntries;\n }\n\n return entryList.length;\n },\n\n forEach: function (callback) {\n this.entries.forEach(callback);\n },\n\n /**\n * Returns a reference to the entry with the given name or null if entry is inexistent\n *\n * @param entryName\n * @return ZipEntry\n */\n getEntry: function (/*String*/ entryName) {\n if (!loadedEntries) {\n readEntries();\n }\n return entryTable[entryName] || null;\n },\n\n /**\n * Adds the given entry to the entry list\n *\n * @param entry\n */\n setEntry: function (/*ZipEntry*/ entry) {\n if (!loadedEntries) {\n readEntries();\n }\n entryList.push(entry);\n entryTable[entry.entryName] = entry;\n mainHeader.totalEntries = entryList.length;\n },\n\n /**\n * Removes the file with the given name from the entry list.\n *\n * If the entry is a directory, then all nested files and directories will be removed\n * @param entryName\n * @returns {void}\n */\n deleteFile: function (/*String*/ entryName, withsubfolders = true) {\n if (!loadedEntries) {\n readEntries();\n }\n const entry = entryTable[entryName];\n const list = this.getEntryChildren(entry, withsubfolders).map((child) => child.entryName);\n\n list.forEach(this.deleteEntry);\n },\n\n /**\n * Removes the entry with the given name from the entry list.\n *\n * @param {string} entryName\n * @returns {void}\n */\n deleteEntry: function (/*String*/ entryName) {\n if (!loadedEntries) {\n readEntries();\n }\n const entry = entryTable[entryName];\n const index = entryList.indexOf(entry);\n if (index >= 0) {\n entryList.splice(index, 1);\n delete entryTable[entryName];\n mainHeader.totalEntries = entryList.length;\n }\n },\n\n /**\n * Iterates and returns all nested files and directories of the given entry\n *\n * @param entry\n * @return Array\n */\n getEntryChildren: function (/*ZipEntry*/ entry, subfolders = true) {\n if (!loadedEntries) {\n readEntries();\n }\n if (typeof entry === \"object\") {\n if (entry.isDirectory && subfolders) {\n const list = [];\n const name = entry.entryName;\n\n for (const zipEntry of entryList) {\n if (zipEntry.entryName.startsWith(name)) {\n list.push(zipEntry);\n }\n }\n return list;\n } else {\n return [entry];\n }\n }\n return [];\n },\n\n /**\n * How many child elements entry has\n *\n * @param {ZipEntry} entry\n * @return {integer}\n */\n getChildCount: function (entry) {\n if (entry && entry.isDirectory) {\n const list = this.getEntryChildren(entry);\n return list.includes(entry) ? list.length - 1 : list.length;\n }\n return 0;\n },\n\n /**\n * Returns the zip file\n *\n * @return Buffer\n */\n compressToBuffer: function () {\n if (!loadedEntries) {\n readEntries();\n }\n sortEntries();\n\n const dataBlock = [];\n const headerBlocks = [];\n let totalSize = 0;\n let dindex = 0;\n\n mainHeader.size = 0;\n mainHeader.offset = 0;\n let totalEntries = 0;\n\n for (const entry of this.entries) {\n // compress data and set local and entry header accordingly. Reason why is called first\n const compressedData = entry.getCompressedData();\n entry.header.offset = dindex;\n\n // 1. construct local header\n const localHeader = entry.packLocalHeader();\n\n // 2. offsets\n const dataLength = localHeader.length + compressedData.length;\n dindex += dataLength;\n\n // 3. store values in sequence\n dataBlock.push(localHeader);\n dataBlock.push(compressedData);\n\n // 4. construct central header\n const centralHeader = entry.packCentralHeader();\n headerBlocks.push(centralHeader);\n // 5. update main header\n mainHeader.size += centralHeader.length;\n totalSize += dataLength + centralHeader.length;\n totalEntries++;\n }\n\n totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length\n // point to end of data and beginning of central directory first record\n mainHeader.offset = dindex;\n mainHeader.totalEntries = totalEntries;\n\n dindex = 0;\n const outBuffer = Buffer.alloc(totalSize);\n // write data blocks\n for (const content of dataBlock) {\n content.copy(outBuffer, dindex);\n dindex += content.length;\n }\n\n // write central directory entries\n for (const content of headerBlocks) {\n content.copy(outBuffer, dindex);\n dindex += content.length;\n }\n\n // write main header\n const mh = mainHeader.toBinary();\n if (_comment) {\n _comment.copy(mh, Utils.Constants.ENDHDR); // add zip file comment\n }\n mh.copy(outBuffer, dindex);\n\n // Since we update entry and main header offsets,\n // they are no longer valid and we have to reset content\n // (Issue 64)\n\n inBuffer = outBuffer;\n loadedEntries = false;\n\n return outBuffer;\n },\n\n toAsyncBuffer: function (/*Function*/ onSuccess, /*Function*/ onFail, /*Function*/ onItemStart, /*Function*/ onItemEnd) {\n try {\n if (!loadedEntries) {\n readEntries();\n }\n sortEntries();\n\n const dataBlock = [];\n const centralHeaders = [];\n let totalSize = 0;\n let dindex = 0;\n let totalEntries = 0;\n\n mainHeader.size = 0;\n mainHeader.offset = 0;\n\n const compress2Buffer = function (entryLists) {\n if (entryLists.length > 0) {\n const entry = entryLists.shift();\n const name = entry.entryName + entry.extra.toString();\n if (onItemStart) onItemStart(name);\n entry.getCompressedDataAsync(function (compressedData) {\n if (onItemEnd) onItemEnd(name);\n entry.header.offset = dindex;\n\n // 1. construct local header\n const localHeader = entry.packLocalHeader();\n\n // 2. offsets\n const dataLength = localHeader.length + compressedData.length;\n dindex += dataLength;\n\n // 3. store values in sequence\n dataBlock.push(localHeader);\n dataBlock.push(compressedData);\n\n // central header\n const centalHeader = entry.packCentralHeader();\n centralHeaders.push(centalHeader);\n mainHeader.size += centalHeader.length;\n totalSize += dataLength + centalHeader.length;\n totalEntries++;\n\n compress2Buffer(entryLists);\n });\n } else {\n totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length\n // point to end of data and beginning of central directory first record\n mainHeader.offset = dindex;\n mainHeader.totalEntries = totalEntries;\n\n dindex = 0;\n const outBuffer = Buffer.alloc(totalSize);\n dataBlock.forEach(function (content) {\n content.copy(outBuffer, dindex); // write data blocks\n dindex += content.length;\n });\n centralHeaders.forEach(function (content) {\n content.copy(outBuffer, dindex); // write central directory entries\n dindex += content.length;\n });\n\n const mh = mainHeader.toBinary();\n if (_comment) {\n _comment.copy(mh, Utils.Constants.ENDHDR); // add zip file comment\n }\n\n mh.copy(outBuffer, dindex); // write main header\n\n // Since we update entry and main header offsets, they are no\n // longer valid and we have to reset content using our new buffer\n // (Issue 64)\n\n inBuffer = outBuffer;\n loadedEntries = false;\n\n onSuccess(outBuffer);\n }\n };\n\n compress2Buffer(Array.from(this.entries));\n } catch (e) {\n onFail(e);\n }\n }\n };\n};\n"}, {"path": "headers/entryHeader.js", "content": "var Utils = require(\"../util\"),\n Constants = Utils.Constants;\n\n/* The central directory file header */\nmodule.exports = function () {\n var _verMade = 20, // v2.0\n _version = 10, // v1.0\n _flags = 0,\n _method = 0,\n _time = 0,\n _crc = 0,\n _compressedSize = 0,\n _size = 0,\n _fnameLen = 0,\n _extraLen = 0,\n _comLen = 0,\n _diskStart = 0,\n _inattr = 0,\n _attr = 0,\n _offset = 0;\n\n _verMade |= Utils.isWin ? 0x0a00 : 0x0300;\n\n // Set EFS flag since filename and comment fields are all by default encoded using UTF-8.\n // Without it file names may be corrupted for other apps when file names use unicode chars\n _flags |= Constants.FLG_EFS;\n\n const _localHeader = {\n extraLen: 0\n };\n\n // casting\n const uint32 = (val) => Math.max(0, val) >>> 0;\n const uint16 = (val) => Math.max(0, val) & 0xffff;\n const uint8 = (val) => Math.max(0, val) & 0xff;\n\n _time = Utils.fromDate2DOS(new Date());\n\n return {\n get made() {\n return _verMade;\n },\n set made(val) {\n _verMade = val;\n },\n\n get version() {\n return _version;\n },\n set version(val) {\n _version = val;\n },\n\n get flags() {\n return _flags;\n },\n set flags(val) {\n _flags = val;\n },\n\n get flags_efs() {\n return (_flags & Constants.FLG_EFS) > 0;\n },\n set flags_efs(val) {\n if (val) {\n _flags |= Constants.FLG_EFS;\n } else {\n _flags &= ~Constants.FLG_EFS;\n }\n },\n\n get flags_desc() {\n return (_flags & Constants.FLG_DESC) > 0;\n },\n set flags_desc(val) {\n if (val) {\n _flags |= Constants.FLG_DESC;\n } else {\n _flags &= ~Constants.FLG_DESC;\n }\n },\n\n get method() {\n return _method;\n },\n set method(val) {\n switch (val) {\n case Constants.STORED:\n this.version = 10;\n case Constants.DEFLATED:\n default:\n this.version = 20;\n }\n _method = val;\n },\n\n get time() {\n return Utils.fromDOS2Date(this.timeval);\n },\n set time(val) {\n val = new Date(val);\n this.timeval = Utils.fromDate2DOS(val);\n },\n\n get timeval() {\n return _time;\n },\n set timeval(val) {\n _time = uint32(val);\n },\n\n get timeHighByte() {\n return uint8(_time >>> 8);\n },\n get crc() {\n return _crc;\n },\n set crc(val) {\n _crc = uint32(val);\n },\n\n get compressedSize() {\n return _compressedSize;\n },\n set compressedSize(val) {\n _compressedSize = uint32(val);\n },\n\n get size() {\n return _size;\n },\n set size(val) {\n _size = uint32(val);\n },\n\n get fileNameLength() {\n return _fnameLen;\n },\n set fileNameLength(val) {\n _fnameLen = val;\n },\n\n get extraLength() {\n return _extraLen;\n },\n set extraLength(val) {\n _extraLen = val;\n },\n\n get extraLocalLength() {\n return _localHeader.extraLen;\n },\n set extraLocalLength(val) {\n _localHeader.extraLen = val;\n },\n\n get commentLength() {\n return _comLen;\n },\n set commentLength(val) {\n _comLen = val;\n },\n\n get diskNumStart() {\n return _diskStart;\n },\n set diskNumStart(val) {\n _diskStart = uint32(val);\n },\n\n get inAttr() {\n return _inattr;\n },\n set inAttr(val) {\n _inattr = uint32(val);\n },\n\n get attr() {\n return _attr;\n },\n set attr(val) {\n _attr = uint32(val);\n },\n\n // get Unix file permissions\n get fileAttr() {\n return (_attr || 0) >> 16 & 0xfff;\n },\n\n get offset() {\n return _offset;\n },\n set offset(val) {\n _offset = uint32(val);\n },\n\n get encrypted() {\n return (_flags & Constants.FLG_ENC) === Constants.FLG_ENC;\n },\n\n get centralHeaderSize() {\n return Constants.CENHDR + _fnameLen + _extraLen + _comLen;\n },\n\n get realDataOffset() {\n return _offset + Constants.LOCHDR + _localHeader.fnameLen + _localHeader.extraLen;\n },\n\n get localHeader() {\n return _localHeader;\n },\n\n loadLocalHeaderFromBinary: function (/*Buffer*/ input) {\n var data = input.slice(_offset, _offset + Constants.LOCHDR);\n // 30 bytes and should start with \"PK\\003\\004\"\n if (data.readUInt32LE(0) !== Constants.LOCSIG) {\n throw Utils.Errors.INVALID_LOC();\n }\n\n // version needed to extract\n _localHeader.version = data.readUInt16LE(Constants.LOCVER);\n // general purpose bit flag\n _localHeader.flags = data.readUInt16LE(Constants.LOCFLG);\n // desc flag\n _localHeader.flags_desc = (_localHeader.flags & Constants.FLG_DESC) > 0;\n // compression method\n _localHeader.method = data.readUInt16LE(Constants.LOCHOW);\n // modification time (2 bytes time, 2 bytes date)\n _localHeader.time = data.readUInt32LE(Constants.LOCTIM);\n // uncompressed file crc-32 valu\n _localHeader.crc = data.readUInt32LE(Constants.LOCCRC);\n // compressed size\n _localHeader.compressedSize = data.readUInt32LE(Constants.LOCSIZ);\n // uncompressed size\n _localHeader.size = data.readUInt32LE(Constants.LOCLEN);\n // filename length\n _localHeader.fnameLen = data.readUInt16LE(Constants.LOCNAM);\n // extra field length\n _localHeader.extraLen = data.readUInt16LE(Constants.LOCEXT);\n\n // read extra data\n const extraStart = _offset + Constants.LOCHDR + _localHeader.fnameLen;\n const extraEnd = extraStart + _localHeader.extraLen;\n return input.slice(extraStart, extraEnd);\n },\n\n loadFromBinary: function (/*Buffer*/ data) {\n // data should be 46 bytes and start with \"PK 01 02\"\n if (data.length !== Constants.CENHDR || data.readUInt32LE(0) !== Constants.CENSIG) {\n throw Utils.Errors.INVALID_CEN();\n }\n // version made by\n _verMade = data.readUInt16LE(Constants.CENVEM);\n // version needed to extract\n _version = data.readUInt16LE(Constants.CENVER);\n // encrypt, decrypt flags\n _flags = data.readUInt16LE(Constants.CENFLG);\n // compression method\n _method = data.readUInt16LE(Constants.CENHOW);\n // modification time (2 bytes time, 2 bytes date)\n _time = data.readUInt32LE(Constants.CENTIM);\n // uncompressed file crc-32 value\n _crc = data.readUInt32LE(Constants.CENCRC);\n // compressed size\n _compressedSize = data.readUInt32LE(Constants.CENSIZ);\n // uncompressed size\n _size = data.readUInt32LE(Constants.CENLEN);\n // filename length\n _fnameLen = data.readUInt16LE(Constants.CENNAM);\n // extra field length\n _extraLen = data.readUInt16LE(Constants.CENEXT);\n // file comment length\n _comLen = data.readUInt16LE(Constants.CENCOM);\n // volume number start\n _diskStart = data.readUInt16LE(Constants.CENDSK);\n // internal file attributes\n _inattr = data.readUInt16LE(Constants.CENATT);\n // external file attributes\n _attr = data.readUInt32LE(Constants.CENATX);\n // LOC header offset\n _offset = data.readUInt32LE(Constants.CENOFF);\n },\n\n localHeaderToBinary: function () {\n // LOC header size (30 bytes)\n var data = Buffer.alloc(Constants.LOCHDR);\n // \"PK\\003\\004\"\n data.writeUInt32LE(Constants.LOCSIG, 0);\n // version needed to extract\n data.writeUInt16LE(_version, Constants.LOCVER);\n // general purpose bit flag\n data.writeUInt16LE(_flags, Constants.LOCFLG);\n // compression method\n data.writeUInt16LE(_method, Constants.LOCHOW);\n // modification time (2 bytes time, 2 bytes date)\n data.writeUInt32LE(_time, Constants.LOCTIM);\n // uncompressed file crc-32 value\n data.writeUInt32LE(_crc, Constants.LOCCRC);\n // compressed size\n data.writeUInt32LE(_compressedSize, Constants.LOCSIZ);\n // uncompressed size\n data.writeUInt32LE(_size, Constants.LOCLEN);\n // filename length\n data.writeUInt16LE(_fnameLen, Constants.LOCNAM);\n // extra field length\n data.writeUInt16LE(_localHeader.extraLen, Constants.LOCEXT);\n return data;\n },\n\n centralHeaderToBinary: function () {\n // CEN header size (46 bytes)\n var data = Buffer.alloc(Constants.CENHDR + _fnameLen + _extraLen + _comLen);\n // \"PK\\001\\002\"\n data.writeUInt32LE(Constants.CENSIG, 0);\n // version made by\n data.writeUInt16LE(_verMade, Constants.CENVEM);\n // version needed to extract\n data.writeUInt16LE(_version, Constants.CENVER);\n // encrypt, decrypt flags\n data.writeUInt16LE(_flags, Constants.CENFLG);\n // compression method\n data.writeUInt16LE(_method, Constants.CENHOW);\n // modification time (2 bytes time, 2 bytes date)\n data.writeUInt32LE(_time, Constants.CENTIM);\n // uncompressed file crc-32 value\n data.writeUInt32LE(_crc, Constants.CENCRC);\n // compressed size\n data.writeUInt32LE(_compressedSize, Constants.CENSIZ);\n // uncompressed size\n data.writeUInt32LE(_size, Constants.CENLEN);\n // filename length\n data.writeUInt16LE(_fnameLen, Constants.CENNAM);\n // extra field length\n data.writeUInt16LE(_extraLen, Constants.CENEXT);\n // file comment length\n data.writeUInt16LE(_comLen, Constants.CENCOM);\n // volume number start\n data.writeUInt16LE(_diskStart, Constants.CENDSK);\n // internal file attributes\n data.writeUInt16LE(_inattr, Constants.CENATT);\n // external file attributes\n data.writeUInt32LE(_attr, Constants.CENATX);\n // LOC header offset\n data.writeUInt32LE(_offset, Constants.CENOFF);\n return data;\n },\n\n toJSON: function () {\n const bytes = function (nr) {\n return nr + \" bytes\";\n };\n\n return {\n made: _verMade,\n version: _version,\n flags: _flags,\n method: Utils.methodToString(_method),\n time: this.time,\n crc: \"0x\" + _crc.toString(16).toUpperCase(),\n compressedSize: bytes(_compressedSize),\n size: bytes(_size),\n fileNameLength: bytes(_fnameLen),\n extraLength: bytes(_extraLen),\n commentLength: bytes(_comLen),\n diskNumStart: _diskStart,\n inAttr: _inattr,\n attr: _attr,\n offset: _offset,\n centralHeaderSize: bytes(Constants.CENHDR + _fnameLen + _extraLen + _comLen)\n };\n },\n\n toString: function () {\n return JSON.stringify(this.toJSON(), null, \"\\t\");\n }\n };\n};\n"}, {"path": "headers/index.js", "content": "exports.EntryHeader = require(\"./entryHeader\");\nexports.MainHeader = require(\"./mainHeader\");\n"}, {"path": "headers/mainHeader.js", "content": "var Utils = require(\"../util\"),\n Constants = Utils.Constants;\n\n/* The entries in the end of central directory */\nmodule.exports = function () {\n var _volumeEntries = 0,\n _totalEntries = 0,\n _size = 0,\n _offset = 0,\n _commentLength = 0;\n\n return {\n get diskEntries() {\n return _volumeEntries;\n },\n set diskEntries(/*Number*/ val) {\n _volumeEntries = _totalEntries = val;\n },\n\n get totalEntries() {\n return _totalEntries;\n },\n set totalEntries(/*Number*/ val) {\n _totalEntries = _volumeEntries = val;\n },\n\n get size() {\n return _size;\n },\n set size(/*Number*/ val) {\n _size = val;\n },\n\n get offset() {\n return _offset;\n },\n set offset(/*Number*/ val) {\n _offset = val;\n },\n\n get commentLength() {\n return _commentLength;\n },\n set commentLength(/*Number*/ val) {\n _commentLength = val;\n },\n\n get mainHeaderSize() {\n return Constants.ENDHDR + _commentLength;\n },\n\n loadFromBinary: function (/*Buffer*/ data) {\n // data should be 22 bytes and start with \"PK 05 06\"\n // or be 56+ bytes and start with \"PK 06 06\" for Zip64\n if (\n (data.length !== Constants.ENDHDR || data.readUInt32LE(0) !== Constants.ENDSIG) &&\n (data.length < Constants.ZIP64HDR || data.readUInt32LE(0) !== Constants.ZIP64SIG)\n ) {\n throw Utils.Errors.INVALID_END();\n }\n\n if (data.readUInt32LE(0) === Constants.ENDSIG) {\n // number of entries on this volume\n _volumeEntries = data.readUInt16LE(Constants.ENDSUB);\n // total number of entries\n _totalEntries = data.readUInt16LE(Constants.ENDTOT);\n // central directory size in bytes\n _size = data.readUInt32LE(Constants.ENDSIZ);\n // offset of first CEN header\n _offset = data.readUInt32LE(Constants.ENDOFF);\n // zip file comment length\n _commentLength = data.readUInt16LE(Constants.ENDCOM);\n } else {\n // number of entries on this volume\n _volumeEntries = Utils.readBigUInt64LE(data, Constants.ZIP64SUB);\n // total number of entries\n _totalEntries = Utils.readBigUInt64LE(data, Constants.ZIP64TOT);\n // central directory size in bytes\n _size = Utils.readBigUInt64LE(data, Constants.ZIP64SIZE);\n // offset of first CEN header\n _offset = Utils.readBigUInt64LE(data, Constants.ZIP64OFF);\n\n _commentLength = 0;\n }\n },\n\n toBinary: function () {\n var b = Buffer.alloc(Constants.ENDHDR + _commentLength);\n // \"PK 05 06\" signature\n b.writeUInt32LE(Constants.ENDSIG, 0);\n b.writeUInt32LE(0, 4);\n // number of entries on this volume\n b.writeUInt16LE(_volumeEntries, Constants.ENDSUB);\n // total number of entries\n b.writeUInt16LE(_totalEntries, Constants.ENDTOT);\n // central directory size in bytes\n b.writeUInt32LE(_size, Constants.ENDSIZ);\n // offset of first CEN header\n b.writeUInt32LE(_offset, Constants.ENDOFF);\n // zip file comment length\n b.writeUInt16LE(_commentLength, Constants.ENDCOM);\n // fill comment memory with spaces so no garbage is left there\n b.fill(\" \", Constants.ENDHDR);\n\n return b;\n },\n\n toJSON: function () {\n // creates 0x0000 style output\n const offset = function (nr, len) {\n let offs = nr.toString(16).toUpperCase();\n while (offs.length < len) offs = \"0\" + offs;\n return \"0x\" + offs;\n };\n\n return {\n diskEntries: _volumeEntries,\n totalEntries: _totalEntries,\n size: _size + \" bytes\",\n offset: offset(_offset, 4),\n commentLength: _commentLength\n };\n },\n\n toString: function () {\n return JSON.stringify(this.toJSON(), null, \"\\t\");\n }\n };\n};\n// Misspelled\n"}, {"path": "methods/deflater.js", "content": "module.exports = function (/*Buffer*/ inbuf) {\n var zlib = require(\"zlib\");\n\n var opts = { chunkSize: (parseInt(inbuf.length / 1024) + 1) * 1024 };\n\n return {\n deflate: function () {\n return zlib.deflateRawSync(inbuf, opts);\n },\n\n deflateAsync: function (/*Function*/ callback) {\n var tmp = zlib.createDeflateRaw(opts),\n parts = [],\n total = 0;\n tmp.on(\"data\", function (data) {\n parts.push(data);\n total += data.length;\n });\n tmp.on(\"end\", function () {\n var buf = Buffer.alloc(total),\n written = 0;\n buf.fill(0);\n for (var i = 0; i < parts.length; i++) {\n var part = parts[i];\n part.copy(buf, written);\n written += part.length;\n }\n callback && callback(buf);\n });\n tmp.end(inbuf);\n }\n };\n};\n"}, {"path": "methods/index.js", "content": "exports.Deflater = require(\"./deflater\");\nexports.Inflater = require(\"./inflater\");\nexports.ZipCrypto = require(\"./zipcrypto\");\n"}, {"path": "methods/inflater.js", "content": "const version = +(process.versions ? process.versions.node : \"\").split(\".\")[0] || 0;\n\nmodule.exports = function (/*Buffer*/ inbuf, /*number*/ expectedLength) {\n var zlib = require(\"zlib\");\n const option = version >= 15 && expectedLength > 0 ? { maxOutputLength: expectedLength } : {};\n\n return {\n inflate: function () {\n return zlib.inflateRawSync(inbuf, option);\n },\n\n inflateAsync: function (/*Function*/ callback) {\n var tmp = zlib.createInflateRaw(option),\n parts = [],\n total = 0;\n tmp.on(\"data\", function (data) {\n parts.push(data);\n total += data.length;\n });\n tmp.on(\"end\", function () {\n var buf = Buffer.alloc(total),\n written = 0;\n buf.fill(0);\n for (var i = 0; i < parts.length; i++) {\n var part = parts[i];\n part.copy(buf, written);\n written += part.length;\n }\n callback && callback(buf);\n });\n tmp.end(inbuf);\n }\n };\n};\n"}, {"path": "test/issue_130/issue_130.test.js", "content": "\"use strict\";\n\nconst assert = require(\"assert\");\nconst fs = require(\"fs\");\nconst pth = require(\"path\");\nconst Zip = require(\"../../adm-zip\");\nconst rimraf = require(\"rimraf\");\n\ndescribe(\"ADM-ZIP - Issues\", () => {\n const destination = pth.resolve(\"./test/xxx\");\n const unzipped = pth.join(destination, \"unzipped\");\n\n // clean up folder content\n afterEach((done) => rimraf(destination, done));\n\n it(\"Issue 130 - Created zip's under Windows are corrupt\", () => {\n // init the final zip file\n const writeZip = new Zip();\n\n // file in root folder\n writeZip.addFile(\"root_file.txt\", \"root\");\n\n // add folder\n writeZip.addFile(\"sub/\", Buffer.alloc(0));\n\n // file in sub folder\n writeZip.addFile(\"sub/sub_file.txt\", \"sub\");\n\n // files from local folder\n writeZip.addLocalFolder(pth.resolve(\"./test/issue_130\", \"nested\"), \"nested\");\n\n // write to disk\n writeZip.writeZip(pth.join(destination, \"test.zip\"));\n\n // read zip from disk\n const readZip = new Zip(pth.join(destination, \"test.zip\"));\n\n // unpack everything\n readZip.extractAllTo(unzipped, true);\n\n // assert the files\n const fileRoot = fs.readFileSync(pth.join(unzipped, \"root_file.txt\"), \"utf8\");\n assert(fileRoot === \"root\", \"root file not correct\");\n\n const fileSub = fs.readFileSync(pth.join(unzipped, \"sub/sub_file.txt\"), \"utf8\");\n assert(fileSub === \"sub\", \"sub file not correct\");\n\n const fileNested = fs.readFileSync(pth.join(unzipped, \"nested/nested_file.txt\"), \"utf8\");\n assert(fileNested === \"nested\", \"nested file not correct\");\n\n const fileDeeper = fs.readFileSync(pth.join(unzipped, \"nested/deeper/deeper_file.txt\"), \"utf8\");\n assert(fileDeeper === \"deeper\", \"deeper file not correct\");\n });\n});\n"}, {"path": "util/decoder.js", "content": "module.exports = {\n efs: true,\n encode: (data) => Buffer.from(data, \"utf8\"),\n decode: (data) => data.toString(\"utf8\")\n};\n"}], "context_lines": 1499, "buggy_files": ["adm-zip.js"], "test_files": [{"path": "test/methods/methods.test.js", "content": "const { expect } = require(\"chai\");\n//const Attr = require(\"../util\").FileAttr;\nconst Zip = require(\"../../adm-zip\");\nconst pth = require(\"path\");\nconst fs = require(\"fs\");\nconst rimraf = require(\"rimraf\");\nconst Utils = require(\"../../util/utils\");\n\ndescribe(\"adm-zip.js - methods handling local files\", () => {\n const wrapList = (c) => pth.normalize(pth.join(destination, c));\n const destination = \"./test/xxx\";\n const testFileFolderList = [\n { name: \"subfolder1/subfolder2/zipEntry1.txt\", content: \"zipEntry1\" },\n { name: \"subfolder1/subfolder2/subfolder3/zipEntry2.txt\", content: \"zipEntry2\" },\n { name: \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\", content: \"zipEntry3\" },\n { name: \"subfolder1/subfolder2/subfolder3/subfolder4/\" }\n ];\n const testFileFileList = [\n { name: \"folder/zipEntry1.txt\", content: \"zipEntry1\" },\n { name: \"folder/zipEntry2.txt\", content: \"zipEntry2\" },\n { name: \"folder/zipEntry3.txt\", content: \"zipEntry3\" },\n { name: \"folder/zipEntry4.txt\", content: \"zipEntry4\" },\n { name: \"folder/subfolder1/\" },\n { name: \"folder/subfolder2/\" },\n { name: \"folder/subfolder3/\" }\n ];\n\n // clean up folder content\n afterEach((done) => rimraf(destination, done));\n\n describe(\".deleteFile()\", () => {\n const ultrazip = [\n \"./attributes_test/asd/New Text Document.txt\",\n \"./attributes_test/blank file.txt\",\n \"./attributes_test/New folder/hidden.txt\",\n \"./attributes_test/New folder/hidden_readonly.txt\",\n \"./attributes_test/New folder/readonly.txt\",\n \"./utes_test/New folder/somefile.txt\"\n ].map(wrapList);\n\n // Issue 523 - deletes additional files\n it(\"zip.deleteFile() - delete folder with subfolders\", () => {\n const content = \"test\";\n const comment = \"comment\";\n const zip1 = new Zip({ noSort: true });\n zip1.addFile(\"test/\");\n zip1.addFile(\"test/path1/\");\n zip1.addFile(\"test/path1/file1.txt\", content, comment);\n zip1.addFile(\"test/path1/folder1/\");\n zip1.addFile(\"test/path1/folder1/file2.txt\", content, comment);\n zip1.addFile(\"test/path2/\");\n zip1.addFile(\"test/path2/file1.txt\", content, comment);\n zip1.addFile(\"test/path2/folder1/\");\n zip1.addFile(\"test/path2/folder1/file2.txt\", content, comment);\n\n zip1.deleteFile(\"test/path1/\");\n\n const zipEntries = zip1.getEntries().map((child) => child.entryName);\n\n expect(zipEntries).to.deep.equal([\"test/\", \"test/path2/\", \"test/path2/file1.txt\", \"test/path2/folder1/\", \"test/path2/folder1/file2.txt\"]);\n });\n\n it(\"zip.deleteFile() - delete folder\", () => {\n const content = \"test\";\n const comment = \"comment\";\n const zip1 = new Zip({ noSort: true });\n zip1.addFile(\"test/\");\n zip1.addFile(\"test/path1/\");\n zip1.addFile(\"test/path1/file1.txt\", content, comment);\n zip1.addFile(\"test/path1/folder1/\");\n zip1.addFile(\"test/path1/folder1/file2.txt\", content, comment);\n zip1.addFile(\"test/path2/\");\n zip1.addFile(\"test/path2/file1.txt\", content, comment);\n zip1.addFile(\"test/path2/folder1/\");\n zip1.addFile(\"test/path2/folder1/file2.txt\", content, comment);\n\n zip1.deleteFile(\"test/path1/\", false);\n\n const zipEntries = zip1.getEntries().map((child) => child.entryName);\n\n expect(zipEntries).to.deep.equal([\n \"test/\",\n \"test/path1/file1.txt\",\n \"test/path1/folder1/\",\n \"test/path1/folder1/file2.txt\",\n \"test/path2/\",\n \"test/path2/file1.txt\",\n \"test/path2/folder1/\",\n \"test/path2/folder1/file2.txt\"\n ]);\n });\n\n it(\"zip.deleteFile() - delete files\", () => {\n const content = \"test\";\n const comment = \"comment\";\n const zip1 = new Zip({ noSort: true });\n zip1.addFile(\"test/\");\n zip1.addFile(\"test/path1/\");\n zip1.addFile(\"test/path1/file1.txt\", content, comment);\n zip1.addFile(\"test/path1/folder1/\");\n zip1.addFile(\"test/path1/folder1/file2.txt\", content, comment);\n\n zip1.deleteFile(\"test/path1/file1.txt\", false);\n zip1.deleteFile(\"test/path1/folder1/file2.txt\", false);\n\n const zipEntries = zip1.getEntries().map((child) => child.entryName);\n\n expect(zipEntries).to.deep.equal([\"test/\", \"test/path1/\", \"test/path1/folder1/\"]);\n });\n });\n\n describe(\".extractAllTo() - sync\", () => {\n const ultrazip = [\n \"./attributes_test/asd/New Text Document.txt\",\n \"./attributes_test/blank file.txt\",\n \"./attributes_test/New folder/hidden.txt\",\n \"./attributes_test/New folder/hidden_readonly.txt\",\n \"./attributes_test/New folder/readonly.txt\",\n \"./utes_test/New folder/somefile.txt\"\n ].map(wrapList);\n\n it(\"zip.extractAllTo(destination)\", () => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n zip.extractAllTo(destination);\n const files = walk(destination);\n\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n });\n\n it(\"zip.extractAllTo(destination) - streamed file\", () => {\n const zip = new Zip(\"./test/assets/stream-nozip64.zip\");\n zip.extractAllTo(destination);\n const files = walk(destination);\n\n expect(files.sort()).to.deep.equal([pth.normalize(\"./test/xxx/lorem.txt\")]);\n });\n });\n\n describe(\".extractAllToAsync - sync\", () => {\n const ultrazip = [\n \"./attributes_test/asd/New Text Document.txt\",\n \"./attributes_test/blank file.txt\",\n \"./attributes_test/New folder/hidden.txt\",\n \"./attributes_test/New folder/hidden_readonly.txt\",\n \"./attributes_test/New folder/readonly.txt\",\n \"./utes_test/New folder/somefile.txt\"\n ].map(wrapList);\n\n it(\"zip.extractAllToAsync(destination)\", (done) => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n zip.extractAllToAsync(destination, (error) => {\n const files = walk(destination);\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n done();\n });\n });\n\n it(\"zip.extractAllToAsync(destination) [Promise]\", function () {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n // note the return\n return zip.extractAllToAsync(destination).then(function (data) {\n const files = walk(destination);\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n }); // no catch, it'll figure it out since the promise is rejected\n });\n\n it(\"zip.extractAllToAsync(destination, false, false, callback)\", (done) => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n zip.extractAllToAsync(destination, false, false, (error) => {\n const files = walk(destination);\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n done();\n });\n });\n\n it(\"zip.extractAllToAsync(destination, false, false) [Promise]\", function () {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n // note the return\n return zip.extractAllToAsync(destination, false, false).then(function (data) {\n const files = walk(destination);\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n }); // no catch, it'll figure it out since the promise is rejected\n });\n\n it(\"zip.extractAllToAsync(destination, false, callback)\", (done) => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n zip.extractAllToAsync(destination, false, (error) => {\n const files = walk(destination);\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n done();\n });\n });\n\n it(\"zip.extractAllToAsync(destination, false) [Promise]\", () => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n // note the return\n return zip.extractAllToAsync(destination, false).then(function (data) {\n const files = walk(destination);\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n }); // no catch, it'll figure it out since the promise is rejected\n });\n });\n\n describe(\".extractEntryTo() - sync\", () => {\n // each entry one by one\n it(\"zip.extractEntryTo(entry, destination, false, true)\", () => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n var zipEntries = zip.getEntries();\n zipEntries.forEach((e) => zip.extractEntryTo(e, destination, false, true));\n\n const files = walk(destination);\n const ultrazip = [\"blank file.txt\", \"hidden.txt\", \"hidden_readonly.txt\", \"New Text Document.txt\", \"readonly.txt\", \"somefile.txt\"].map(wrapList);\n\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n });\n\n // each entry one by one\n it(\"zip.extractEntryTo(entry, destination, true, true)\", () => {\n const zip = new Zip(\"./test/assets/ultra.zip\");\n var zipEntries = zip.getEntries();\n zipEntries.forEach((e) => zip.extractEntryTo(e, destination, true, true));\n\n const files = walk(destination);\n const ultrazip = [\n \"./attributes_test/asd/New Text Document.txt\",\n \"./attributes_test/blank file.txt\",\n \"./attributes_test/New folder/hidden.txt\",\n \"./attributes_test/New folder/hidden_readonly.txt\",\n \"./attributes_test/New folder/readonly.txt\",\n \"./utes_test/New folder/somefile.txt\"\n ].map(wrapList);\n\n expect(files.sort()).to.deep.equal(ultrazip.sort());\n });\n\n it(\"zip.extractEntryTo(entry, destination, false, true) - [ extract folder from file where folders exists ]\", () => {\n const zip = new Zip(\"./test/assets/maximum.zip\");\n\n zip.extractEntryTo(\"./attributes_test/New folder/\", destination, false, true);\n\n const files = walk(destination);\n const maximumzip = [\"hidden.txt\", \"hidden_readonly.txt\", \"readonly.txt\", \"somefile.txt\"].map(wrapList);\n\n expect(files.sort()).to.deep.equal(maximumzip.sort());\n });\n\n it(\"zip.extractEntryTo(entry, destination, false, true) - [ extract folder from file where folders does not exists ]\", () => {\n const zip = new Zip(\"./test/assets/maximum3.zip\");\n\n zip.extractEntryTo(\"./attributes_test/New folder/\", destination, false, true);\n\n const files = walk(destination);\n const maximumzip = [\"hidden.txt\", \"hidden_readonly.txt\", \"readonly.txt\", \"somefile.txt\"].map(wrapList);\n\n expect(files.sort()).to.deep.equal(maximumzip.sort());\n });\n\n it(\"zip.extractEntryTo(entry, destination, true, true) - [ extract folder from file where folders exists ]\", () => {\n const zip = new Zip(\"./test/assets/maximum.zip\");\n\n zip.extractEntryTo(\"./attributes_test/New folder/\", destination, true, true);\n\n const files = walk(destination);\n const maximumzip = [\n \"./attributes_test/New folder/hidden.txt\",\n \"./attributes_test/New folder/hidden_readonly.txt\",\n \"./attributes_test/New folder/readonly.txt\",\n \"./attributes_test/New folder/somefile.txt\"\n ].map(wrapList);\n expect(files.sort()).to.deep.equal(maximumzip.sort());\n });\n\n it(\"zip.extractEntryTo(entry, destination, true, true) - [ extract folder from file where folders does not exists ]\", () => {\n const zip = new Zip(\"./test/assets/maximum3.zip\");\n\n zip.extractEntryTo(\"./attributes_test/New folder/\", destination, true, true);\n\n const files = walk(destination);\n const maximumzip = [\n \"./attributes_test/New folder/hidden.txt\",\n \"./attributes_test/New folder/hidden_readonly.txt\",\n \"./attributes_test/New folder/readonly.txt\",\n \"./attributes_test/New folder/somefile.txt\"\n ].map(wrapList);\n expect(files.sort()).to.deep.equal(maximumzip.sort());\n });\n });\n\n describe(\".addLocalFolder() - sync\", () => {\n beforeEach(() => {\n genFiles(testFileFolderList, destination);\n });\n\n it(\"zip.addLocalFolder(destination)\", () => {\n const zip = new Zip({ noSort: true });\n zip.addLocalFolder(destination);\n zip.toBuffer();\n\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\",\n \"subfolder1/subfolder2/zipEntry1.txt\"\n ];\n\n expect(zip1Entries).to.deep.equal(expected);\n });\n\n it(\"zip.addLocalFolder(destination, zipPath)\", () => {\n const zip = new Zip();\n zip.addLocalFolder(destination, \"parent\");\n zip.toBuffer();\n\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"parent/subfolder1/\",\n \"parent/subfolder1/subfolder2/\",\n \"parent/subfolder1/subfolder2/subfolder3/\",\n \"parent/subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry3.txt\",\n \"parent/subfolder1/subfolder2/zipEntry1.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n });\n\n it(\"zip.addLocalFolder(destination, '', filter)\", () => {\n const zip = new Zip();\n const filter = /zipEntry[23]\\.txt/;\n zip.addLocalFolder(destination, \"\", filter);\n zip.toBuffer();\n\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\"subfolder1/subfolder2/subfolder3/zipEntry2.txt\", \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\"].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n });\n\n it(\"zip.addLocalFolder(destination, '', filter)\", () => {\n const zip = new Zip();\n const filter = function (str) {\n return str.slice(-1) === pth.sep;\n };\n zip.addLocalFolder(destination, \"\", filter);\n zip.toBuffer();\n\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\"subfolder1/\", \"subfolder1/subfolder2/\", \"subfolder1/subfolder2/subfolder3/\", \"subfolder1/subfolder2/subfolder3/subfolder4/\"].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n });\n });\n\n describe(\".addLocalFileAsync() - async\", () => {\n beforeEach(() => {\n genFiles(testFileFileList, destination);\n });\n\n it(\"zip.addLocalFileAsync({ localPath, comment, zipPath }, callback)\", (done) => {\n const zip = new Zip();\n const zipPath = \"folder\";\n const fileComment = \"file Comment\";\n const list1 = testFileFileList.map((c) => c.name);\n list1.sort();\n zip.addZipComment(fileComment);\n\n setImmediate(\n list1.reverse().reduce(\n function (next, file) {\n return function (err, done) {\n if (err) next(err, false);\n\n const localPath = pth.resolve(destination, file);\n const comment = pth.basename(file);\n\n zip.addLocalFileAsync({ localPath, comment, zipPath }, function (err, done) {\n if (err) next(err, false);\n\n setImmediate(next, undefined, true);\n });\n };\n },\n function (err) {\n if (err) done(err);\n\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n const zip1Comment = zip.getEntries().map((e) => e.comment);\n\n const expected1 = list1;\n const expected2 = list1.map((n) => pth.basename(n));\n\n expect(zip1Entries.sort()).to.deep.equal(expected1.sort());\n expect(zip1Comment.sort()).to.deep.equal(expected2.sort());\n expect(zip.getZipComment()).to.equal(fileComment);\n\n done();\n }\n )\n );\n });\n });\n\n describe(\".addLocalFolderAsync2() - async\", () => {\n beforeEach(() => {\n genFiles(testFileFolderList, destination);\n });\n\n it(\"zip.addLocalFolderAsync2(destination, callback)\", (done) => {\n const zip = new Zip();\n zip.addLocalFolderAsync2(destination, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/zipEntry1.txt\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\"\n ];\n\n expect(zip1Entries).to.deep.equal(expected.sort());\n done();\n });\n });\n });\n\n it(\"zip.addLocalFolderAsync2({localPath}, callback)\", (done) => {\n const zip = new Zip();\n zip.addLocalFolderAsync2({ localPath: destination }, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\",\n \"subfolder1/subfolder2/zipEntry1.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n done();\n });\n });\n });\n\n it(\"zip.addLocalFolderAsync2({localPath, namefix}, callback)\", (done) => {\n const zip = new Zip();\n const namefix = (str) => str.toLowerCase();\n zip.addLocalFolderAsync2({ localPath: destination, namefix }, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipentry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipentry3.txt\",\n \"subfolder1/subfolder2/zipentry1.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n done();\n });\n });\n });\n\n it(\"zip.addLocalFolderAsync2({localPath, namefix}, callback)\", (done) => {\n const zip = new Zip();\n genFiles([{ name: \"subfolder1/\u00e6ble.txt\", content: \"apple\" }], destination);\n\n zip.addLocalFolderAsync2({ localPath: destination, namefix: \"latin1\" }, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/ble.txt\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\",\n \"subfolder1/subfolder2/zipEntry1.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n done();\n });\n });\n });\n\n it(\"zip.addLocalFolderAsync2({localPath, zipPath}, callback)\", (done) => {\n const zip = new Zip();\n zip.addLocalFolderAsync2({ localPath: destination, zipPath: \"parent\" }, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"parent/subfolder1/\",\n \"parent/subfolder1/subfolder2/\",\n \"parent/subfolder1/subfolder2/subfolder3/\",\n \"parent/subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry3.txt\",\n \"parent/subfolder1/subfolder2/zipEntry1.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n done();\n });\n });\n });\n\n it(\"zip.addLocalFolderAsync2({localPath, filter}, callback)\", (done) => {\n const zip = new Zip();\n const filter = /zipEntry[23]\\.txt/;\n zip.addLocalFolderAsync2({ localPath: destination, filter }, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\"subfolder1/subfolder2/subfolder3/zipEntry2.txt\", \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\"].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n done();\n });\n });\n });\n\n it(\"zip.addLocalFolderAsync2({localPath, filter}, callback)\", (done) => {\n const zip = new Zip();\n const filter = function (str) {\n return str.slice(-1) === pth.sep;\n };\n zip.addLocalFolderAsync2({ localPath: destination, filter }, (error) => {\n if (error) done(false);\n\n zip.toBuffer(function () {\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\"subfolder1/\", \"subfolder1/subfolder2/\", \"subfolder1/subfolder2/subfolder3/\", \"subfolder1/subfolder2/subfolder3/subfolder4/\"].sort();\n\n expect(zip1Entries).to.deep.equal(expected);\n done();\n });\n });\n });\n });\n\n describe(\".addLocalFolderPromise() - promise\", () => {\n beforeEach(() => {\n genFiles(testFileFolderList, destination);\n });\n\n it(\"zip.addLocalFolderPromise(destination)\", async function () {\n const zip = new Zip();\n const zip1 = await zip.addLocalFolderPromise(destination);\n\n zip1.toBuffer();\n const zip1Entries = zip1.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/zipEntry1.txt\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipEntry3.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected.sort());\n });\n\n it(\"zip.addLocalFolderPromise(destination, {namefix})\", async function () {\n const zip = new Zip();\n const namefix = (str) => str.toLowerCase();\n const zip1 = await zip.addLocalFolderPromise(destination, { namefix });\n\n zip1.toBuffer();\n const zip1Entries = zip1.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"subfolder1/\",\n \"subfolder1/subfolder2/\",\n \"subfolder1/subfolder2/subfolder3/\",\n \"subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"subfolder1/subfolder2/subfolder3/zipentry2.txt\",\n \"subfolder1/subfolder2/subfolder3/zipentry3.txt\",\n \"subfolder1/subfolder2/zipentry1.txt\"\n ].sort();\n\n expect(zip1Entries).to.deep.equal(expected.sort());\n });\n\n it(\"zip.addLocalFolderPromise(destination, {zipPath})\", async function () {\n const zip = new Zip();\n await zip.addLocalFolderPromise(destination, { zipPath: \"parent\" });\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"parent/subfolder1/\",\n \"parent/subfolder1/subfolder2/\",\n \"parent/subfolder1/subfolder2/subfolder3/\",\n \"parent/subfolder1/subfolder2/zipEntry1.txt\",\n \"parent/subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry3.txt\"\n ];\n\n expect(zip1Entries.sort()).to.deep.equal(expected.sort());\n });\n\n\n\n it(\"zip.addLocalFolderPromise(destination, {zipPath}) with absolute path\", async function () {\n const zip = new Zip();\n await zip.addLocalFolderPromise(pth.resolve(destination), { zipPath: \"parent\" });\n const zip1Entries = zip.getEntries().map((e) => e.entryName);\n\n const expected = [\n \"parent/subfolder1/\",\n \"parent/subfolder1/subfolder2/\",\n \"parent/subfolder1/subfolder2/subfolder3/\",\n \"parent/subfolder1/subfolder2/zipEntry1.txt\",\n \"parent/subfolder1/subfolder2/subfolder3/subfolder4/\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry2.txt\",\n \"parent/subfolder1/subfolder2/subfolder3/zipEntry3.txt\"\n ];\n\n expect(zip1Entries.sort()).to.deep.equal(expected.sort());\n });\n });\n});\n\nfunction walk(dir) {\n let results = [];\n const list = fs.readdirSync(dir);\n list.forEach(function (file) {\n file = dir + \"/\" + file;\n const stat = fs.statSync(file);\n if (stat && stat.isDirectory()) {\n /* Recurse into a subdirectory */\n results = results.concat(walk(file));\n } else {\n /* Is a file */\n results.push(pth.normalize(file));\n }\n });\n return results;\n}\n\nfunction genFiles(list, location) {\n const utils = new Utils({ fs });\n\n for (const el of list) {\n const path = pth.resolve(location, el.name);\n if (el.name.slice(-1) === \"/\") {\n utils.makeDir(path);\n } else {\n utils.makeDir(pth.dirname(path));\n fs.writeFileSync(path, el.content, \"utf8\");\n }\n }\n}\n"}], "eval": {"test_cmds": ["mkdir -p reports; npx mocha --reporter json > reports/mocha-results.json"], "print_cmds": [], "log_parser": "def parser(log: str) -> dict[str, str]:\n import json\n import re\n\n results = {}\n\n def add(name, status):\n if name:\n results[name] = status\n\n data = None\n # Try direct JSON parse\n try:\n data = json.loads(log)\n except Exception:\n pass\n\n # Fallback: regex extract JSON object\n if data is None:\n matches = re.findall(r\"\\{.*\\}\", log, flags=re.DOTALL)\n for chunk in reversed(matches):\n try:\n data = json.loads(chunk)\n if isinstance(data, dict):\n break\n except Exception:\n data = None\n\n if not isinstance(data, dict):\n return results\n\n tests = data.get(\"tests\") or []\n for test in tests:\n if not isinstance(test, dict):\n continue\n name = test.get(\"fullTitle\") or test.get(\"title\")\n state = (test.get(\"state\") or \"\").lower()\n pending_flag = bool(test.get(\"pending\") or test.get(\"isPending\"))\n err = test.get(\"err\") or {}\n\n if state in (\"failed\", \"fail\", \"error\"):\n status = \"fail\"\n elif state in (\"pending\", \"skipped\", \"skip\"):\n status = \"skip\"\n elif pending_flag:\n status = \"skip\"\n elif isinstance(err, dict) and err:\n if err.get(\"message\") or err.get(\"stack\") or err.get(\"name\") or err != {}:\n status = \"fail\"\n else:\n status = \"pass\"\n else:\n status = \"pass\"\n add(name, status)\n\n for test in data.get(\"passes\") or []:\n if isinstance(test, dict):\n add(test.get(\"fullTitle\") or test.get(\"title\"), \"pass\")\n for test in data.get(\"pending\") or []:\n if isinstance(test, dict):\n add(test.get(\"fullTitle\") or test.get(\"title\"), \"skip\")\n for test in data.get(\"failures\") or []:\n if isinstance(test, dict):\n add(test.get(\"fullTitle\") or test.get(\"title\"), \"fail\")\n\n return results", "rebuild_cmds": []}}
{"id": "patchbench-js-real-0014", "repo": "moment/luxon", "base_commit": "4cc03e5b71240ece26ba1424cabcf35b8a939c56", "status": "no_tests_parsed", "verify_status": null, "error": null, "timing": {"setup": 1.1, "pre_test_0": 19.2, "pre_test_1": 8.6, "post_test_0": 14.9, "post_test_1": 8.5, "total": 52.9}, "test_cmds": ["TZ=America/New_York NODE_ICU_DATA=\\\"$(pwd)/node_modules/full-icu\\\" npm test -- --json --outputFile=jest-results.json"], "rebuild_cmds": [], "print_cmds": [], "f2p_pre_ok": true, "pre_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 0}, "p2p_env_dropped_count": 1143, "f2p_post_ok": false, "p2p_post_ok": true, "post_detail": {"missing": 32, "wrong": [], "missing_ids": ["/testbed/test/interval/parse.test.js::Interval.fromISO defaults missing values in end to start Ordinal, end just time", "/testbed/test/interval/parse.test.js::Interval.fromISO defaults missing values in end to start Gregorian, end month and day", "/testbed/test/interval/parse.test.js::Interval.fromISO defaults missing values in end to start Ordinal, end with ordinal", "/testbed/test/interval/parse.test.js::Interval.fromISO defaults missing values in end to start Gregorian with start zone and zone in options", "/testbed/test/interval/parse.test.js::Interval.fromISO defaults missing values in end to start Gregorian with two zones"], "parsed_count": 0}, "raw_tail": " test(\"Ordinal, end weekNumber and weekday\", () => {\n\n at Object.toISO (test/interval/parse.test.js:317:20)\n\n \u25cf Interval.fromISO defaults missing values in end to start \u203a Ordinal, end weekNumber and weekday\n\n TypeError: Cannot read properties of null (reading 'toISO')\n\n 320 | test(\"Ordinal, end weekNumber and weekday\", () => {\n 321 | const i = Interval.fromISO(\"2025-132T09/W21-1T15:30\");\n > 322 | expect(i.start.toISO()).toBe(\"2025-05-12T09:00:00.000-04:00\");\n | ^\n 323 | expect(i.end.toISO()).toBe(\"2025-05-19T15:30:00.000-04:00\");\n 324 | });\n 325 | });\n\n at Object.toISO (test/interval/parse.test.js:322:20)\n\nFAIL test/interval/format.test.js\n \u25cf Interval#toLocaleString can override the start DateTime's output calendar\n\n expect(received).toBe(expected) // Object.is equality\n\n Expected: \"9/17/1698\u2009\u2013\u20092/3/1700 ERA1\"\n Received: \"9/17/1698\u2009\u2013\u20092/3/1700 AM\"\n\n 90 | interval.end\n 91 | ).toLocaleString({}, { outputCalendar: \"coptic\" })\n > 92 | ).toBe(\"9/17/1698\u2009\u2013\u20092/3/1700 ERA1\");\n | ^\n 93 | });\n 94 |\n 95 | test(\"Interval#toLocaleString shows things in the right IANA zone\", () => {\n\n at Object.toBe (test/interval/format.test.js:92:5)\n\n\nTest Suites: 4 failed, 54 passed, 58 total\nTests: 36 failed, 1157 passed, 1193 total\nSnapshots: 1 passed, 1 total\nTime: 12.22 s\nRan all test suites.\nTest results written to: jest-results.json\n\n\n"}
{"id": "patchbench-js-real-0003", "repo": "sveltejs/svelte", "base_commit": "c3348aea06b5dcc13159b96053351f36d6cb6d71", "status": "no_tests_parsed", "verify_status": null, "error": null, "timing": {"setup": 4.0, "pre_test_0": 67.2, "pre_test_1": 52.6, "post_test_0": 58.0, "post_test_1": 53.6, "total": 236.6}, "test_cmds": ["pnpm test --reporter=json > vitest-results.json"], "rebuild_cmds": [], "print_cmds": [], "f2p_pre_ok": true, "pre_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 0}, "p2p_env_dropped_count": 6075, "f2p_post_ok": false, "p2p_post_ok": true, "post_detail": {"missing": 2, "wrong": [], "missing_ids": ["select-spread-option-selected (hydrate)", "select-spread-option-selected (dom)"], "parsed_count": 0}, "raw_tail": "\n\n"}
{"id": "patchbench-js-real-0094", "repo": "open-gsd/gsd-core", "base_commit": "ffd353f080a27e9f3309a2590a6ee980c01a4d8f", "status": "f2p_not_failing_prefix", "verify_status": null, "error": null, "timing": {"setup": 6.6, "pre_test_0": 558.4, "pre_test_1": 528.0, "post_test_0": 535.7, "post_test_1": 566.3, "total": 2196.3}, "test_cmds": ["cd /tmp/cache/repos/open-gsd__gsd-core ; npm test 2>&1 | tee test-output.log"], "rebuild_cmds": [], "print_cmds": [], "f2p_pre_ok": false, "pre_detail": {"missing": 0, "wrong": [["plan-review-convergence.md uses gsd_run drift-guard seam > workflow drift-guard authority call includes --raw (prevents JSON-quoted capture)", "pass"], ["Parametric E2E sweep \u2014 4 empty points return correct envelope shape via real registry (ship:post excluded \u2014 mempalace registers 1 step there; verify:pre excluded since \\#1562 added the api-coverage gate) > [parametric] execute:pre \u2014 E2E subprocess exits 0 with {point, activeHooks:[], rendered:placeholder}", "pass"], ["folded:feat-3210-fallow-integration (consolidation epic \\#1969 B3 \\#1972) > feat-3210 / \\#1012: code-review workflow invokes fallow with the real CLI > does NOT use removed flags: --json , --profile, --stdin-files", "pass"], ["folded:feat-3210-fallow-integration (consolidation epic \\#1969 B3 \\#1972) > feat-3210: fallow integration module > normalizes empty fallow report to zero findings", "pass"], ["cmdInitMapCodebase > empty codebase dir returns no maps", "pass"], ["folded:feat-3210-fallow-integration (consolidation epic \\#1969 B3 \\#1972) > feat-3210 / \\#1012: code-review workflow invokes fallow with the real CLI > uses audit --format json and --quiet (real fallow 2.x flags)", "pass"], ["classifyDriftSeverity \u2014 validation > unknown authority \u2192 TypeError", "pass"], ["Section offset invariant: content.slice(bodyStart, bodyEnd) === body > invariant holds with CRLF line endings", "pass"], ["gsd-tools drift-guard \u2014 CLI e2e > severity --status MISSING --authority lsp \u2192 {severity:HIGH, hardBlock:true}", "pass"], ["folded:feat-3210-fallow-integration (consolidation epic \\#1969 B3 \\#1972) > feat-3210: workflow and config contracts > config schema allows code_quality.fallow.* keys in CJS and runtime manifest", "pass"]], "missing_ids": [], "parsed_count": 19978}, "p2p_env_dropped_count": 481, "f2p_post_ok": true, "p2p_post_ok": false, "post_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 20080}, "raw_tail": "fy-only\n ---\n duration_ms: 0.376127\n type: 'suite'\n ...\n# Subtest: verify-only: worktree_branch_check must NOT run git reset (\\#48, supersedes \\#2015)\n # Subtest: execute-phase.md worktree_branch_check does not use reset --soft\n ok 1 - execute-phase.md worktree_branch_check does not use reset --soft\n ---\n duration_ms: 0.179966\n type: 'test'\n ...\n # Subtest: verify-only: execute-phase.md worktree_branch_check must not run git reset at all (\\#48, supersedes \\#2015)\n ok 2 - verify-only: execute-phase.md worktree_branch_check must not run git reset at all (\\#48, supersedes \\#2015)\n ---\n duration_ms: 0.113356\n type: 'test'\n ...\n # Subtest: quick.md worktree_branch_check does not use reset --soft\n ok 3 - quick.md worktree_branch_check does not use reset --soft\n ---\n duration_ms: 0.107355\n type: 'test'\n ...\n # Subtest: verify-only: quick.md worktree_branch_check must not run git reset at all (\\#48, supersedes \\#2015)\n ok 4 - verify-only: quick.md worktree_branch_check must not run git reset at all (\\#48, supersedes \\#2015)\n ---\n duration_ms: 0.111306\n type: 'test'\n ...\n # Subtest: execute-phase.md references the canonical fragment\n ok 5 - execute-phase.md references the canonical fragment\n ---\n duration_ms: 0.519229\n type: 'test'\n ...\n1..209\n# tests 1132\n# suites 210\n# pass 1132\n# fail 0\n# cancelled 0\n# skipped 0\n# todo 0\n# duration_ms 18082.991894\n\n\n"}
{"id": "patchbench-js-real-0035", "repo": "hotwired/turbo", "base_commit": "71a769167eb64fafed48fe45ed175a54738216af", "status": "f2p_not_passing_postfix", "verify_status": null, "error": null, "timing": {"setup": 1.0, "pre_test_0": 1401.3, "pre_test_1": 1230.2, "post_test_0": 1236.5, "post_test_1": 1245.4, "total": 5114.6}, "test_cmds": ["mkdir -p reports && yarn test:unit 2>&1 | tee reports/unit-test-output.log || true && yarn test:browser --reporter=list 2>&1 | tee reports/playwright-list.log || true"], "rebuild_cmds": [], "print_cmds": [], "f2p_pre_ok": true, "pre_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 962}, "p2p_env_dropped_count": 0, "f2p_post_ok": false, "p2p_post_ok": true, "post_detail": {"missing": 36, "wrong": [["playwright:chrome:src/tests/functional/visit_tests.js::refreshing a location with a non-HTML extension", "fail"], ["playwright:chrome:src/tests/functional/drive_view_transition_tests.js::navigating does not trigger a view transition when prefers reduced motion is reduce", "fail"], ["playwright:chrome:src/tests/functional/form_submission_tests.js::input named action with action attribute", "fail"], ["playwright:chrome:src/tests/functional/visit_tests.js::visits with data-turbo-stream do not set aria-busy", "fail"], ["playwright:chrome:src/tests/functional/form_submission_tests.js::frame form submission with empty no-content response", "fail"], ["playwright:chrome:src/tests/functional/navigation_tests.js::drive disabled; click an element in the slot within data-turbo='false'", "fail"], ["playwright:chrome:src/tests/functional/form_submission_tests.js::stream link method form submission inside frame", "fail"], ["playwright:chrome:src/tests/functional/frame_tests.js::navigating frame with form[method=get][data-turbo-action=advance] to the same URL clears the [aria-busy] and [data-turbo-preview] state", "fail"], ["playwright:chrome:src/tests/functional/form_submission_tests.js::standard GET form submission does not merge values into the [action] attribute", "fail"], ["playwright:chrome:src/tests/functional/form_submission_tests.js::frame form submission ignores submissions with their defaultPrevented", "fail"]], "missing_ids": ["playwright:chrome:src/tests/functional/navigation_tests.js::following a redirection", "playwright:chrome:src/tests/functional/stream_tests.js::receiving a message without a template", "playwright:chrome:src/tests/functional/rendering_tests.js::error pages", "playwright:chrome:src/tests/functional/pausable_rendering_tests.js::pauses and resumes rendering", "playwright:chrome:src/tests/functional/rendering_tests.js::before-cache event"], "parsed_count": 966}, "raw_tail": " libwayland-client.so.0 \u2551\n \u2551 libGLESv2.so.2 \u2551\n \u2551 libx264.so \u2551\n \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d\n at /tmp/cache/repos/hotwired__turbo/node_modules/@web/test-runner-playwright/dist/PlaywrightLauncher.js:94:74\n at PlaywrightLauncher.getOrStartBrowser (/tmp/cache/repos/hotwired__turbo/node_modules/@web/test-runner-playwright/dist/PlaywrightLauncher.js:96:15)\n at PlaywrightLauncher.startSession (/tmp/cache/repos/hotwired__turbo/node_modules/@web/test-runner-playwright/dist/PlaywrightLauncher.js:41:36)\n at TestScheduler.startSession (/tmp/cache/repos/hotwired__turbo/node_modules/@web/test-runner-core/dist/runner/TestScheduler.js:103:62)\n at TestScheduler.runNextScheduled (/tmp/cache/repos/hotwired__turbo/node_modules/@web/test-runner-core/dist/runner/TestScheduler.js:83:30)\n at Timeout._onTimeout (/tmp/cache/repos/hotwired__turbo/node_modules/@web/test-runner-core/dist/runner/TestScheduler.js:34:26)\n\n\n\u001b[2K\u001b[1A\u001b[2K\u001b[GChromium: |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 5/5 test files | 0 passed, 0 failed\nFirefox: |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 5/5 test files | 0 passed, 0 failed\nWebkit: |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 5/5 test files | 0 passed, 0 failed\n\nError while running tests.\n\n\nerror Command failed with exit code 1.\ninfo Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.\n\n"}
{"id": "patchbench-js-real-0031", "repo": "stdlib-js/stdlib", "base_commit": "277ff471b445b93975761564f8b66a8f29da0070", "status": "f2p_not_passing_postfix", "verify_status": null, "error": null, "timing": {"setup": 65.1, "pre_test_0": 752.2, "pre_test_1": 593.4, "post_test_0": 694.8, "post_test_1": 689.3, "total": 2801.6}, "test_cmds": ["make -k test 2>&1 | tee test-output.log"], "rebuild_cmds": [], "print_cmds": [], "f2p_pre_ok": true, "pre_detail": {"missing": 0, "wrong": [], "missing_ids": [], "parsed_count": 434500}, "p2p_env_dropped_count": 24679, "f2p_post_ok": false, "p2p_post_ok": true, "post_detail": {"missing": 51, "wrong": [], "missing_ids": ["/testbed/lib/node_modules/@stdlib/plot/sparklines/unicode/line/test/test.label.js :: an instance throws an error if provided an invalid `label` value :: throws an error when provided null", "/testbed/lib/node_modules/@stdlib/ndarray/vector/ctor/test/test.factory.js :: the function returns a function which supports specifying the memory layout (arraybuffer) :: returns expected value [4]", "/testbed/lib/node_modules/@stdlib/ndarray/ctor/test/test.instance.iget_2d.js :: an ndarray constructor returns an instance which has an `iget` method for retrieving an array element using a linear index (2d; row-major; complex typed) :: returns expected value [29]", "/testbed/lib/node_modules/@stdlib/ndarray/vector/bool/test/test.js :: the function throws an error if provided an invalid byte offset argument (options) :: throws an error when provided null", "/testbed/lib/node_modules/@stdlib/plot/sparklines/unicode/line/test/test.label.js :: an instance throws an error if provided an invalid `label` value :: throws an error when provided true"], "parsed_count": 988894}, "raw_tail": "03774155\n \u2714 returns expected value when provided -48.16965462940526\n \u2714 returns expected value when provided -8.465977694537798\n \u2714 returns expected value when provided -31.9628752288714\n \u2714 returns expected value when provided 12.01158647786027\n \u2714 returns expected value when provided 28.848738042238637\n \u2714 returns expected value when provided -5.385224333882299\n \u2714 returns expected value when provided -15.496198692508045\n \u2714 returns expected value when provided -48.14387214404695\n \u2714 returns expected value when provided -20.46311755024587\n \u2714 returns expected value when provided 24.842645335742972\n \u2714 returns expected value when provided -39.86473812885532\n \u2714 returns expected value when provided -26.599368218855034\n \u2714 returns expected value when provided 45.89512691357764\n \u2714 returns expected value when provided -36.25251471968129\n \u2714 returns expected value when provided -39.71358317360695\n \u2714 returns expected value when provided 22.396419333928037\n\n the function returns `false` if provided `NaN`\n\n \u2714 returns expected value\n\n the function returns `false` if provided `+infinity`\n\n \u2714 returns expected value\n\n the function returns `false` if provided `-infinity`\n\n \u2714 returns expected value\n\n the function returns `false` if provided `1`\n\n \u2714 returns expected value\n\n\nmake: *** [/tmp/cache/repos/stdlib-js__stdlib/tools/make/lib/test/javascript.mk:101: test-javascript-local] Error 1\nmake: Target 'test' not remade because of errors.\n\n\n"}
|