7z-iterator 0.2.13 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/FileEntry.d.cts +3 -3
  2. package/dist/cjs/FileEntry.d.ts +3 -3
  3. package/dist/cjs/FileEntry.js.map +1 -1
  4. package/dist/cjs/SevenZipIterator.d.cts +4 -4
  5. package/dist/cjs/SevenZipIterator.d.ts +4 -4
  6. package/dist/cjs/SevenZipIterator.js +70 -9
  7. package/dist/cjs/SevenZipIterator.js.map +1 -1
  8. package/dist/cjs/sevenz/ArchiveSource.d.cts +40 -0
  9. package/dist/cjs/sevenz/ArchiveSource.d.ts +40 -0
  10. package/dist/cjs/sevenz/ArchiveSource.js +82 -0
  11. package/dist/cjs/sevenz/ArchiveSource.js.map +1 -0
  12. package/dist/cjs/sevenz/NumberCodec.js.map +1 -1
  13. package/dist/cjs/sevenz/SevenZipParser.d.cts +21 -30
  14. package/dist/cjs/sevenz/SevenZipParser.d.ts +21 -30
  15. package/dist/cjs/sevenz/SevenZipParser.js +24 -54
  16. package/dist/cjs/sevenz/SevenZipParser.js.map +1 -1
  17. package/dist/cjs/sevenz/codecs/Aes.js.map +1 -1
  18. package/dist/cjs/types.d.cts +4 -12
  19. package/dist/cjs/types.d.ts +4 -12
  20. package/dist/cjs/types.js +3 -0
  21. package/dist/cjs/types.js.map +1 -1
  22. package/dist/esm/FileEntry.d.ts +3 -3
  23. package/dist/esm/FileEntry.js.map +1 -1
  24. package/dist/esm/SevenZipIterator.d.ts +4 -4
  25. package/dist/esm/SevenZipIterator.js +26 -8
  26. package/dist/esm/SevenZipIterator.js.map +1 -1
  27. package/dist/esm/sevenz/ArchiveSource.d.ts +40 -0
  28. package/dist/esm/sevenz/ArchiveSource.js +54 -0
  29. package/dist/esm/sevenz/ArchiveSource.js.map +1 -0
  30. package/dist/esm/sevenz/SevenZipParser.d.ts +21 -30
  31. package/dist/esm/sevenz/SevenZipParser.js +21 -46
  32. package/dist/esm/sevenz/SevenZipParser.js.map +1 -1
  33. package/dist/esm/types.d.ts +4 -12
  34. package/dist/esm/types.js +1 -1
  35. package/dist/esm/types.js.map +1 -1
  36. package/package.json +15 -16
  37. package/dist/cjs/lib/Lock.d.cts +0 -12
  38. package/dist/cjs/lib/Lock.d.ts +0 -12
  39. package/dist/cjs/lib/Lock.js +0 -71
  40. package/dist/cjs/lib/Lock.js.map +0 -1
  41. package/dist/esm/lib/Lock.d.ts +0 -12
  42. package/dist/esm/lib/Lock.js +0 -47
  43. package/dist/esm/lib/Lock.js.map +0 -1
@@ -1,6 +1,22 @@
1
- // SevenZipParser - Main 7z archive parser
2
- // Handles reading archive structure and providing file streams
3
- "use strict";
1
+ /**
2
+ * SevenZipParser - Main 7z archive parser
3
+ *
4
+ * Handles reading archive structure and providing file streams.
5
+ *
6
+ * Parser Flow:
7
+ * 1. Read signature header (32 bytes) to get header location
8
+ * 2. Read encoded header from nextHeaderOffset
9
+ * 3. If header is compressed, decompress it first
10
+ * 4. Parse streams info (folder structure, pack positions)
11
+ * 5. Parse files info (names, sizes, attributes)
12
+ * 6. Build entry list for iteration
13
+ *
14
+ * Decompression:
15
+ * - 7z uses "folders" as decompression units
16
+ * - Solid archives: multiple files share one folder (decompress once)
17
+ * - Non-solid: one file per folder
18
+ * - Supports LZMA, LZMA2, COPY, BCJ2, and other codecs
19
+ */ "use strict";
4
20
  Object.defineProperty(exports, "__esModule", {
5
21
  value: true
6
22
  });
@@ -12,23 +28,23 @@ function _export(target, all) {
12
28
  }
13
29
  _export(exports, {
14
30
  get BufferSource () {
15
- return BufferSource;
31
+ return _ArchiveSourcets.BufferSource;
16
32
  },
17
33
  get FileSource () {
18
- return FileSource;
34
+ return _ArchiveSourcets.FileSource;
19
35
  },
20
36
  get SevenZipParser () {
21
37
  return SevenZipParser;
22
38
  }
23
39
  });
24
40
  var _extractbaseiterator = require("extract-base-iterator");
25
- var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
26
41
  var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
27
42
  var _stream = /*#__PURE__*/ _interop_require_default(require("stream"));
28
43
  var _indexts = require("./codecs/index.js");
29
44
  var _constantsts = require("./constants.js");
30
45
  var _headersts = require("./headers.js");
31
46
  var _NumberCodects = require("./NumberCodec.js");
47
+ var _ArchiveSourcets = require("./ArchiveSource.js");
32
48
  function _class_call_check(instance, Constructor) {
33
49
  if (!(instance instanceof Constructor)) {
34
50
  throw new TypeError("Cannot call a class as a function");
@@ -47,52 +63,6 @@ if (major > 0) {
47
63
  } else {
48
64
  PassThrough = require('readable-stream').PassThrough;
49
65
  }
50
- var BufferSource = /*#__PURE__*/ function() {
51
- "use strict";
52
- function BufferSource(buffer) {
53
- _class_call_check(this, BufferSource);
54
- this.buffer = buffer;
55
- }
56
- var _proto = BufferSource.prototype;
57
- _proto.read = function read(position, length) {
58
- return this.buffer.slice(position, position + length);
59
- };
60
- _proto.getSize = function getSize() {
61
- return this.buffer.length;
62
- };
63
- _proto.close = function close() {
64
- // Nothing to close for buffer
65
- };
66
- return BufferSource;
67
- }();
68
- var FileSource = /*#__PURE__*/ function() {
69
- "use strict";
70
- function FileSource(fd, size) {
71
- _class_call_check(this, FileSource);
72
- this.fd = fd;
73
- this.size = size;
74
- }
75
- var _proto = FileSource.prototype;
76
- _proto.read = function read(position, length) {
77
- var buf = (0, _extractbaseiterator.allocBuffer)(length);
78
- var bytesRead = _fs.default.readSync(this.fd, buf, 0, length, position);
79
- if (bytesRead < length) {
80
- return buf.slice(0, bytesRead);
81
- }
82
- return buf;
83
- };
84
- _proto.getSize = function getSize() {
85
- return this.size;
86
- };
87
- _proto.close = function close() {
88
- try {
89
- _fs.default.closeSync(this.fd);
90
- } catch (_e) {
91
- // Ignore close errors
92
- }
93
- };
94
- return FileSource;
95
- }();
96
66
  var SevenZipParser = /*#__PURE__*/ function() {
97
67
  "use strict";
98
68
  function SevenZipParser(source) {
@@ -179,7 +149,7 @@ var SevenZipParser = /*#__PURE__*/ function() {
179
149
  decompressedHeader = null; // CRC mismatch, need to search
180
150
  }
181
151
  }
182
- } catch (e) {
152
+ } catch (unused) {
183
153
  decompressedHeader = null; // Decompression failed, need to search
184
154
  }
185
155
  // If initial decompression failed, search for the correct position as a fallback
@@ -209,7 +179,7 @@ var SevenZipParser = /*#__PURE__*/ function() {
209
179
  decompressedHeader = candidateDecompressed;
210
180
  break searchLoop;
211
181
  }
212
- } catch (e) {
182
+ } catch (unused) {
213
183
  // Decompression failed, continue searching
214
184
  }
215
185
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/SevenZipParser.ts"],"sourcesContent":["// SevenZipParser - Main 7z archive parser\n// Handles reading archive structure and providing file streams\n\nimport { allocBuffer, crc32 } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\nimport Stream from 'stream';\nimport { decodeBcj2Multi, getCodec, getCodecName, isBcj2Codec, isCodecSupported } from './codecs/index.ts';\n\n// Use native streams when available, readable-stream only for Node 0.x\nconst major = +process.versions.node.split('.')[0];\nlet PassThrough: typeof Stream.PassThrough;\nif (major > 0) {\n PassThrough = Stream.PassThrough;\n} else {\n PassThrough = require('readable-stream').PassThrough;\n}\ntype Readable = Stream.Readable;\n\nimport { type CodedError, createCodedError, ErrorCode, FileAttribute, PropertyId, SIGNATURE_HEADER_SIZE } from './constants.ts';\nimport { type FileInfo, parseEncodedHeader, parseHeaderContent, parseSignatureHeader, type SignatureHeader, type StreamsInfo } from './headers.ts';\nimport { readNumber } from './NumberCodec.ts';\n\n// Callback type for async operations\ntype DecompressCallback = (err: Error | null, data?: Buffer) => void;\n\n// Entry type for iteration\nexport interface SevenZipEntry {\n name: string;\n path: string;\n type: 'file' | 'directory' | 'link';\n size: number;\n mtime?: Date;\n atime?: Date;\n ctime?: Date;\n mode?: number;\n isAntiFile: boolean;\n // Internal tracking\n _folderIndex: number;\n _streamIndex: number; // Global stream index\n _streamIndexInFolder: number; // Stream index within folder (for solid archives)\n _hasStream: boolean;\n _crc?: number; // Expected CRC32 for this file (if present in archive)\n}\n\n/**\n * Archive source abstraction - allows reading from file descriptor or buffer\n */\nexport interface ArchiveSource {\n read(position: number, length: number): Buffer;\n getSize(): number;\n close(): void;\n}\n\n/**\n * Buffer-based archive source\n */\nexport class BufferSource implements ArchiveSource {\n private buffer: Buffer;\n\n constructor(buffer: Buffer) {\n this.buffer = buffer;\n }\n\n read(position: number, length: number): Buffer {\n return this.buffer.slice(position, position + length);\n }\n\n getSize(): number {\n return this.buffer.length;\n }\n\n close(): void {\n // Nothing to close for buffer\n }\n}\n\n/**\n * File descriptor based archive source\n */\nexport class FileSource implements ArchiveSource {\n private fd: number;\n private size: number;\n\n constructor(fd: number, size: number) {\n this.fd = fd;\n this.size = size;\n }\n\n read(position: number, length: number): Buffer {\n const buf = allocBuffer(length);\n const bytesRead = fs.readSync(this.fd, buf, 0, length, position);\n if (bytesRead < length) {\n return buf.slice(0, bytesRead);\n }\n return buf;\n }\n\n getSize(): number {\n return this.size;\n }\n\n close(): void {\n try {\n fs.closeSync(this.fd);\n } catch (_e) {\n // Ignore close errors\n }\n }\n}\n\n/**\n * SevenZipParser - parses 7z archives and provides entry iteration\n */\nexport class SevenZipParser {\n private source: ArchiveSource;\n private signature: SignatureHeader | null = null;\n private streamsInfo: StreamsInfo | null = null;\n private filesInfo: FileInfo[] = [];\n private entries: SevenZipEntry[] = [];\n private parsed = false;\n // Smart cache for decompressed solid blocks\n // Only caches when multiple files share a block, releases when last file extracted\n private decompressedCache: { [key: number]: Buffer } = {};\n // Track files per folder and how many have been extracted\n private filesPerFolder: { [key: number]: number } = {};\n private extractedPerFolder: { [key: number]: number } = {};\n\n constructor(source: ArchiveSource) {\n this.source = source;\n }\n\n /**\n * Parse the archive structure\n * Must be called before iterating entries\n */\n parse(): void {\n if (this.parsed) return;\n\n // Read signature header\n const sigBuf = this.source.read(0, SIGNATURE_HEADER_SIZE);\n if (sigBuf.length < SIGNATURE_HEADER_SIZE) {\n throw createCodedError('Archive too small', ErrorCode.TRUNCATED_ARCHIVE);\n }\n\n this.signature = parseSignatureHeader(sigBuf);\n\n // Read encoded header\n const headerOffset = SIGNATURE_HEADER_SIZE + this.signature.nextHeaderOffset;\n const headerBuf = this.source.read(headerOffset, this.signature.nextHeaderSize);\n\n if (headerBuf.length < this.signature.nextHeaderSize) {\n throw createCodedError('Truncated header', ErrorCode.TRUNCATED_ARCHIVE);\n }\n\n // Parse encoded header (may need decompression)\n try {\n const headerResult = parseEncodedHeader(headerBuf, this.signature.nextHeaderCRC);\n this.streamsInfo = headerResult.streamsInfo || null;\n this.filesInfo = headerResult.filesInfo;\n } catch (err: unknown) {\n const codedErr = err as CodedError;\n if (codedErr && codedErr.code === ErrorCode.COMPRESSED_HEADER) {\n // Header is compressed - need to decompress first\n this.handleCompressedHeader(headerBuf);\n } else {\n throw err;\n }\n }\n\n // Build entries list\n this.buildEntries();\n this.parsed = true;\n }\n\n /**\n * Handle compressed header (kEncodedHeader)\n */\n private handleCompressedHeader(headerBuf: Buffer): void {\n // Parse the encoded header info to get decompression parameters\n let offset = 1; // Skip kEncodedHeader byte\n\n // Should have StreamsInfo for the header itself\n const propertyId = headerBuf[offset++];\n if (propertyId !== PropertyId.kMainStreamsInfo && propertyId !== PropertyId.kPackInfo) {\n throw createCodedError('Expected StreamsInfo in encoded header', ErrorCode.CORRUPT_HEADER);\n }\n\n // For now, we parse the streams info from the encoded header block\n // This tells us how to decompress the actual header\n\n // Read pack info from the encoded header structure\n const packInfoResult = this.parseEncodedHeaderStreams(headerBuf, 1);\n\n // Calculate compressed header position\n // For simple archives: header is at SIGNATURE_HEADER_SIZE + packPos\n // For BCJ2/complex archives: header may be at the END of pack data area\n // The pack data area ends at nextHeaderOffset (where encoded header starts)\n const compressedStart = SIGNATURE_HEADER_SIZE + packInfoResult.packPos;\n const compressedData = this.source.read(compressedStart, packInfoResult.packSize);\n\n // Decompress using the specified codec\n const codec = getCodec(packInfoResult.codecId);\n let decompressedHeader: Buffer | null = null;\n\n // Try decompressing from the calculated position first\n try {\n decompressedHeader = codec.decode(compressedData, packInfoResult.properties, packInfoResult.unpackSize);\n // Verify CRC if present\n if (packInfoResult.unpackCRC !== undefined) {\n const actualCRC = crc32(decompressedHeader);\n if (actualCRC !== packInfoResult.unpackCRC) {\n decompressedHeader = null; // CRC mismatch, need to search\n }\n }\n } catch {\n decompressedHeader = null; // Decompression failed, need to search\n }\n\n // If initial decompression failed, search for the correct position as a fallback\n // This handles edge cases where packPos doesn't point directly to header pack data\n if (decompressedHeader === null && this.signature) {\n const packAreaEnd = SIGNATURE_HEADER_SIZE + this.signature.nextHeaderOffset;\n const searchStart = packAreaEnd - packInfoResult.packSize;\n const searchEnd = Math.max(SIGNATURE_HEADER_SIZE, compressedStart - 100000);\n\n // Scan for LZMA data starting with 0x00 (range coder init)\n // Try each candidate and validate with CRC\n const scanChunkSize = 4096;\n searchLoop: for (let chunkStart = searchStart; chunkStart >= searchEnd; chunkStart -= scanChunkSize) {\n const chunk = this.source.read(chunkStart, scanChunkSize + packInfoResult.packSize);\n for (let i = 0; i < Math.min(chunk.length, scanChunkSize); i++) {\n if (chunk[i] === 0x00) {\n const candidateData = chunk.subarray(i, i + packInfoResult.packSize);\n if (candidateData.length === packInfoResult.packSize) {\n try {\n const candidateDecompressed = codec.decode(candidateData, packInfoResult.properties, packInfoResult.unpackSize);\n if (packInfoResult.unpackCRC !== undefined) {\n const candCRC = crc32(candidateDecompressed);\n if (candCRC === packInfoResult.unpackCRC) {\n decompressedHeader = candidateDecompressed;\n break searchLoop;\n }\n } else {\n decompressedHeader = candidateDecompressed;\n break searchLoop;\n }\n } catch {\n // Decompression failed, continue searching\n }\n }\n }\n }\n }\n }\n\n if (decompressedHeader === null) {\n throw createCodedError('Failed to decompress header - could not find valid LZMA data', ErrorCode.CORRUPT_HEADER);\n }\n\n // Now parse the decompressed header\n // It should start with kHeader\n let decompOffset = 0;\n const headerId = decompressedHeader[decompOffset++];\n if (headerId !== PropertyId.kHeader) {\n throw createCodedError('Expected kHeader in decompressed header', ErrorCode.CORRUPT_HEADER);\n }\n\n // Parse the decompressed header using shared function from headers.ts\n const result = parseHeaderContent(decompressedHeader, decompOffset);\n this.streamsInfo = result.streamsInfo || null;\n this.filesInfo = result.filesInfo;\n }\n\n /**\n * Parse streams info from encoded header block\n * This is a simplified parser for the header's own compression info\n */\n private parseEncodedHeaderStreams(\n buf: Buffer,\n offset: number\n ): {\n packPos: number;\n packSize: number;\n unpackSize: number;\n codecId: number[];\n properties?: Buffer;\n unpackCRC?: number;\n } {\n // This is a simplified parser for the encoded header's own streams info\n let packPos = 0;\n let packSize = 0;\n let unpackSize = 0;\n let codecId: number[] = [];\n let properties: Buffer | undefined;\n let unpackCRC: number | undefined;\n\n while (offset < buf.length) {\n const propertyId = buf[offset++];\n\n if (propertyId === PropertyId.kEnd) {\n break;\n }\n\n switch (propertyId) {\n case PropertyId.kPackInfo: {\n const packPosResult = readNumber(buf, offset);\n packPos = packPosResult.value;\n offset += packPosResult.bytesRead;\n\n const numPackResult = readNumber(buf, offset);\n offset += numPackResult.bytesRead;\n\n // Read until kEnd\n while (buf[offset] !== PropertyId.kEnd) {\n if (buf[offset] === PropertyId.kSize) {\n offset++;\n const sizeResult = readNumber(buf, offset);\n packSize = sizeResult.value;\n offset += sizeResult.bytesRead;\n } else {\n offset++;\n }\n }\n offset++; // Skip kEnd\n break;\n }\n\n case PropertyId.kUnpackInfo:\n // Find folder/coder info\n while (offset < buf.length && buf[offset] !== PropertyId.kEnd) {\n if (buf[offset] === PropertyId.kFolder) {\n offset++;\n const numFoldersResult = readNumber(buf, offset);\n offset += numFoldersResult.bytesRead;\n offset++; // external flag\n\n // Parse coder\n const numCodersResult = readNumber(buf, offset);\n offset += numCodersResult.bytesRead;\n\n const flags = buf[offset++];\n const idSize = flags & 0x0f;\n const hasAttributes = (flags & 0x20) !== 0;\n\n codecId = [];\n for (let i = 0; i < idSize; i++) {\n codecId.push(buf[offset++]);\n }\n\n if (hasAttributes) {\n const propsLenResult = readNumber(buf, offset);\n offset += propsLenResult.bytesRead;\n properties = buf.slice(offset, offset + propsLenResult.value);\n offset += propsLenResult.value;\n }\n } else if (buf[offset] === PropertyId.kCodersUnpackSize) {\n offset++;\n // Read unpack size - needed for LZMA decoder\n const unpackSizeResult = readNumber(buf, offset);\n unpackSize = unpackSizeResult.value;\n offset += unpackSizeResult.bytesRead;\n } else if (buf[offset] === PropertyId.kCRC) {\n offset++;\n const allDefined = buf[offset++];\n if (allDefined) {\n unpackCRC = buf.readUInt32LE(offset);\n offset += 4;\n }\n } else {\n offset++;\n }\n }\n if (buf[offset] === PropertyId.kEnd) offset++;\n break;\n }\n }\n\n return { packPos: packPos, packSize: packSize, unpackSize: unpackSize, codecId: codecId, properties: properties, unpackCRC: unpackCRC };\n }\n\n /**\n * Build the entries list from parsed file info\n */\n private buildEntries(): void {\n this.entries = [];\n\n if (!this.streamsInfo) {\n // No streams info - just create entries from file info\n for (let i = 0; i < this.filesInfo.length; i++) {\n const file = this.filesInfo[i];\n this.entries.push(this.createEntry(file, 0, 0, 0));\n }\n return;\n }\n\n // Use the properly parsed numUnpackStreamsPerFolder from the archive header\n const streamsPerFolder = this.streamsInfo.numUnpackStreamsPerFolder;\n\n // Initialize files per folder count (for smart caching)\n for (let f = 0; f < streamsPerFolder.length; f++) {\n this.filesPerFolder[f] = streamsPerFolder[f];\n this.extractedPerFolder[f] = 0;\n }\n\n // Now build entries with proper folder/stream tracking\n let streamIndex = 0;\n let folderIndex = 0;\n let streamInFolder = 0;\n let folderStreamCount = streamsPerFolder[0] || 0;\n\n for (let j = 0; j < this.filesInfo.length; j++) {\n const fileInfo = this.filesInfo[j];\n\n // Get size from unpackSizes for files with streams\n let size = 0;\n if (fileInfo.hasStream && streamIndex < this.streamsInfo.unpackSizes.length) {\n size = this.streamsInfo.unpackSizes[streamIndex];\n }\n\n const entry = this.createEntry(fileInfo, size, folderIndex, streamInFolder);\n entry._streamIndex = streamIndex;\n // Set CRC if available\n if (fileInfo.hasStream && this.streamsInfo.unpackCRCs && this.streamsInfo.unpackCRCs[streamIndex] !== undefined) {\n entry._crc = this.streamsInfo.unpackCRCs[streamIndex];\n }\n this.entries.push(entry);\n\n // Advance stream tracking for files with streams\n if (fileInfo.hasStream) {\n streamIndex++;\n streamInFolder++;\n\n // Check if we've exhausted streams in this folder\n if (streamInFolder >= folderStreamCount) {\n folderIndex++;\n streamInFolder = 0;\n folderStreamCount = streamsPerFolder[folderIndex] || 0;\n }\n }\n }\n }\n\n /**\n * Create an entry from file info\n */\n private createEntry(file: FileInfo, size: number, folderIndex: number, streamInFolder: number): SevenZipEntry {\n // Determine entry type\n // Note: 7z format doesn't natively support symlinks. p7zip with -snl stores\n // symlinks as regular files with the target path as content.\n let type: 'file' | 'directory' | 'link' = 'file';\n if (file.isDirectory) {\n type = 'directory';\n }\n\n // Calculate mode from Windows attributes\n let mode: number | undefined;\n if (file.attributes !== undefined) {\n // Check for Unix extension bit\n if ((file.attributes & FileAttribute.UNIX_EXTENSION) !== 0) {\n mode = (file.attributes >>> 16) & 0xffff;\n // Check for symlink (S_IFLNK = 0xA000)\n // Note: Most 7z implementations don't preserve symlink mode bits\n if ((mode & 0xf000) === 0xa000) {\n type = 'link';\n }\n } else if (file.isDirectory) {\n mode = 493; // 0o755\n } else {\n mode = 420; // 0o644\n }\n }\n\n return {\n name: getBaseName(file.name),\n path: file.name,\n type: type,\n size: size,\n mtime: file.mtime,\n atime: file.atime,\n ctime: file.ctime,\n mode: mode,\n isAntiFile: file.isAntiFile,\n _folderIndex: folderIndex,\n _streamIndex: 0, // Set by caller\n _streamIndexInFolder: streamInFolder,\n _hasStream: file.hasStream,\n };\n }\n\n /**\n * Get the list of entries\n */\n getEntries(): SevenZipEntry[] {\n if (!this.parsed) {\n this.parse();\n }\n return this.entries;\n }\n\n /**\n * Get a readable stream for an entry's content\n */\n getEntryStream(entry: SevenZipEntry): Readable {\n if (!entry._hasStream || entry.type === 'directory') {\n // Return empty stream for directories and empty files\n const emptyStream = new PassThrough();\n emptyStream.end();\n return emptyStream;\n }\n\n if (!this.streamsInfo) {\n throw createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER);\n }\n\n // Get folder info\n const folder = this.streamsInfo.folders[entry._folderIndex];\n if (!folder) {\n throw createCodedError('Invalid folder index', ErrorCode.CORRUPT_HEADER);\n }\n\n // Check codec support\n for (let i = 0; i < folder.coders.length; i++) {\n const coder = folder.coders[i];\n if (!isCodecSupported(coder.id)) {\n const codecName = getCodecName(coder.id);\n throw createCodedError(`Unsupported codec: ${codecName}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n }\n\n // Get decompressed data for this folder (with smart caching)\n const folderIdx = entry._folderIndex;\n const data = this.getDecompressedFolder(folderIdx);\n\n // Calculate file offset within the decompressed block\n // For solid archives, multiple files are concatenated in the block\n let fileStart = 0;\n for (let m = 0; m < entry._streamIndexInFolder; m++) {\n // Sum sizes of all streams before this one in the folder\n const prevStreamGlobalIndex = entry._streamIndex - entry._streamIndexInFolder + m;\n fileStart += this.streamsInfo.unpackSizes[prevStreamGlobalIndex];\n }\n\n const fileSize = entry.size;\n\n // Create a PassThrough stream with the file data\n const outputStream = new PassThrough();\n\n // Bounds check to prevent \"oob\" error on older Node versions\n if (fileStart + fileSize > data.length) {\n throw createCodedError(`File data out of bounds: offset ${fileStart} + size ${fileSize} > decompressed length ${data.length}`, ErrorCode.DECOMPRESSION_FAILED);\n }\n\n const fileData = data.slice(fileStart, fileStart + fileSize);\n\n // Verify CRC if present\n if (entry._crc !== undefined) {\n const actualCRC = crc32(fileData);\n if (actualCRC !== entry._crc) {\n throw createCodedError(`CRC mismatch for ${entry.path}: expected ${entry._crc.toString(16)}, got ${actualCRC.toString(16)}`, ErrorCode.CRC_MISMATCH);\n }\n }\n\n outputStream.end(fileData);\n\n // Track extraction and release cache when all files from this folder are done\n this.extractedPerFolder[folderIdx] = (this.extractedPerFolder[folderIdx] || 0) + 1;\n if (this.extractedPerFolder[folderIdx] >= this.filesPerFolder[folderIdx]) {\n // All files from this folder extracted, release cache\n delete this.decompressedCache[folderIdx];\n }\n\n return outputStream;\n }\n\n /**\n * Get a readable stream for an entry's content (callback-based async version)\n * Uses streaming decompression for non-blocking I/O\n */\n getEntryStreamAsync(entry: SevenZipEntry, callback: (err: Error | null, stream?: Readable) => void): void {\n if (!entry._hasStream || entry.type === 'directory') {\n // Return empty stream for directories and empty files\n const emptyStream = new PassThrough();\n emptyStream.end();\n callback(null, emptyStream);\n return;\n }\n\n if (!this.streamsInfo) {\n callback(createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER));\n return;\n }\n\n // Get folder info\n const folder = this.streamsInfo.folders[entry._folderIndex];\n if (!folder) {\n callback(createCodedError('Invalid folder index', ErrorCode.CORRUPT_HEADER));\n return;\n }\n\n // Check codec support\n for (let i = 0; i < folder.coders.length; i++) {\n const coder = folder.coders[i];\n if (!isCodecSupported(coder.id)) {\n const codecName = getCodecName(coder.id);\n callback(createCodedError(`Unsupported codec: ${codecName}`, ErrorCode.UNSUPPORTED_CODEC));\n return;\n }\n }\n\n // Get decompressed data for this folder using async method\n const folderIdx = entry._folderIndex;\n const streamsInfo = this.streamsInfo;\n\n this.getDecompressedFolderAsync(folderIdx, (err, data) => {\n if (err) return callback(err);\n if (!data) return callback(new Error('No data returned from decompression'));\n\n // Calculate file offset within the decompressed block\n let fileStart = 0;\n for (let m = 0; m < entry._streamIndexInFolder; m++) {\n const prevStreamGlobalIndex = entry._streamIndex - entry._streamIndexInFolder + m;\n fileStart += streamsInfo.unpackSizes[prevStreamGlobalIndex];\n }\n\n const fileSize = entry.size;\n\n // Bounds check\n if (fileStart + fileSize > data.length) {\n return callback(createCodedError(`File data out of bounds: offset ${fileStart} + size ${fileSize} > decompressed length ${data.length}`, ErrorCode.DECOMPRESSION_FAILED));\n }\n\n // Create a PassThrough stream with the file data\n const outputStream = new PassThrough();\n const fileData = data.slice(fileStart, fileStart + fileSize);\n\n // Verify CRC if present\n if (entry._crc !== undefined) {\n const actualCRC = crc32(fileData);\n if (actualCRC !== entry._crc) {\n return callback(createCodedError(`CRC mismatch for ${entry.path}: expected ${entry._crc.toString(16)}, got ${actualCRC.toString(16)}`, ErrorCode.CRC_MISMATCH));\n }\n }\n\n outputStream.end(fileData);\n\n // Track extraction and release cache when all files from this folder are done\n this.extractedPerFolder[folderIdx] = (this.extractedPerFolder[folderIdx] || 0) + 1;\n if (this.extractedPerFolder[folderIdx] >= this.filesPerFolder[folderIdx]) {\n delete this.decompressedCache[folderIdx];\n }\n\n callback(null, outputStream);\n });\n }\n\n /**\n * Check if a folder uses BCJ2 codec\n */\n private folderHasBcj2(folder: { coders: { id: number[] }[] }): boolean {\n for (let i = 0; i < folder.coders.length; i++) {\n if (isBcj2Codec(folder.coders[i].id)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Get decompressed data for a folder, with smart caching for solid archives\n * Only caches when multiple files share a block, releases when last file extracted\n */\n private getDecompressedFolder(folderIndex: number): Buffer {\n // Check cache first\n if (this.decompressedCache[folderIndex]) {\n return this.decompressedCache[folderIndex];\n }\n\n if (!this.streamsInfo) {\n throw createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER);\n }\n\n const folder = this.streamsInfo.folders[folderIndex];\n\n // Check how many files remain in this folder\n const filesInFolder = this.filesPerFolder[folderIndex] || 1;\n const extractedFromFolder = this.extractedPerFolder[folderIndex] || 0;\n const remainingFiles = filesInFolder - extractedFromFolder;\n // Only cache if more than 1 file remains (including the current one being extracted)\n const shouldCache = remainingFiles > 1;\n\n // Check if this folder uses BCJ2 (requires special multi-stream handling)\n if (this.folderHasBcj2(folder)) {\n const data = this.decompressBcj2Folder(folderIndex);\n if (shouldCache) {\n this.decompressedCache[folderIndex] = data;\n }\n return data;\n }\n\n // Calculate packed data position\n let packPos = SIGNATURE_HEADER_SIZE + this.streamsInfo.packPos;\n\n // Find which pack stream this folder uses\n let packStreamIndex = 0;\n for (let j = 0; j < folderIndex; j++) {\n packStreamIndex += this.streamsInfo.folders[j].packedStreams.length;\n }\n\n // Calculate position of this pack stream\n for (let k = 0; k < packStreamIndex; k++) {\n packPos += this.streamsInfo.packSizes[k];\n }\n\n const packSize = this.streamsInfo.packSizes[packStreamIndex];\n\n // Read packed data\n const packedData = this.source.read(packPos, packSize);\n\n // Decompress through codec chain\n let data2 = packedData;\n for (let l = 0; l < folder.coders.length; l++) {\n const coderInfo = folder.coders[l];\n const codec = getCodec(coderInfo.id);\n // Get unpack size for this coder (needed by LZMA)\n const unpackSize = folder.unpackSizes[l];\n data2 = codec.decode(data2, coderInfo.properties, unpackSize);\n }\n\n // Cache only if more files remain in this folder\n if (shouldCache) {\n this.decompressedCache[folderIndex] = data2;\n }\n\n return data2;\n }\n\n /**\n * Get decompressed data for a folder using streaming (callback-based async)\n * Uses createDecoder() streams for non-blocking decompression\n */\n private getDecompressedFolderAsync(folderIndex: number, callback: DecompressCallback): void {\n const self = this;\n\n // Check cache first\n if (this.decompressedCache[folderIndex]) {\n callback(null, this.decompressedCache[folderIndex]);\n return;\n }\n\n if (!this.streamsInfo) {\n callback(createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER));\n return;\n }\n\n const folder = this.streamsInfo.folders[folderIndex];\n\n // Check how many files remain in this folder\n const filesInFolder = this.filesPerFolder[folderIndex] || 1;\n const extractedFromFolder = this.extractedPerFolder[folderIndex] || 0;\n const remainingFiles = filesInFolder - extractedFromFolder;\n const shouldCache = remainingFiles > 1;\n\n // BCJ2 requires special handling - use sync version for now\n // TODO: Add async BCJ2 support\n if (this.folderHasBcj2(folder)) {\n try {\n const data = this.decompressBcj2Folder(folderIndex);\n if (shouldCache) {\n this.decompressedCache[folderIndex] = data;\n }\n callback(null, data);\n } catch (err) {\n callback(err as Error);\n }\n return;\n }\n\n // Calculate packed data position\n let packPos = SIGNATURE_HEADER_SIZE + this.streamsInfo.packPos;\n\n // Find which pack stream this folder uses\n let packStreamIndex = 0;\n for (let j = 0; j < folderIndex; j++) {\n packStreamIndex += this.streamsInfo.folders[j].packedStreams.length;\n }\n\n // Calculate position of this pack stream\n for (let k = 0; k < packStreamIndex; k++) {\n packPos += this.streamsInfo.packSizes[k];\n }\n\n const packSize = this.streamsInfo.packSizes[packStreamIndex];\n\n // Read packed data\n const packedData = this.source.read(packPos, packSize);\n\n // Create decoder stream chain and decompress\n const coders = folder.coders;\n const unpackSizes = folder.unpackSizes;\n\n // Helper to decompress through a single codec stream\n function decompressWithStream(input: Buffer, coderIdx: number, cb: DecompressCallback): void {\n const coderInfo = coders[coderIdx];\n const codec = getCodec(coderInfo.id);\n const decoder = codec.createDecoder(coderInfo.properties, unpackSizes[coderIdx]);\n\n const chunks: Buffer[] = [];\n let errorOccurred = false;\n\n decoder.on('data', (chunk: Buffer) => {\n chunks.push(chunk);\n });\n\n oo(decoder, ['error', 'end', 'close', 'finish'], (err?: Error) => {\n if (errorOccurred) return;\n if (err) {\n errorOccurred = true;\n return cb(err);\n }\n cb(null, Buffer.concat(chunks));\n });\n\n // Write input data to decoder and signal end\n decoder.end(input);\n }\n\n // Chain decompression through all codecs\n function decompressChain(input: Buffer, idx: number): void {\n if (idx >= coders.length) {\n // All done - cache and return\n if (shouldCache) {\n self.decompressedCache[folderIndex] = input;\n }\n callback(null, input);\n return;\n }\n\n decompressWithStream(input, idx, (err, output) => {\n if (err) {\n callback(err);\n return;\n }\n decompressChain(output as Buffer, idx + 1);\n });\n }\n\n // Start the chain\n decompressChain(packedData, 0);\n }\n\n /**\n * Decompress a BCJ2 folder with multi-stream handling\n * BCJ2 uses 4 input streams: main, call, jump, range coder\n */\n private decompressBcj2Folder(folderIndex: number): Buffer {\n if (!this.streamsInfo) {\n throw createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER);\n }\n\n const folder = this.streamsInfo.folders[folderIndex];\n\n // Calculate starting pack position\n let packPos = SIGNATURE_HEADER_SIZE + this.streamsInfo.packPos;\n\n // Find which pack stream index this folder starts at\n let packStreamIndex = 0;\n for (let j = 0; j < folderIndex; j++) {\n packStreamIndex += this.streamsInfo.folders[j].packedStreams.length;\n }\n\n // Calculate position\n for (let k = 0; k < packStreamIndex; k++) {\n packPos += this.streamsInfo.packSizes[k];\n }\n\n // Read all pack streams for this folder\n const numPackStreams = folder.packedStreams.length;\n const packStreams: Buffer[] = [];\n let currentPos = packPos;\n\n for (let p = 0; p < numPackStreams; p++) {\n const size = this.streamsInfo.packSizes[packStreamIndex + p];\n packStreams.push(this.source.read(currentPos, size));\n currentPos += size;\n }\n\n // Build a map of coder outputs\n // For BCJ2, typical structure is:\n // Coder 0: LZMA2 (main stream) - 1 in, 1 out\n // Coder 1: LZMA (call stream) - 1 in, 1 out\n // Coder 2: LZMA (jump stream) - 1 in, 1 out\n // Coder 3: BCJ2 - 4 in, 1 out\n // Pack streams map to: coder inputs not bound to other coder outputs\n\n // First, decompress each non-BCJ2 coder\n const coderOutputs: { [key: number]: Buffer } = {};\n\n // Find the BCJ2 coder\n let bcj2CoderIndex = -1;\n for (let c = 0; c < folder.coders.length; c++) {\n if (isBcj2Codec(folder.coders[c].id)) {\n bcj2CoderIndex = c;\n break;\n }\n }\n\n if (bcj2CoderIndex === -1) {\n throw createCodedError('BCJ2 coder not found in folder', ErrorCode.CORRUPT_HEADER);\n }\n\n // Build input stream index -> pack stream mapping\n // folder.packedStreams tells us which input indices are unbound and their order\n const inputToPackStream: { [key: number]: number } = {};\n for (let pi = 0; pi < folder.packedStreams.length; pi++) {\n inputToPackStream[folder.packedStreams[pi]] = pi;\n }\n\n // Build output stream index -> coder mapping\n const outputToCoder: { [key: number]: number } = {};\n let totalOutputs = 0;\n for (let co = 0; co < folder.coders.length; co++) {\n const numOut = folder.coders[co].numOutStreams;\n for (let outp = 0; outp < numOut; outp++) {\n outputToCoder[totalOutputs + outp] = co;\n }\n totalOutputs += numOut;\n }\n\n // Decompress non-BCJ2 coders (LZMA, LZMA2)\n // We need to process in dependency order\n const processed: { [key: number]: boolean } = {};\n\n const processOrder = this.getCoderProcessOrder(folder, bcj2CoderIndex);\n\n for (let po = 0; po < processOrder.length; po++) {\n const coderIdx = processOrder[po];\n if (coderIdx === bcj2CoderIndex) continue;\n\n const coder = folder.coders[coderIdx];\n const codec = getCodec(coder.id);\n\n // Find input for this coder\n let coderInputStart = 0;\n for (let ci2 = 0; ci2 < coderIdx; ci2++) {\n coderInputStart += folder.coders[ci2].numInStreams;\n }\n\n // Get input data (from pack stream)\n const inputIdx = coderInputStart;\n const packStreamIdx = inputToPackStream[inputIdx];\n const inputData = packStreams[packStreamIdx];\n\n // Decompress\n const unpackSize = folder.unpackSizes[coderIdx];\n const outputData = codec.decode(inputData, coder.properties, unpackSize);\n\n // Store in coder outputs\n let coderOutputStart = 0;\n for (let co2 = 0; co2 < coderIdx; co2++) {\n coderOutputStart += folder.coders[co2].numOutStreams;\n }\n coderOutputs[coderOutputStart] = outputData;\n processed[coderIdx] = true;\n }\n\n // Now process BCJ2\n // BCJ2 has 4 inputs, need to map them correctly\n // Standard order: main(LZMA2 output), call(LZMA output), jump(LZMA output), range(raw pack)\n let bcj2InputStart = 0;\n for (let ci3 = 0; ci3 < bcj2CoderIndex; ci3++) {\n bcj2InputStart += folder.coders[ci3].numInStreams;\n }\n\n const bcj2Inputs: Buffer[] = [];\n for (let bi = 0; bi < 4; bi++) {\n const globalIdx = bcj2InputStart + bi;\n\n // Check if this input is bound to a coder output\n let boundOutput = -1;\n for (let bp2 = 0; bp2 < folder.bindPairs.length; bp2++) {\n if (folder.bindPairs[bp2].inIndex === globalIdx) {\n boundOutput = folder.bindPairs[bp2].outIndex;\n break;\n }\n }\n\n if (boundOutput >= 0) {\n // Get from coder outputs\n bcj2Inputs.push(coderOutputs[boundOutput]);\n } else {\n // Get from pack streams\n const psIdx = inputToPackStream[globalIdx];\n bcj2Inputs.push(packStreams[psIdx]);\n }\n }\n\n // Get BCJ2 unpack size\n let bcj2OutputStart = 0;\n for (let co3 = 0; co3 < bcj2CoderIndex; co3++) {\n bcj2OutputStart += folder.coders[co3].numOutStreams;\n }\n const bcj2UnpackSize = folder.unpackSizes[bcj2OutputStart];\n\n // Memory optimization: Clear intermediate buffers to help GC\n // These are no longer needed after bcj2Inputs is built\n for (const key in coderOutputs) {\n delete coderOutputs[key];\n }\n // Clear packStreams array (allows GC to free compressed data)\n packStreams.length = 0;\n\n // Decode BCJ2\n return decodeBcj2Multi(bcj2Inputs, undefined, bcj2UnpackSize);\n }\n\n /**\n * Get processing order for coders (dependency order)\n */\n private getCoderProcessOrder(folder: { coders: { numInStreams: number; numOutStreams: number }[]; bindPairs: { inIndex: number; outIndex: number }[] }, excludeIdx: number): number[] {\n const order: number[] = [];\n const processed: { [key: number]: boolean } = {};\n\n // Simple approach: process coders that don't depend on unprocessed outputs\n let changed = true;\n while (changed) {\n changed = false;\n for (let c = 0; c < folder.coders.length; c++) {\n if (processed[c] || c === excludeIdx) continue;\n\n // Check if all inputs are satisfied\n let inputStart = 0;\n for (let i = 0; i < c; i++) {\n inputStart += folder.coders[i].numInStreams;\n }\n\n let canProcess = true;\n for (let inp = 0; inp < folder.coders[c].numInStreams; inp++) {\n const globalIdx = inputStart + inp;\n // Check if bound to an unprocessed coder\n for (let bp = 0; bp < folder.bindPairs.length; bp++) {\n if (folder.bindPairs[bp].inIndex === globalIdx) {\n // Find which coder produces this output\n const outIdx = folder.bindPairs[bp].outIndex;\n let outStart = 0;\n for (let oc = 0; oc < folder.coders.length; oc++) {\n const numOut = folder.coders[oc].numOutStreams;\n if (outIdx < outStart + numOut) {\n if (!processed[oc] && oc !== excludeIdx) {\n canProcess = false;\n }\n break;\n }\n outStart += numOut;\n }\n }\n }\n }\n\n if (canProcess) {\n order.push(c);\n processed[c] = true;\n changed = true;\n }\n }\n }\n\n return order;\n }\n\n /**\n * Close the parser and release resources\n */\n close(): void {\n if (this.source) {\n this.source.close();\n }\n }\n}\n\n/**\n * Get base name from a path\n */\nfunction getBaseName(path: string): string {\n const lastSlash = path.lastIndexOf('/');\n const lastBackslash = path.lastIndexOf('\\\\');\n const lastSep = Math.max(lastSlash, lastBackslash);\n return lastSep >= 0 ? path.slice(lastSep + 1) : path;\n}\n"],"names":["BufferSource","FileSource","SevenZipParser","major","process","versions","node","split","PassThrough","Stream","require","buffer","read","position","length","slice","getSize","close","fd","size","buf","allocBuffer","bytesRead","fs","readSync","closeSync","_e","source","signature","streamsInfo","filesInfo","entries","parsed","decompressedCache","filesPerFolder","extractedPerFolder","parse","sigBuf","SIGNATURE_HEADER_SIZE","createCodedError","ErrorCode","TRUNCATED_ARCHIVE","parseSignatureHeader","headerOffset","nextHeaderOffset","headerBuf","nextHeaderSize","headerResult","parseEncodedHeader","nextHeaderCRC","err","codedErr","code","COMPRESSED_HEADER","handleCompressedHeader","buildEntries","offset","propertyId","PropertyId","kMainStreamsInfo","kPackInfo","CORRUPT_HEADER","packInfoResult","parseEncodedHeaderStreams","compressedStart","packPos","compressedData","packSize","codec","getCodec","codecId","decompressedHeader","decode","properties","unpackSize","unpackCRC","undefined","actualCRC","crc32","packAreaEnd","searchStart","searchEnd","Math","max","scanChunkSize","searchLoop","chunkStart","chunk","i","min","candidateData","subarray","candidateDecompressed","candCRC","decompOffset","headerId","kHeader","result","parseHeaderContent","kEnd","packPosResult","readNumber","value","numPackResult","kSize","sizeResult","kUnpackInfo","kFolder","numFoldersResult","numCodersResult","flags","idSize","hasAttributes","push","propsLenResult","kCodersUnpackSize","unpackSizeResult","kCRC","allDefined","readUInt32LE","file","createEntry","streamsPerFolder","numUnpackStreamsPerFolder","f","streamIndex","folderIndex","streamInFolder","folderStreamCount","j","fileInfo","hasStream","unpackSizes","entry","_streamIndex","unpackCRCs","_crc","type","isDirectory","mode","attributes","FileAttribute","UNIX_EXTENSION","name","getBaseName","path","mtime","atime","ctime","isAntiFile","_folderIndex","_streamIndexInFolder","_hasStream","getEntries","getEntryStream","emptyStream","end","folder","folders","coders","coder","isCodecSupported","id","codecName","getCodecName","UNSUPPORTED_CODEC","folderIdx","data","getDecompressedFolder","fileStart","m","prevStreamGlobalIndex","fileSize","outputStream","DECOMPRESSION_FAILED","fileData","toString","CRC_MISMATCH","getEntryStreamAsync","callback","getDecompressedFolderAsync","Error","folderHasBcj2","isBcj2Codec","filesInFolder","extractedFromFolder","remainingFiles","shouldCache","decompressBcj2Folder","packStreamIndex","packedStreams","k","packSizes","packedData","data2","l","coderInfo","self","decompressWithStream","input","coderIdx","cb","decoder","createDecoder","chunks","errorOccurred","on","oo","Buffer","concat","decompressChain","idx","output","numPackStreams","packStreams","currentPos","p","coderOutputs","bcj2CoderIndex","c","inputToPackStream","pi","outputToCoder","totalOutputs","co","numOut","numOutStreams","outp","processed","processOrder","getCoderProcessOrder","po","coderInputStart","ci2","numInStreams","inputIdx","packStreamIdx","inputData","outputData","coderOutputStart","co2","bcj2InputStart","ci3","bcj2Inputs","bi","globalIdx","boundOutput","bp2","bindPairs","inIndex","outIndex","psIdx","bcj2OutputStart","co3","bcj2UnpackSize","key","decodeBcj2Multi","excludeIdx","order","changed","inputStart","canProcess","inp","bp","outIdx","outStart","oc","lastSlash","lastIndexOf","lastBackslash","lastSep"],"mappings":"AAAA,0CAA0C;AAC1C,+DAA+D;;;;;;;;;;;;QAwDlDA;eAAAA;;QAuBAC;eAAAA;;QAkCAC;eAAAA;;;mCA/GsB;yDACpB;4DACA;6DACI;uBACoE;2BAYwB;yBACqB;6BACzG;;;;;;;;;;;AAZ3B,uEAAuE;AACvE,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAIC;AACJ,IAAIL,QAAQ,GAAG;IACbK,cAAcC,eAAM,CAACD,WAAW;AAClC,OAAO;IACLA,cAAcE,QAAQ,mBAAmBF,WAAW;AACtD;AAyCO,IAAA,AAAMR,6BAAN;;aAAMA,aAGCW,MAAc;gCAHfX;QAIT,IAAI,CAACW,MAAM,GAAGA;;iBAJLX;IAOXY,OAAAA,IAEC,GAFDA,SAAAA,KAA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;CAEC,GACD,SAAS8I,YAAYC,IAAY;IAC/B,IAAM0H,YAAY1H,KAAK2H,WAAW,CAAC;IACnC,IAAMC,gBAAgB5H,KAAK2H,WAAW,CAAC;IACvC,IAAME,UAAU5L,KAAKC,GAAG,CAACwL,WAAWE;IACpC,OAAOC,WAAW,IAAI7H,KAAKlI,KAAK,CAAC+P,UAAU,KAAK7H;AAClD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/SevenZipParser.ts"],"sourcesContent":["/**\n * SevenZipParser - Main 7z archive parser\n *\n * Handles reading archive structure and providing file streams.\n *\n * Parser Flow:\n * 1. Read signature header (32 bytes) to get header location\n * 2. Read encoded header from nextHeaderOffset\n * 3. If header is compressed, decompress it first\n * 4. Parse streams info (folder structure, pack positions)\n * 5. Parse files info (names, sizes, attributes)\n * 6. Build entry list for iteration\n *\n * Decompression:\n * - 7z uses \"folders\" as decompression units\n * - Solid archives: multiple files share one folder (decompress once)\n * - Non-solid: one file per folder\n * - Supports LZMA, LZMA2, COPY, BCJ2, and other codecs\n */\n\nimport { crc32 } from 'extract-base-iterator';\nimport oo from 'on-one';\nimport Stream from 'stream';\nimport type { ArchiveSource } from './ArchiveSource.ts';\nimport { decodeBcj2Multi, getCodec, getCodecName, isBcj2Codec, isCodecSupported } from './codecs/index.ts';\n\n// Use native streams when available, readable-stream only for Node 0.x\nconst major = +process.versions.node.split('.')[0];\nlet PassThrough: typeof Stream.PassThrough;\nif (major > 0) {\n PassThrough = Stream.PassThrough;\n} else {\n PassThrough = require('readable-stream').PassThrough;\n}\ntype Readable = Stream.Readable;\n\nimport { type CodedError, createCodedError, ErrorCode, FileAttribute, PropertyId, SIGNATURE_HEADER_SIZE } from './constants.ts';\nimport { type FileInfo, parseEncodedHeader, parseHeaderContent, parseSignatureHeader, type SignatureHeader, type StreamsInfo } from './headers.ts';\nimport { readNumber } from './NumberCodec.ts';\n\n// Re-export for backwards compatibility\nexport { type ArchiveSource, BufferSource, FileSource } from './ArchiveSource.ts';\n\n// Callback type for async operations\ntype DecompressCallback = (err: Error | null, data?: Buffer) => void;\n\n// Entry type for iteration\nexport interface SevenZipEntry {\n name: string;\n path: string;\n type: 'file' | 'directory' | 'link';\n size: number;\n mtime?: Date;\n atime?: Date;\n ctime?: Date;\n mode?: number;\n isAntiFile: boolean;\n // Internal tracking\n _folderIndex: number;\n _streamIndex: number; // Global stream index\n _streamIndexInFolder: number; // Stream index within folder (for solid archives)\n _hasStream: boolean;\n _crc?: number; // Expected CRC32 for this file (if present in archive)\n}\n\n/**\n * SevenZipParser - parses 7z archives and provides entry iteration\n */\nexport class SevenZipParser {\n private source: ArchiveSource;\n private signature: SignatureHeader | null = null;\n private streamsInfo: StreamsInfo | null = null;\n private filesInfo: FileInfo[] = [];\n private entries: SevenZipEntry[] = [];\n private parsed = false;\n // Smart cache for decompressed solid blocks\n // Only caches when multiple files share a block, releases when last file extracted\n private decompressedCache: { [key: number]: Buffer } = {};\n // Track files per folder and how many have been extracted\n private filesPerFolder: { [key: number]: number } = {};\n private extractedPerFolder: { [key: number]: number } = {};\n\n constructor(source: ArchiveSource) {\n this.source = source;\n }\n\n /**\n * Parse the archive structure\n * Must be called before iterating entries\n */\n parse(): void {\n if (this.parsed) return;\n\n // Read signature header\n const sigBuf = this.source.read(0, SIGNATURE_HEADER_SIZE);\n if (sigBuf.length < SIGNATURE_HEADER_SIZE) {\n throw createCodedError('Archive too small', ErrorCode.TRUNCATED_ARCHIVE);\n }\n\n this.signature = parseSignatureHeader(sigBuf);\n\n // Read encoded header\n const headerOffset = SIGNATURE_HEADER_SIZE + this.signature.nextHeaderOffset;\n const headerBuf = this.source.read(headerOffset, this.signature.nextHeaderSize);\n\n if (headerBuf.length < this.signature.nextHeaderSize) {\n throw createCodedError('Truncated header', ErrorCode.TRUNCATED_ARCHIVE);\n }\n\n // Parse encoded header (may need decompression)\n try {\n const headerResult = parseEncodedHeader(headerBuf, this.signature.nextHeaderCRC);\n this.streamsInfo = headerResult.streamsInfo || null;\n this.filesInfo = headerResult.filesInfo;\n } catch (err: unknown) {\n const codedErr = err as CodedError;\n if (codedErr && codedErr.code === ErrorCode.COMPRESSED_HEADER) {\n // Header is compressed - need to decompress first\n this.handleCompressedHeader(headerBuf);\n } else {\n throw err;\n }\n }\n\n // Build entries list\n this.buildEntries();\n this.parsed = true;\n }\n\n /**\n * Handle compressed header (kEncodedHeader)\n */\n private handleCompressedHeader(headerBuf: Buffer): void {\n // Parse the encoded header info to get decompression parameters\n let offset = 1; // Skip kEncodedHeader byte\n\n // Should have StreamsInfo for the header itself\n const propertyId = headerBuf[offset++];\n if (propertyId !== PropertyId.kMainStreamsInfo && propertyId !== PropertyId.kPackInfo) {\n throw createCodedError('Expected StreamsInfo in encoded header', ErrorCode.CORRUPT_HEADER);\n }\n\n // For now, we parse the streams info from the encoded header block\n // This tells us how to decompress the actual header\n\n // Read pack info from the encoded header structure\n const packInfoResult = this.parseEncodedHeaderStreams(headerBuf, 1);\n\n // Calculate compressed header position\n // For simple archives: header is at SIGNATURE_HEADER_SIZE + packPos\n // For BCJ2/complex archives: header may be at the END of pack data area\n // The pack data area ends at nextHeaderOffset (where encoded header starts)\n const compressedStart = SIGNATURE_HEADER_SIZE + packInfoResult.packPos;\n const compressedData = this.source.read(compressedStart, packInfoResult.packSize);\n\n // Decompress using the specified codec\n const codec = getCodec(packInfoResult.codecId);\n let decompressedHeader: Buffer | null = null;\n\n // Try decompressing from the calculated position first\n try {\n decompressedHeader = codec.decode(compressedData, packInfoResult.properties, packInfoResult.unpackSize);\n // Verify CRC if present\n if (packInfoResult.unpackCRC !== undefined) {\n const actualCRC = crc32(decompressedHeader);\n if (actualCRC !== packInfoResult.unpackCRC) {\n decompressedHeader = null; // CRC mismatch, need to search\n }\n }\n } catch {\n decompressedHeader = null; // Decompression failed, need to search\n }\n\n // If initial decompression failed, search for the correct position as a fallback\n // This handles edge cases where packPos doesn't point directly to header pack data\n if (decompressedHeader === null && this.signature) {\n const packAreaEnd = SIGNATURE_HEADER_SIZE + this.signature.nextHeaderOffset;\n const searchStart = packAreaEnd - packInfoResult.packSize;\n const searchEnd = Math.max(SIGNATURE_HEADER_SIZE, compressedStart - 100000);\n\n // Scan for LZMA data starting with 0x00 (range coder init)\n // Try each candidate and validate with CRC\n const scanChunkSize = 4096;\n searchLoop: for (let chunkStart = searchStart; chunkStart >= searchEnd; chunkStart -= scanChunkSize) {\n const chunk = this.source.read(chunkStart, scanChunkSize + packInfoResult.packSize);\n for (let i = 0; i < Math.min(chunk.length, scanChunkSize); i++) {\n if (chunk[i] === 0x00) {\n const candidateData = chunk.subarray(i, i + packInfoResult.packSize);\n if (candidateData.length === packInfoResult.packSize) {\n try {\n const candidateDecompressed = codec.decode(candidateData, packInfoResult.properties, packInfoResult.unpackSize);\n if (packInfoResult.unpackCRC !== undefined) {\n const candCRC = crc32(candidateDecompressed);\n if (candCRC === packInfoResult.unpackCRC) {\n decompressedHeader = candidateDecompressed;\n break searchLoop;\n }\n } else {\n decompressedHeader = candidateDecompressed;\n break searchLoop;\n }\n } catch {\n // Decompression failed, continue searching\n }\n }\n }\n }\n }\n }\n\n if (decompressedHeader === null) {\n throw createCodedError('Failed to decompress header - could not find valid LZMA data', ErrorCode.CORRUPT_HEADER);\n }\n\n // Now parse the decompressed header\n // It should start with kHeader\n let decompOffset = 0;\n const headerId = decompressedHeader[decompOffset++];\n if (headerId !== PropertyId.kHeader) {\n throw createCodedError('Expected kHeader in decompressed header', ErrorCode.CORRUPT_HEADER);\n }\n\n // Parse the decompressed header using shared function from headers.ts\n const result = parseHeaderContent(decompressedHeader, decompOffset);\n this.streamsInfo = result.streamsInfo || null;\n this.filesInfo = result.filesInfo;\n }\n\n /**\n * Parse streams info from encoded header block\n * This is a simplified parser for the header's own compression info\n */\n private parseEncodedHeaderStreams(\n buf: Buffer,\n offset: number\n ): {\n packPos: number;\n packSize: number;\n unpackSize: number;\n codecId: number[];\n properties?: Buffer;\n unpackCRC?: number;\n } {\n // This is a simplified parser for the encoded header's own streams info\n let packPos = 0;\n let packSize = 0;\n let unpackSize = 0;\n let codecId: number[] = [];\n let properties: Buffer | undefined;\n let unpackCRC: number | undefined;\n\n while (offset < buf.length) {\n const propertyId = buf[offset++];\n\n if (propertyId === PropertyId.kEnd) {\n break;\n }\n\n switch (propertyId) {\n case PropertyId.kPackInfo: {\n const packPosResult = readNumber(buf, offset);\n packPos = packPosResult.value;\n offset += packPosResult.bytesRead;\n\n const numPackResult = readNumber(buf, offset);\n offset += numPackResult.bytesRead;\n\n // Read until kEnd\n while (buf[offset] !== PropertyId.kEnd) {\n if (buf[offset] === PropertyId.kSize) {\n offset++;\n const sizeResult = readNumber(buf, offset);\n packSize = sizeResult.value;\n offset += sizeResult.bytesRead;\n } else {\n offset++;\n }\n }\n offset++; // Skip kEnd\n break;\n }\n\n case PropertyId.kUnpackInfo:\n // Find folder/coder info\n while (offset < buf.length && buf[offset] !== PropertyId.kEnd) {\n if (buf[offset] === PropertyId.kFolder) {\n offset++;\n const numFoldersResult = readNumber(buf, offset);\n offset += numFoldersResult.bytesRead;\n offset++; // external flag\n\n // Parse coder\n const numCodersResult = readNumber(buf, offset);\n offset += numCodersResult.bytesRead;\n\n const flags = buf[offset++];\n const idSize = flags & 0x0f;\n const hasAttributes = (flags & 0x20) !== 0;\n\n codecId = [];\n for (let i = 0; i < idSize; i++) {\n codecId.push(buf[offset++]);\n }\n\n if (hasAttributes) {\n const propsLenResult = readNumber(buf, offset);\n offset += propsLenResult.bytesRead;\n properties = buf.slice(offset, offset + propsLenResult.value);\n offset += propsLenResult.value;\n }\n } else if (buf[offset] === PropertyId.kCodersUnpackSize) {\n offset++;\n // Read unpack size - needed for LZMA decoder\n const unpackSizeResult = readNumber(buf, offset);\n unpackSize = unpackSizeResult.value;\n offset += unpackSizeResult.bytesRead;\n } else if (buf[offset] === PropertyId.kCRC) {\n offset++;\n const allDefined = buf[offset++];\n if (allDefined) {\n unpackCRC = buf.readUInt32LE(offset);\n offset += 4;\n }\n } else {\n offset++;\n }\n }\n if (buf[offset] === PropertyId.kEnd) offset++;\n break;\n }\n }\n\n return { packPos: packPos, packSize: packSize, unpackSize: unpackSize, codecId: codecId, properties: properties, unpackCRC: unpackCRC };\n }\n\n /**\n * Build the entries list from parsed file info\n */\n private buildEntries(): void {\n this.entries = [];\n\n if (!this.streamsInfo) {\n // No streams info - just create entries from file info\n for (let i = 0; i < this.filesInfo.length; i++) {\n const file = this.filesInfo[i];\n this.entries.push(this.createEntry(file, 0, 0, 0));\n }\n return;\n }\n\n // Use the properly parsed numUnpackStreamsPerFolder from the archive header\n const streamsPerFolder = this.streamsInfo.numUnpackStreamsPerFolder;\n\n // Initialize files per folder count (for smart caching)\n for (let f = 0; f < streamsPerFolder.length; f++) {\n this.filesPerFolder[f] = streamsPerFolder[f];\n this.extractedPerFolder[f] = 0;\n }\n\n // Now build entries with proper folder/stream tracking\n let streamIndex = 0;\n let folderIndex = 0;\n let streamInFolder = 0;\n let folderStreamCount = streamsPerFolder[0] || 0;\n\n for (let j = 0; j < this.filesInfo.length; j++) {\n const fileInfo = this.filesInfo[j];\n\n // Get size from unpackSizes for files with streams\n let size = 0;\n if (fileInfo.hasStream && streamIndex < this.streamsInfo.unpackSizes.length) {\n size = this.streamsInfo.unpackSizes[streamIndex];\n }\n\n const entry = this.createEntry(fileInfo, size, folderIndex, streamInFolder);\n entry._streamIndex = streamIndex;\n // Set CRC if available\n if (fileInfo.hasStream && this.streamsInfo.unpackCRCs && this.streamsInfo.unpackCRCs[streamIndex] !== undefined) {\n entry._crc = this.streamsInfo.unpackCRCs[streamIndex];\n }\n this.entries.push(entry);\n\n // Advance stream tracking for files with streams\n if (fileInfo.hasStream) {\n streamIndex++;\n streamInFolder++;\n\n // Check if we've exhausted streams in this folder\n if (streamInFolder >= folderStreamCount) {\n folderIndex++;\n streamInFolder = 0;\n folderStreamCount = streamsPerFolder[folderIndex] || 0;\n }\n }\n }\n }\n\n /**\n * Create an entry from file info\n */\n private createEntry(file: FileInfo, size: number, folderIndex: number, streamInFolder: number): SevenZipEntry {\n // Determine entry type\n // Note: 7z format doesn't natively support symlinks. p7zip with -snl stores\n // symlinks as regular files with the target path as content.\n let type: 'file' | 'directory' | 'link' = 'file';\n if (file.isDirectory) {\n type = 'directory';\n }\n\n // Calculate mode from Windows attributes\n let mode: number | undefined;\n if (file.attributes !== undefined) {\n // Check for Unix extension bit\n if ((file.attributes & FileAttribute.UNIX_EXTENSION) !== 0) {\n mode = (file.attributes >>> 16) & 0xffff;\n // Check for symlink (S_IFLNK = 0xA000)\n // Note: Most 7z implementations don't preserve symlink mode bits\n if ((mode & 0xf000) === 0xa000) {\n type = 'link';\n }\n } else if (file.isDirectory) {\n mode = 493; // 0o755\n } else {\n mode = 420; // 0o644\n }\n }\n\n return {\n name: getBaseName(file.name),\n path: file.name,\n type: type,\n size: size,\n mtime: file.mtime,\n atime: file.atime,\n ctime: file.ctime,\n mode: mode,\n isAntiFile: file.isAntiFile,\n _folderIndex: folderIndex,\n _streamIndex: 0, // Set by caller\n _streamIndexInFolder: streamInFolder,\n _hasStream: file.hasStream,\n };\n }\n\n /**\n * Get the list of entries\n */\n getEntries(): SevenZipEntry[] {\n if (!this.parsed) {\n this.parse();\n }\n return this.entries;\n }\n\n /**\n * Get a readable stream for an entry's content\n */\n getEntryStream(entry: SevenZipEntry): Readable {\n if (!entry._hasStream || entry.type === 'directory') {\n // Return empty stream for directories and empty files\n const emptyStream = new PassThrough();\n emptyStream.end();\n return emptyStream;\n }\n\n if (!this.streamsInfo) {\n throw createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER);\n }\n\n // Get folder info\n const folder = this.streamsInfo.folders[entry._folderIndex];\n if (!folder) {\n throw createCodedError('Invalid folder index', ErrorCode.CORRUPT_HEADER);\n }\n\n // Check codec support\n for (let i = 0; i < folder.coders.length; i++) {\n const coder = folder.coders[i];\n if (!isCodecSupported(coder.id)) {\n const codecName = getCodecName(coder.id);\n throw createCodedError(`Unsupported codec: ${codecName}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n }\n\n // Get decompressed data for this folder (with smart caching)\n const folderIdx = entry._folderIndex;\n const data = this.getDecompressedFolder(folderIdx);\n\n // Calculate file offset within the decompressed block\n // For solid archives, multiple files are concatenated in the block\n let fileStart = 0;\n for (let m = 0; m < entry._streamIndexInFolder; m++) {\n // Sum sizes of all streams before this one in the folder\n const prevStreamGlobalIndex = entry._streamIndex - entry._streamIndexInFolder + m;\n fileStart += this.streamsInfo.unpackSizes[prevStreamGlobalIndex];\n }\n\n const fileSize = entry.size;\n\n // Create a PassThrough stream with the file data\n const outputStream = new PassThrough();\n\n // Bounds check to prevent \"oob\" error on older Node versions\n if (fileStart + fileSize > data.length) {\n throw createCodedError(`File data out of bounds: offset ${fileStart} + size ${fileSize} > decompressed length ${data.length}`, ErrorCode.DECOMPRESSION_FAILED);\n }\n\n const fileData = data.slice(fileStart, fileStart + fileSize);\n\n // Verify CRC if present\n if (entry._crc !== undefined) {\n const actualCRC = crc32(fileData);\n if (actualCRC !== entry._crc) {\n throw createCodedError(`CRC mismatch for ${entry.path}: expected ${entry._crc.toString(16)}, got ${actualCRC.toString(16)}`, ErrorCode.CRC_MISMATCH);\n }\n }\n\n outputStream.end(fileData);\n\n // Track extraction and release cache when all files from this folder are done\n this.extractedPerFolder[folderIdx] = (this.extractedPerFolder[folderIdx] || 0) + 1;\n if (this.extractedPerFolder[folderIdx] >= this.filesPerFolder[folderIdx]) {\n // All files from this folder extracted, release cache\n delete this.decompressedCache[folderIdx];\n }\n\n return outputStream;\n }\n\n /**\n * Get a readable stream for an entry's content (callback-based async version)\n * Uses streaming decompression for non-blocking I/O\n */\n getEntryStreamAsync(entry: SevenZipEntry, callback: (err: Error | null, stream?: Readable) => void): void {\n if (!entry._hasStream || entry.type === 'directory') {\n // Return empty stream for directories and empty files\n const emptyStream = new PassThrough();\n emptyStream.end();\n callback(null, emptyStream);\n return;\n }\n\n if (!this.streamsInfo) {\n callback(createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER));\n return;\n }\n\n // Get folder info\n const folder = this.streamsInfo.folders[entry._folderIndex];\n if (!folder) {\n callback(createCodedError('Invalid folder index', ErrorCode.CORRUPT_HEADER));\n return;\n }\n\n // Check codec support\n for (let i = 0; i < folder.coders.length; i++) {\n const coder = folder.coders[i];\n if (!isCodecSupported(coder.id)) {\n const codecName = getCodecName(coder.id);\n callback(createCodedError(`Unsupported codec: ${codecName}`, ErrorCode.UNSUPPORTED_CODEC));\n return;\n }\n }\n\n // Get decompressed data for this folder using async method\n const folderIdx = entry._folderIndex;\n const streamsInfo = this.streamsInfo;\n\n this.getDecompressedFolderAsync(folderIdx, (err, data) => {\n if (err) return callback(err);\n if (!data) return callback(new Error('No data returned from decompression'));\n\n // Calculate file offset within the decompressed block\n let fileStart = 0;\n for (let m = 0; m < entry._streamIndexInFolder; m++) {\n const prevStreamGlobalIndex = entry._streamIndex - entry._streamIndexInFolder + m;\n fileStart += streamsInfo.unpackSizes[prevStreamGlobalIndex];\n }\n\n const fileSize = entry.size;\n\n // Bounds check\n if (fileStart + fileSize > data.length) {\n return callback(createCodedError(`File data out of bounds: offset ${fileStart} + size ${fileSize} > decompressed length ${data.length}`, ErrorCode.DECOMPRESSION_FAILED));\n }\n\n // Create a PassThrough stream with the file data\n const outputStream = new PassThrough();\n const fileData = data.slice(fileStart, fileStart + fileSize);\n\n // Verify CRC if present\n if (entry._crc !== undefined) {\n const actualCRC = crc32(fileData);\n if (actualCRC !== entry._crc) {\n return callback(createCodedError(`CRC mismatch for ${entry.path}: expected ${entry._crc.toString(16)}, got ${actualCRC.toString(16)}`, ErrorCode.CRC_MISMATCH));\n }\n }\n\n outputStream.end(fileData);\n\n // Track extraction and release cache when all files from this folder are done\n this.extractedPerFolder[folderIdx] = (this.extractedPerFolder[folderIdx] || 0) + 1;\n if (this.extractedPerFolder[folderIdx] >= this.filesPerFolder[folderIdx]) {\n delete this.decompressedCache[folderIdx];\n }\n\n callback(null, outputStream);\n });\n }\n\n /**\n * Check if a folder uses BCJ2 codec\n */\n private folderHasBcj2(folder: { coders: { id: number[] }[] }): boolean {\n for (let i = 0; i < folder.coders.length; i++) {\n if (isBcj2Codec(folder.coders[i].id)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Get decompressed data for a folder, with smart caching for solid archives\n * Only caches when multiple files share a block, releases when last file extracted\n */\n private getDecompressedFolder(folderIndex: number): Buffer {\n // Check cache first\n if (this.decompressedCache[folderIndex]) {\n return this.decompressedCache[folderIndex];\n }\n\n if (!this.streamsInfo) {\n throw createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER);\n }\n\n const folder = this.streamsInfo.folders[folderIndex];\n\n // Check how many files remain in this folder\n const filesInFolder = this.filesPerFolder[folderIndex] || 1;\n const extractedFromFolder = this.extractedPerFolder[folderIndex] || 0;\n const remainingFiles = filesInFolder - extractedFromFolder;\n // Only cache if more than 1 file remains (including the current one being extracted)\n const shouldCache = remainingFiles > 1;\n\n // Check if this folder uses BCJ2 (requires special multi-stream handling)\n if (this.folderHasBcj2(folder)) {\n const data = this.decompressBcj2Folder(folderIndex);\n if (shouldCache) {\n this.decompressedCache[folderIndex] = data;\n }\n return data;\n }\n\n // Calculate packed data position\n let packPos = SIGNATURE_HEADER_SIZE + this.streamsInfo.packPos;\n\n // Find which pack stream this folder uses\n let packStreamIndex = 0;\n for (let j = 0; j < folderIndex; j++) {\n packStreamIndex += this.streamsInfo.folders[j].packedStreams.length;\n }\n\n // Calculate position of this pack stream\n for (let k = 0; k < packStreamIndex; k++) {\n packPos += this.streamsInfo.packSizes[k];\n }\n\n const packSize = this.streamsInfo.packSizes[packStreamIndex];\n\n // Read packed data\n const packedData = this.source.read(packPos, packSize);\n\n // Decompress through codec chain\n let data2 = packedData;\n for (let l = 0; l < folder.coders.length; l++) {\n const coderInfo = folder.coders[l];\n const codec = getCodec(coderInfo.id);\n // Get unpack size for this coder (needed by LZMA)\n const unpackSize = folder.unpackSizes[l];\n data2 = codec.decode(data2, coderInfo.properties, unpackSize);\n }\n\n // Cache only if more files remain in this folder\n if (shouldCache) {\n this.decompressedCache[folderIndex] = data2;\n }\n\n return data2;\n }\n\n /**\n * Get decompressed data for a folder using streaming (callback-based async)\n * Uses createDecoder() streams for non-blocking decompression\n */\n private getDecompressedFolderAsync(folderIndex: number, callback: DecompressCallback): void {\n const self = this;\n\n // Check cache first\n if (this.decompressedCache[folderIndex]) {\n callback(null, this.decompressedCache[folderIndex]);\n return;\n }\n\n if (!this.streamsInfo) {\n callback(createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER));\n return;\n }\n\n const folder = this.streamsInfo.folders[folderIndex];\n\n // Check how many files remain in this folder\n const filesInFolder = this.filesPerFolder[folderIndex] || 1;\n const extractedFromFolder = this.extractedPerFolder[folderIndex] || 0;\n const remainingFiles = filesInFolder - extractedFromFolder;\n const shouldCache = remainingFiles > 1;\n\n // BCJ2 requires special handling - use sync version for now\n // TODO: Add async BCJ2 support\n if (this.folderHasBcj2(folder)) {\n try {\n const data = this.decompressBcj2Folder(folderIndex);\n if (shouldCache) {\n this.decompressedCache[folderIndex] = data;\n }\n callback(null, data);\n } catch (err) {\n callback(err as Error);\n }\n return;\n }\n\n // Calculate packed data position\n let packPos = SIGNATURE_HEADER_SIZE + this.streamsInfo.packPos;\n\n // Find which pack stream this folder uses\n let packStreamIndex = 0;\n for (let j = 0; j < folderIndex; j++) {\n packStreamIndex += this.streamsInfo.folders[j].packedStreams.length;\n }\n\n // Calculate position of this pack stream\n for (let k = 0; k < packStreamIndex; k++) {\n packPos += this.streamsInfo.packSizes[k];\n }\n\n const packSize = this.streamsInfo.packSizes[packStreamIndex];\n\n // Read packed data\n const packedData = this.source.read(packPos, packSize);\n\n // Create decoder stream chain and decompress\n const coders = folder.coders;\n const unpackSizes = folder.unpackSizes;\n\n // Helper to decompress through a single codec stream\n function decompressWithStream(input: Buffer, coderIdx: number, cb: DecompressCallback): void {\n const coderInfo = coders[coderIdx];\n const codec = getCodec(coderInfo.id);\n const decoder = codec.createDecoder(coderInfo.properties, unpackSizes[coderIdx]);\n\n const chunks: Buffer[] = [];\n let errorOccurred = false;\n\n decoder.on('data', (chunk: Buffer) => {\n chunks.push(chunk);\n });\n\n oo(decoder, ['error', 'end', 'close', 'finish'], (err?: Error) => {\n if (errorOccurred) return;\n if (err) {\n errorOccurred = true;\n return cb(err);\n }\n cb(null, Buffer.concat(chunks));\n });\n\n // Write input data to decoder and signal end\n decoder.end(input);\n }\n\n // Chain decompression through all codecs\n function decompressChain(input: Buffer, idx: number): void {\n if (idx >= coders.length) {\n // All done - cache and return\n if (shouldCache) {\n self.decompressedCache[folderIndex] = input;\n }\n callback(null, input);\n return;\n }\n\n decompressWithStream(input, idx, (err, output) => {\n if (err) {\n callback(err);\n return;\n }\n decompressChain(output as Buffer, idx + 1);\n });\n }\n\n // Start the chain\n decompressChain(packedData, 0);\n }\n\n /**\n * Decompress a BCJ2 folder with multi-stream handling\n * BCJ2 uses 4 input streams: main, call, jump, range coder\n */\n private decompressBcj2Folder(folderIndex: number): Buffer {\n if (!this.streamsInfo) {\n throw createCodedError('No streams info available', ErrorCode.CORRUPT_HEADER);\n }\n\n const folder = this.streamsInfo.folders[folderIndex];\n\n // Calculate starting pack position\n let packPos = SIGNATURE_HEADER_SIZE + this.streamsInfo.packPos;\n\n // Find which pack stream index this folder starts at\n let packStreamIndex = 0;\n for (let j = 0; j < folderIndex; j++) {\n packStreamIndex += this.streamsInfo.folders[j].packedStreams.length;\n }\n\n // Calculate position\n for (let k = 0; k < packStreamIndex; k++) {\n packPos += this.streamsInfo.packSizes[k];\n }\n\n // Read all pack streams for this folder\n const numPackStreams = folder.packedStreams.length;\n const packStreams: Buffer[] = [];\n let currentPos = packPos;\n\n for (let p = 0; p < numPackStreams; p++) {\n const size = this.streamsInfo.packSizes[packStreamIndex + p];\n packStreams.push(this.source.read(currentPos, size));\n currentPos += size;\n }\n\n // Build a map of coder outputs\n // For BCJ2, typical structure is:\n // Coder 0: LZMA2 (main stream) - 1 in, 1 out\n // Coder 1: LZMA (call stream) - 1 in, 1 out\n // Coder 2: LZMA (jump stream) - 1 in, 1 out\n // Coder 3: BCJ2 - 4 in, 1 out\n // Pack streams map to: coder inputs not bound to other coder outputs\n\n // First, decompress each non-BCJ2 coder\n const coderOutputs: { [key: number]: Buffer } = {};\n\n // Find the BCJ2 coder\n let bcj2CoderIndex = -1;\n for (let c = 0; c < folder.coders.length; c++) {\n if (isBcj2Codec(folder.coders[c].id)) {\n bcj2CoderIndex = c;\n break;\n }\n }\n\n if (bcj2CoderIndex === -1) {\n throw createCodedError('BCJ2 coder not found in folder', ErrorCode.CORRUPT_HEADER);\n }\n\n // Build input stream index -> pack stream mapping\n // folder.packedStreams tells us which input indices are unbound and their order\n const inputToPackStream: { [key: number]: number } = {};\n for (let pi = 0; pi < folder.packedStreams.length; pi++) {\n inputToPackStream[folder.packedStreams[pi]] = pi;\n }\n\n // Build output stream index -> coder mapping\n const outputToCoder: { [key: number]: number } = {};\n let totalOutputs = 0;\n for (let co = 0; co < folder.coders.length; co++) {\n const numOut = folder.coders[co].numOutStreams;\n for (let outp = 0; outp < numOut; outp++) {\n outputToCoder[totalOutputs + outp] = co;\n }\n totalOutputs += numOut;\n }\n\n // Decompress non-BCJ2 coders (LZMA, LZMA2)\n // We need to process in dependency order\n const processed: { [key: number]: boolean } = {};\n\n const processOrder = this.getCoderProcessOrder(folder, bcj2CoderIndex);\n\n for (let po = 0; po < processOrder.length; po++) {\n const coderIdx = processOrder[po];\n if (coderIdx === bcj2CoderIndex) continue;\n\n const coder = folder.coders[coderIdx];\n const codec = getCodec(coder.id);\n\n // Find input for this coder\n let coderInputStart = 0;\n for (let ci2 = 0; ci2 < coderIdx; ci2++) {\n coderInputStart += folder.coders[ci2].numInStreams;\n }\n\n // Get input data (from pack stream)\n const inputIdx = coderInputStart;\n const packStreamIdx = inputToPackStream[inputIdx];\n const inputData = packStreams[packStreamIdx];\n\n // Decompress\n const unpackSize = folder.unpackSizes[coderIdx];\n const outputData = codec.decode(inputData, coder.properties, unpackSize);\n\n // Store in coder outputs\n let coderOutputStart = 0;\n for (let co2 = 0; co2 < coderIdx; co2++) {\n coderOutputStart += folder.coders[co2].numOutStreams;\n }\n coderOutputs[coderOutputStart] = outputData;\n processed[coderIdx] = true;\n }\n\n // Now process BCJ2\n // BCJ2 has 4 inputs, need to map them correctly\n // Standard order: main(LZMA2 output), call(LZMA output), jump(LZMA output), range(raw pack)\n let bcj2InputStart = 0;\n for (let ci3 = 0; ci3 < bcj2CoderIndex; ci3++) {\n bcj2InputStart += folder.coders[ci3].numInStreams;\n }\n\n const bcj2Inputs: Buffer[] = [];\n for (let bi = 0; bi < 4; bi++) {\n const globalIdx = bcj2InputStart + bi;\n\n // Check if this input is bound to a coder output\n let boundOutput = -1;\n for (let bp2 = 0; bp2 < folder.bindPairs.length; bp2++) {\n if (folder.bindPairs[bp2].inIndex === globalIdx) {\n boundOutput = folder.bindPairs[bp2].outIndex;\n break;\n }\n }\n\n if (boundOutput >= 0) {\n // Get from coder outputs\n bcj2Inputs.push(coderOutputs[boundOutput]);\n } else {\n // Get from pack streams\n const psIdx = inputToPackStream[globalIdx];\n bcj2Inputs.push(packStreams[psIdx]);\n }\n }\n\n // Get BCJ2 unpack size\n let bcj2OutputStart = 0;\n for (let co3 = 0; co3 < bcj2CoderIndex; co3++) {\n bcj2OutputStart += folder.coders[co3].numOutStreams;\n }\n const bcj2UnpackSize = folder.unpackSizes[bcj2OutputStart];\n\n // Memory optimization: Clear intermediate buffers to help GC\n // These are no longer needed after bcj2Inputs is built\n for (const key in coderOutputs) {\n delete coderOutputs[key];\n }\n // Clear packStreams array (allows GC to free compressed data)\n packStreams.length = 0;\n\n // Decode BCJ2\n return decodeBcj2Multi(bcj2Inputs, undefined, bcj2UnpackSize);\n }\n\n /**\n * Get processing order for coders (dependency order)\n */\n private getCoderProcessOrder(folder: { coders: { numInStreams: number; numOutStreams: number }[]; bindPairs: { inIndex: number; outIndex: number }[] }, excludeIdx: number): number[] {\n const order: number[] = [];\n const processed: { [key: number]: boolean } = {};\n\n // Simple approach: process coders that don't depend on unprocessed outputs\n let changed = true;\n while (changed) {\n changed = false;\n for (let c = 0; c < folder.coders.length; c++) {\n if (processed[c] || c === excludeIdx) continue;\n\n // Check if all inputs are satisfied\n let inputStart = 0;\n for (let i = 0; i < c; i++) {\n inputStart += folder.coders[i].numInStreams;\n }\n\n let canProcess = true;\n for (let inp = 0; inp < folder.coders[c].numInStreams; inp++) {\n const globalIdx = inputStart + inp;\n // Check if bound to an unprocessed coder\n for (let bp = 0; bp < folder.bindPairs.length; bp++) {\n if (folder.bindPairs[bp].inIndex === globalIdx) {\n // Find which coder produces this output\n const outIdx = folder.bindPairs[bp].outIndex;\n let outStart = 0;\n for (let oc = 0; oc < folder.coders.length; oc++) {\n const numOut = folder.coders[oc].numOutStreams;\n if (outIdx < outStart + numOut) {\n if (!processed[oc] && oc !== excludeIdx) {\n canProcess = false;\n }\n break;\n }\n outStart += numOut;\n }\n }\n }\n }\n\n if (canProcess) {\n order.push(c);\n processed[c] = true;\n changed = true;\n }\n }\n }\n\n return order;\n }\n\n /**\n * Close the parser and release resources\n */\n close(): void {\n if (this.source) {\n this.source.close();\n }\n }\n}\n\n/**\n * Get base name from a path\n */\nfunction getBaseName(path: string): string {\n const lastSlash = path.lastIndexOf('/');\n const lastBackslash = path.lastIndexOf('\\\\');\n const lastSep = Math.max(lastSlash, lastBackslash);\n return lastSep >= 0 ? path.slice(lastSep + 1) : path;\n}\n"],"names":["BufferSource","FileSource","SevenZipParser","major","process","versions","node","split","PassThrough","Stream","require","source","signature","streamsInfo","filesInfo","entries","parsed","decompressedCache","filesPerFolder","extractedPerFolder","parse","sigBuf","read","SIGNATURE_HEADER_SIZE","length","createCodedError","ErrorCode","TRUNCATED_ARCHIVE","parseSignatureHeader","headerOffset","nextHeaderOffset","headerBuf","nextHeaderSize","headerResult","parseEncodedHeader","nextHeaderCRC","err","codedErr","code","COMPRESSED_HEADER","handleCompressedHeader","buildEntries","offset","propertyId","PropertyId","kMainStreamsInfo","kPackInfo","CORRUPT_HEADER","packInfoResult","parseEncodedHeaderStreams","compressedStart","packPos","compressedData","packSize","codec","getCodec","codecId","decompressedHeader","decode","properties","unpackSize","unpackCRC","undefined","actualCRC","crc32","packAreaEnd","searchStart","searchEnd","Math","max","scanChunkSize","searchLoop","chunkStart","chunk","i","min","candidateData","subarray","candidateDecompressed","candCRC","decompOffset","headerId","kHeader","result","parseHeaderContent","buf","kEnd","packPosResult","readNumber","value","bytesRead","numPackResult","kSize","sizeResult","kUnpackInfo","kFolder","numFoldersResult","numCodersResult","flags","idSize","hasAttributes","push","propsLenResult","slice","kCodersUnpackSize","unpackSizeResult","kCRC","allDefined","readUInt32LE","file","createEntry","streamsPerFolder","numUnpackStreamsPerFolder","f","streamIndex","folderIndex","streamInFolder","folderStreamCount","j","fileInfo","size","hasStream","unpackSizes","entry","_streamIndex","unpackCRCs","_crc","type","isDirectory","mode","attributes","FileAttribute","UNIX_EXTENSION","name","getBaseName","path","mtime","atime","ctime","isAntiFile","_folderIndex","_streamIndexInFolder","_hasStream","getEntries","getEntryStream","emptyStream","end","folder","folders","coders","coder","isCodecSupported","id","codecName","getCodecName","UNSUPPORTED_CODEC","folderIdx","data","getDecompressedFolder","fileStart","m","prevStreamGlobalIndex","fileSize","outputStream","DECOMPRESSION_FAILED","fileData","toString","CRC_MISMATCH","getEntryStreamAsync","callback","getDecompressedFolderAsync","Error","folderHasBcj2","isBcj2Codec","filesInFolder","extractedFromFolder","remainingFiles","shouldCache","decompressBcj2Folder","packStreamIndex","packedStreams","k","packSizes","packedData","data2","l","coderInfo","self","decompressWithStream","input","coderIdx","cb","decoder","createDecoder","chunks","errorOccurred","on","oo","Buffer","concat","decompressChain","idx","output","numPackStreams","packStreams","currentPos","p","coderOutputs","bcj2CoderIndex","c","inputToPackStream","pi","outputToCoder","totalOutputs","co","numOut","numOutStreams","outp","processed","processOrder","getCoderProcessOrder","po","coderInputStart","ci2","numInStreams","inputIdx","packStreamIdx","inputData","outputData","coderOutputStart","co2","bcj2InputStart","ci3","bcj2Inputs","bi","globalIdx","boundOutput","bp2","bindPairs","inIndex","outIndex","psIdx","bcj2OutputStart","co3","bcj2UnpackSize","key","decodeBcj2Multi","excludeIdx","order","changed","inputStart","canProcess","inp","bp","outIdx","outStart","oc","close","lastSlash","lastIndexOf","lastBackslash","lastSep"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;CAkBC;;;;;;;;;;;QAuB4BA;eAAAA,6BAAY;;QAAEC;eAAAA,2BAAU;;QA2BxCC;eAAAA;;;mCAhDS;4DACP;6DACI;uBAEoE;2BAYwB;yBACqB;6BACzG;+BAGkC;;;;;;;;;;;AAf7D,uEAAuE;AACvE,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAIC;AACJ,IAAIL,QAAQ,GAAG;IACbK,cAAcC,eAAM,CAACD,WAAW;AAClC,OAAO;IACLA,cAAcE,QAAQ,mBAAmBF,WAAW;AACtD;AAmCO,IAAA,AAAMN,+BAAN;;aAAMA,eAcCS,MAAqB;gCAdtBT;aAEHU,YAAoC;aACpCC,cAAkC;aAClCC,YAAwB,EAAE;aAC1BC,UAA2B,EAAE;aAC7BC,SAAS;QACjB,4CAA4C;QAC5C,mFAAmF;aAC3EC,oBAA+C,CAAC;QACxD,0DAA0D;aAClDC,iBAA4C,CAAC;aAC7CC,qBAAgD,CAAC;QAGvD,IAAI,CAACR,MAAM,GAAGA;;iBAfLT;IAkBX;;;GAGC,GACDkB,OAAAA,KAqCC,GArCDA,SAAAA;QACE,IAAI,IAAI,CAACJ,MAAM,EAAE;QAEjB,wBAAwB;QACxB,IAAMK,SAAS,IAAI,CAACV,MAAM,CAACW,IAAI,CAAC,GAAGC,kCAAqB;QACxD,IAAIF,OAAOG,MAAM,GAAGD,kCAAqB,EAAE;YACzC,MAAME,IAAAA,6BAAgB,EAAC,q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
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Aes.ts"],"sourcesContent":["// 7z AES-256-CBC codec with SHA-256 key derivation\n// Implements password-based decryption for encrypted 7z archives\n//\n// Properties format:\n// Byte 0: bits 0-5 = NumCyclesPower (iterations = 2^NumCyclesPower)\n// bit 6 = IV present flag\n// bit 7 = Salt present flag\n// Byte 1: upper nibble = salt size extension\n// lower nibble = IV size extension\n// Following bytes: salt data, then IV data\n//\n// Key derivation:\n// For each round (2^NumCyclesPower times):\n// hash = SHA256(salt + password_utf16le + round_counter_8bytes)\n// Final key = first 32 bytes of accumulated hash\n\nimport crypto from 'crypto';\nimport { allocBuffer, bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\n\n// Global password storage - set before decryption\nlet _password: string | null = null;\n\n/**\n * Set the password for AES decryption\n */\nexport function setPassword(password: string | null): void {\n _password = password;\n}\n\n/**\n * Get the current password\n */\nexport function getPassword(): string | null {\n return _password;\n}\n\n/**\n * Parse AES properties to extract key derivation parameters\n */\nfunction parseProperties(properties: Buffer): { numCyclesPower: number; salt: Buffer; iv: Buffer } {\n if (!properties || properties.length < 1) {\n throw new Error('AES: missing properties');\n }\n\n const b0 = properties[0];\n const numCyclesPower = b0 & 0x3f;\n\n // Check for special case: no salt/IV flags\n if ((b0 & 0xc0) === 0) {\n // No salt, no IV - use zeros\n return {\n numCyclesPower: numCyclesPower,\n salt: allocBuffer(0),\n iv: allocBuffer(16),\n };\n }\n\n if (properties.length < 2) {\n throw new Error('AES: properties too short');\n }\n\n const b1 = properties[1];\n\n // Calculate sizes\n // saltSize = ((b0 >> 7) & 1) + (b1 >> 4)\n // ivSize = ((b0 >> 6) & 1) + (b1 & 0x0F)\n const saltSize = ((b0 >>> 7) & 1) + (b1 >>> 4);\n const ivSize = ((b0 >>> 6) & 1) + (b1 & 0x0f);\n\n const expectedSize = 2 + saltSize + ivSize;\n if (properties.length < expectedSize) {\n throw new Error('AES: properties too short for salt/IV');\n }\n\n const salt = properties.slice(2, 2 + saltSize);\n const iv = allocBuffer(16);\n\n // Copy IV data (may be less than 16 bytes, rest is zeros)\n const ivData = properties.slice(2 + saltSize, 2 + saltSize + ivSize);\n for (let i = 0; i < ivData.length && i < 16; i++) {\n iv[i] = ivData[i];\n }\n\n return {\n numCyclesPower: numCyclesPower,\n salt: salt,\n iv: iv,\n };\n}\n\n/**\n * Convert password string to UTF-16LE buffer\n */\nfunction passwordToUtf16LE(password: string): Buffer {\n const buf = allocBuffer(password.length * 2);\n for (let i = 0; i < password.length; i++) {\n const code = password.charCodeAt(i);\n buf[i * 2] = code & 0xff;\n buf[i * 2 + 1] = (code >>> 8) & 0xff;\n }\n return buf;\n}\n\n/**\n * Derive AES-256 key from password using 7z's SHA-256 iteration scheme\n *\n * Algorithm:\n * For round = 0 to 2^numCyclesPower - 1:\n * hash.update(salt)\n * hash.update(password_utf16le)\n * hash.update(round as 8-byte little-endian)\n * key = hash.digest()\n */\nfunction deriveKey(password: string, salt: Buffer, numCyclesPower: number): Buffer {\n const passwordBuf = passwordToUtf16LE(password);\n const numRounds = 2 ** numCyclesPower;\n\n // For special case 0x3F, don't iterate\n if (numCyclesPower === 0x3f) {\n // Direct concatenation mode\n const key = allocBuffer(32);\n let offset = 0;\n for (let j = 0; j < salt.length && offset < 32; j++) {\n key[offset++] = salt[j];\n }\n for (let k = 0; k < passwordBuf.length && offset < 32; k++) {\n key[offset++] = passwordBuf[k];\n }\n return key;\n }\n\n // Counter buffer (8 bytes, little-endian)\n const counter = allocBuffer(8);\n\n // Create hash and iterate\n const hash = crypto.createHash('sha256');\n\n for (let round = 0; round < numRounds; round++) {\n // Write round counter as little-endian 64-bit\n counter[0] = round & 0xff;\n counter[1] = (round >>> 8) & 0xff;\n counter[2] = (round >>> 16) & 0xff;\n counter[3] = (round >>> 24) & 0xff;\n // Upper 32 bits - for large round counts\n const high = Math.floor(round / 0x100000000);\n counter[4] = high & 0xff;\n counter[5] = (high >>> 8) & 0xff;\n counter[6] = (high >>> 16) & 0xff;\n counter[7] = (high >>> 24) & 0xff;\n\n hash.update(salt);\n hash.update(passwordBuf);\n hash.update(counter);\n }\n\n return hash.digest() as Buffer;\n}\n\n/**\n * Decode AES-256-CBC encrypted data\n *\n * @param input - Encrypted data\n * @param properties - AES properties (numCyclesPower, salt, IV)\n * @param _unpackSize - Unused\n * @returns Decrypted data\n */\nexport function decodeAes(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer {\n if (!_password) {\n throw new Error('AES: password required but not set');\n }\n\n if (!properties) {\n throw new Error('AES: properties required');\n }\n\n const params = parseProperties(properties);\n const key = deriveKey(_password, params.salt, params.numCyclesPower);\n\n // Create AES-256-CBC decipher\n const decipher = crypto.createDecipheriv('aes-256-cbc', key, params.iv);\n decipher.setAutoPadding(false); // 7z doesn't use PKCS7 padding\n\n // Node 0.8 returns binary strings, newer Node returns Buffers\n // Use 'binary' encoding for compatibility\n // @ts-expect-error - 'binary' encoding is deprecated but required for Node 0.8 compatibility\n const decStr = decipher.update(input, 'binary', 'binary') + decipher.final('binary');\n const decrypted = bufferFrom(decStr, 'binary' as BufferEncoding);\n\n return decrypted;\n}\n\n/**\n * Create an AES decoder Transform stream\n */\nexport function createAesDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeAes, properties, unpackSize);\n}\n"],"names":["createAesDecoder","decodeAes","getPassword","setPassword","_password","password","parseProperties","properties","length","Error","b0","numCyclesPower","salt","allocBuffer","iv","b1","saltSize","ivSize","expectedSize","slice","ivData","i","passwordToUtf16LE","buf","code","charCodeAt","deriveKey","passwordBuf","numRounds","key","offset","j","k","counter","hash","crypto","createHash","round","high","Math","floor","update","digest","input","_unpackSize","params","decipher","createDecipheriv","setAutoPadding","decStr","final","decrypted","bufferFrom","unpackSize","createBufferingDecoder"],"mappings":"AAAA,mDAAmD;AACnD,iEAAiE;AACjE,EAAE;AACF,qBAAq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F,IAAMC,SAASH,SAASL,MAAM,CAACE,OAAO,UAAU,YAAYG,SAASI,KAAK,CAAC;IAC3E,IAAMC,YAAYC,IAAAA,+BAAU,EAACH,QAAQ;IAErC,OAAOE;AACT;AAKO,SAASnD,iBAAiBO,UAAmB,EAAE8C,UAAmB;IACvE,OAAOC,IAAAA,iCAAsB,EAACrD,WAAWM,YAAY8C;AACvD"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Aes.ts"],"sourcesContent":["// 7z AES-256-CBC codec with SHA-256 key derivation\n// Implements password-based decryption for encrypted 7z archives\n//\n// Properties format:\n// Byte 0: bits 0-5 = NumCyclesPower (iterations = 2^NumCyclesPower)\n// bit 6 = IV present flag\n// bit 7 = Salt present flag\n// Byte 1: upper nibble = salt size extension\n// lower nibble = IV size extension\n// Following bytes: salt data, then IV data\n//\n// Key derivation:\n// For each round (2^NumCyclesPower times):\n// hash = SHA256(salt + password_utf16le + round_counter_8bytes)\n// Final key = first 32 bytes of accumulated hash\n\nimport crypto from 'crypto';\nimport { allocBuffer, bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\n\n// Global password storage - set before decryption\nlet _password: string | null = null;\n\n/**\n * Set the password for AES decryption\n */\nexport function setPassword(password: string | null): void {\n _password = password;\n}\n\n/**\n * Get the current password\n */\nexport function getPassword(): string | null {\n return _password;\n}\n\n/**\n * Parse AES properties to extract key derivation parameters\n */\nfunction parseProperties(properties: Buffer): { numCyclesPower: number; salt: Buffer; iv: Buffer } {\n if (!properties || properties.length < 1) {\n throw new Error('AES: missing properties');\n }\n\n const b0 = properties[0];\n const numCyclesPower = b0 & 0x3f;\n\n // Check for special case: no salt/IV flags\n if ((b0 & 0xc0) === 0) {\n // No salt, no IV - use zeros\n return {\n numCyclesPower: numCyclesPower,\n salt: allocBuffer(0),\n iv: allocBuffer(16),\n };\n }\n\n if (properties.length < 2) {\n throw new Error('AES: properties too short');\n }\n\n const b1 = properties[1];\n\n // Calculate sizes\n // saltSize = ((b0 >> 7) & 1) + (b1 >> 4)\n // ivSize = ((b0 >> 6) & 1) + (b1 & 0x0F)\n const saltSize = ((b0 >>> 7) & 1) + (b1 >>> 4);\n const ivSize = ((b0 >>> 6) & 1) + (b1 & 0x0f);\n\n const expectedSize = 2 + saltSize + ivSize;\n if (properties.length < expectedSize) {\n throw new Error('AES: properties too short for salt/IV');\n }\n\n const salt = properties.slice(2, 2 + saltSize);\n const iv = allocBuffer(16);\n\n // Copy IV data (may be less than 16 bytes, rest is zeros)\n const ivData = properties.slice(2 + saltSize, 2 + saltSize + ivSize);\n for (let i = 0; i < ivData.length && i < 16; i++) {\n iv[i] = ivData[i];\n }\n\n return {\n numCyclesPower: numCyclesPower,\n salt: salt,\n iv: iv,\n };\n}\n\n/**\n * Convert password string to UTF-16LE buffer\n */\nfunction passwordToUtf16LE(password: string): Buffer {\n const buf = allocBuffer(password.length * 2);\n for (let i = 0; i < password.length; i++) {\n const code = password.charCodeAt(i);\n buf[i * 2] = code & 0xff;\n buf[i * 2 + 1] = (code >>> 8) & 0xff;\n }\n return buf;\n}\n\n/**\n * Derive AES-256 key from password using 7z's SHA-256 iteration scheme\n *\n * Algorithm:\n * For round = 0 to 2^numCyclesPower - 1:\n * hash.update(salt)\n * hash.update(password_utf16le)\n * hash.update(round as 8-byte little-endian)\n * key = hash.digest()\n */\nfunction deriveKey(password: string, salt: Buffer, numCyclesPower: number): Buffer {\n const passwordBuf = passwordToUtf16LE(password);\n const numRounds = 2 ** numCyclesPower;\n\n // For special case 0x3F, don't iterate\n if (numCyclesPower === 0x3f) {\n // Direct concatenation mode\n const key = allocBuffer(32);\n let offset = 0;\n for (let j = 0; j < salt.length && offset < 32; j++) {\n key[offset++] = salt[j];\n }\n for (let k = 0; k < passwordBuf.length && offset < 32; k++) {\n key[offset++] = passwordBuf[k];\n }\n return key;\n }\n\n // Counter buffer (8 bytes, little-endian)\n const counter = allocBuffer(8);\n\n // Create hash and iterate\n const hash = crypto.createHash('sha256');\n\n for (let round = 0; round < numRounds; round++) {\n // Write round counter as little-endian 64-bit\n counter[0] = round & 0xff;\n counter[1] = (round >>> 8) & 0xff;\n counter[2] = (round >>> 16) & 0xff;\n counter[3] = (round >>> 24) & 0xff;\n // Upper 32 bits - for large round counts\n const high = Math.floor(round / 0x100000000);\n counter[4] = high & 0xff;\n counter[5] = (high >>> 8) & 0xff;\n counter[6] = (high >>> 16) & 0xff;\n counter[7] = (high >>> 24) & 0xff;\n\n hash.update(salt);\n hash.update(passwordBuf);\n hash.update(counter);\n }\n\n return hash.digest() as Buffer;\n}\n\n/**\n * Decode AES-256-CBC encrypted data\n *\n * @param input - Encrypted data\n * @param properties - AES properties (numCyclesPower, salt, IV)\n * @param _unpackSize - Unused\n * @returns Decrypted data\n */\nexport function decodeAes(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer {\n if (!_password) {\n throw new Error('AES: password required but not set');\n }\n\n if (!properties) {\n throw new Error('AES: properties required');\n }\n\n const params = parseProperties(properties);\n const key = deriveKey(_password, params.salt, params.numCyclesPower);\n\n // Create AES-256-CBC decipher\n const decipher = crypto.createDecipheriv('aes-256-cbc', key, params.iv);\n decipher.setAutoPadding(false); // 7z doesn't use PKCS7 padding\n\n // Node 0.8 returns binary strings, newer Node returns Buffers\n // Use 'binary' encoding for compatibility\n // @ts-expect-error - 'binary' encoding is deprecated but required for Node 0.8 compatibility\n const decStr = decipher.update(input, 'binary', 'binary') + decipher.final('binary');\n const decrypted = bufferFrom(decStr, 'binary' as BufferEncoding);\n\n return decrypted;\n}\n\n/**\n * Create an AES decoder Transform stream\n */\nexport function createAesDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeAes, properties, unpackSize);\n}\n"],"names":["createAesDecoder","decodeAes","getPassword","setPassword","_password","password","parseProperties","properties","length","Error","b0","numCyclesPower","salt","allocBuffer","iv","b1","saltSize","ivSize","expectedSize","slice","ivData","i","passwordToUtf16LE","buf","code","charCodeAt","deriveKey","passwordBuf","numRounds","key","offset","j","k","counter","hash","crypto","createHash","round","high","Math","floor","update","digest","input","_unpackSize","params","decipher","createDecipheriv","setAutoPadding","decStr","final","decrypted","bufferFrom","unpackSize","createBufferingDecoder"],"mappings":"AAAA,mDAAmD;AACnD,iEAAiE;AACjE,EAAE;AACF,qBAAqB;AACrB,sEAAsE;AACtE,oCAAoC;AACpC,sCAAsC;AACtC,+CAA+C;AAC/C,6CAA6C;AAC7C,6CAA6C;AAC7C,EAAE;AACF,kBAAkB;AAClB,6CAA6C;AAC7C,oEAAoE;AACpE,mDAAmD;;;;;;;;;;;;QAsLnCA;eAAAA;;QA5BAC;eAAAA;;QAtIAC;eAAAA;;QAPAC;eAAAA;;;6DAXG;mCACqB;+EAEL;;;;;;AAEnC,kDAAkD;AAClD,IAAIC,YAA2B;AAKxB,SAASD,YAAYE,QAAuB;IACjDD,YAAYC;AACd;AAKO,SAASH;IACd,OAAOE;AACT;AAEA;;CAEC,GACD,SAASE,gBAAgBC,UAAkB;IACzC,IAAI,CAACA,cAAcA,WAAWC,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAMC,KAAKH,UAAU,CAAC,EAAE;IACxB,IAAMI,iBAAiBD,KAAK;IAE5B,2CAA2C;IAC3C,IAAI,AAACA,CAAAA,KAAK,IAAG,MAAO,GAAG;QACrB,6BAA6B;QAC7B,OAAO;YACLC,gBAAgBA;YAChBC,MAAMC,IAAAA,gCAAW,EAAC;YAClBC,IAAID,IAAAA,gCAAW,EAAC;QAClB;IACF;IAEA,IAAIN,WAAWC,MAAM,GAAG,GAAG;QACzB,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAMM,KAAKR,UAAU,CAAC,EAAE;IAExB,kBAAkB;IAClB,yCAAyC;IACzC,yCAAyC;IACzC,IAAMS,WAAW,AAAC,CAAA,AAACN,OAAO,IAAK,CAAA,IAAMK,CAAAA,O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,WAAWyC,OAAOjC,IAAI,EAAEiC,OAAOlC,cAAc;IAEnE,8BAA8B;IAC9B,IAAMmC,WAAWX,eAAM,CAACY,gBAAgB,CAAC,eAAelB,KAAKgB,OAAO/B,EAAE;IACtEgC,SAASE,cAAc,CAAC,QAAQ,+BAA+B;IAE/D,8DAA8D;IAC9D,0CAA0C;IAC1C,6FAA6F;IAC7F,IAAMC,SAASH,SAASL,MAAM,CAACE,OAAO,UAAU,YAAYG,SAASI,KAAK,CAAC;IAC3E,IAAMC,YAAYC,IAAAA,+BAAU,EAACH,QAAQ;IAErC,OAAOE;AACT;AAKO,SAASnD,iBAAiBO,UAAmB,EAAE8C,UAAmB;IACvE,OAAOC,IAAAA,iCAAsB,EAACrD,WAAWM,YAAY8C;AACvD"}
@@ -1,5 +1,7 @@
1
- export { DirectoryEntry, type Entry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';
2
- import type { ExtractOptions as BaseExtractOptions } from 'extract-base-iterator';
1
+ export { DirectoryEntry, LinkEntry, Lock, SymbolicLinkEntry } from 'extract-base-iterator';
2
+ import type { ExtractOptions as BaseExtractOptions, DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';
3
+ import type FileEntry from './FileEntry.js';
4
+ export type Entry = DirectoryEntry | FileEntry | LinkEntry | SymbolicLinkEntry;
3
5
  /**
4
6
  * Options for SevenZipIterator
5
7
  */
@@ -18,15 +20,6 @@ export interface ExtractOptions extends BaseExtractOptions {
18
20
  }
19
21
  export { default as FileEntry } from './FileEntry.js';
20
22
  import type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.js';
21
- export interface LockT {
22
- iterator?: unknown;
23
- err?: Error;
24
- fd?: number;
25
- tempPath: string;
26
- sourceStream?: NodeJS.ReadableStream;
27
- retain: () => void;
28
- release: () => void;
29
- }
30
23
  export interface SevenZipFile {
31
24
  getStream: () => NodeJS.ReadableStream;
32
25
  }
@@ -34,5 +27,4 @@ export interface SevenZipFileIterator {
34
27
  next: () => SevenZipEntry | null;
35
28
  getParser: () => SevenZipParser;
36
29
  }
37
- import type { Entry } from 'extract-base-iterator';
38
30
  export type EntryCallback = (error?: Error, result?: IteratorResult<Entry>) => undefined;
@@ -1,5 +1,7 @@
1
- export { DirectoryEntry, type Entry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';
2
- import type { ExtractOptions as BaseExtractOptions } from 'extract-base-iterator';
1
+ export { DirectoryEntry, LinkEntry, Lock, SymbolicLinkEntry } from 'extract-base-iterator';
2
+ import type { ExtractOptions as BaseExtractOptions, DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';
3
+ import type FileEntry from './FileEntry.js';
4
+ export type Entry = DirectoryEntry | FileEntry | LinkEntry | SymbolicLinkEntry;
3
5
  /**
4
6
  * Options for SevenZipIterator
5
7
  */
@@ -18,15 +20,6 @@ export interface ExtractOptions extends BaseExtractOptions {
18
20
  }
19
21
  export { default as FileEntry } from './FileEntry.js';
20
22
  import type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.js';
21
- export interface LockT {
22
- iterator?: unknown;
23
- err?: Error;
24
- fd?: number;
25
- tempPath: string;
26
- sourceStream?: NodeJS.ReadableStream;
27
- retain: () => void;
28
- release: () => void;
29
- }
30
23
  export interface SevenZipFile {
31
24
  getStream: () => NodeJS.ReadableStream;
32
25
  }
@@ -34,5 +27,4 @@ export interface SevenZipFileIterator {
34
27
  next: () => SevenZipEntry | null;
35
28
  getParser: () => SevenZipParser;
36
29
  }
37
- import type { Entry } from 'extract-base-iterator';
38
30
  export type EntryCallback = (error?: Error, result?: IteratorResult<Entry>) => undefined;
package/dist/cjs/types.js CHANGED
@@ -18,6 +18,9 @@ _export(exports, {
18
18
  get LinkEntry () {
19
19
  return _extractbaseiterator.LinkEntry;
20
20
  },
21
+ get Lock () {
22
+ return _extractbaseiterator.Lock;
23
+ },
21
24
  get SymbolicLinkEntry () {
22
25
  return _extractbaseiterator.SymbolicLinkEntry;
23
26
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/types.ts"],"sourcesContent":["export { DirectoryEntry, type Entry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\n\nimport type { ExtractOptions as BaseExtractOptions } from 'extract-base-iterator';\n\n/**\n * Options for SevenZipIterator\n */\nexport interface ExtractOptions extends BaseExtractOptions {\n /**\n * Password for encrypted archives\n */\n password?: string;\n\n /**\n * Memory threshold in bytes for stream input.\n * Archives smaller than this are buffered in memory for faster processing.\n * Archives larger than this are written to a temp file.\n * Default: 100 MB (100 * 1024 * 1024)\n */\n memoryThreshold?: number;\n}\nexport { default as FileEntry } from './FileEntry.ts';\n\nimport type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\n\nexport interface LockT {\n iterator?: unknown;\n err?: Error;\n fd?: number;\n tempPath: string;\n sourceStream?: NodeJS.ReadableStream;\n retain: () => void;\n release: () => void;\n}\n\nexport interface SevenZipFile {\n getStream: () => NodeJS.ReadableStream;\n}\n\nexport interface SevenZipFileIterator {\n next: () => SevenZipEntry | null;\n getParser: () => SevenZipParser;\n}\n\nimport type { Entry } from 'extract-base-iterator';\n\nexport type EntryCallback = (error?: Error, result?: IteratorResult<Entry>) => undefined;\n"],"names":["DirectoryEntry","FileEntry","LinkEntry","SymbolicLinkEntry"],"mappings":";;;;;;;;;;;QAASA;eAAAA,mCAAc;;QAqBHC;eAAAA,oBAAS;;QArBQC;eAAAA,8BAAS;;QAAEC;eAAAA,sCAAiB;;;mCAAQ;kEAqBpC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/types.ts"],"sourcesContent":["export { DirectoryEntry, LinkEntry, Lock, SymbolicLinkEntry } from 'extract-base-iterator';\n\nimport type { ExtractOptions as BaseExtractOptions, DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\nimport type FileEntry from './FileEntry.ts';\n\n// 7z-specific Entry union type with 7z-specific FileEntry\nexport type Entry = DirectoryEntry | FileEntry | LinkEntry | SymbolicLinkEntry;\n\n/**\n * Options for SevenZipIterator\n */\nexport interface ExtractOptions extends BaseExtractOptions {\n /**\n * Password for encrypted archives\n */\n password?: string;\n\n /**\n * Memory threshold in bytes for stream input.\n * Archives smaller than this are buffered in memory for faster processing.\n * Archives larger than this are written to a temp file.\n * Default: 100 MB (100 * 1024 * 1024)\n */\n memoryThreshold?: number;\n}\nexport { default as FileEntry } from './FileEntry.ts';\n\nimport type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\n\nexport interface SevenZipFile {\n getStream: () => NodeJS.ReadableStream;\n}\n\nexport interface SevenZipFileIterator {\n next: () => SevenZipEntry | null;\n getParser: () => SevenZipParser;\n}\n\nexport type EntryCallback = (error?: Error, result?: IteratorResult<Entry>) => undefined;\n"],"names":["DirectoryEntry","FileEntry","LinkEntry","Lock","SymbolicLinkEntry"],"mappings":";;;;;;;;;;;QAASA;eAAAA,mCAAc;;QAyBHC;eAAAA,oBAAS;;QAzBJC;eAAAA,8BAAS;;QAAEC;eAAAA,yBAAI;;QAAEC;eAAAA,sCAAiB;;;mCAAQ;kEAyB9B"}
@@ -1,11 +1,11 @@
1
- import { type FileAttributes, FileEntry, type NoParamCallback } from 'extract-base-iterator';
1
+ import { type FileAttributes, FileEntry, type Lock, type NoParamCallback } from 'extract-base-iterator';
2
2
  import type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.js';
3
- import type { ExtractOptions, LockT } from './types.js';
3
+ import type { ExtractOptions } from './types.js';
4
4
  export default class SevenZipFileEntry extends FileEntry {
5
5
  private lock;
6
6
  private entry;
7
7
  private parser;
8
- constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock: LockT);
8
+ constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock: Lock);
9
9
  create(dest: string, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | Promise<boolean>;
10
10
  _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined;
11
11
  destroy(): void;