7z-iterator 2.1.0 → 2.2.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.
- package/dist/cjs/FileEntry.js +2 -2
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/SevenZipIterator.js +5 -5
- package/dist/cjs/SevenZipIterator.js.map +1 -1
- package/dist/cjs/lib/streamToSource.js +5 -5
- package/dist/cjs/lib/streamToSource.js.map +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.d.cts +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.d.ts +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/cjs/sevenz/codecs/index.d.cts +3 -2
- package/dist/cjs/sevenz/codecs/index.d.ts +3 -2
- package/dist/cjs/sevenz/codecs/index.js +21 -16
- package/dist/cjs/sevenz/codecs/index.js.map +1 -1
- package/dist/esm/FileEntry.js +1 -1
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/SevenZipIterator.js +1 -1
- package/dist/esm/SevenZipIterator.js.map +1 -1
- package/dist/esm/lib/streamToSource.js +1 -1
- package/dist/esm/lib/streamToSource.js.map +1 -1
- package/dist/esm/sevenz/codecs/createBufferingDecoder.d.ts +1 -1
- package/dist/esm/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/esm/sevenz/codecs/index.d.ts +3 -2
- package/dist/esm/sevenz/codecs/index.js +19 -16
- package/dist/esm/sevenz/codecs/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/cjs/lib/runDecode.d.cts +0 -5
- package/dist/cjs/lib/runDecode.d.ts +0 -5
- package/dist/cjs/lib/runDecode.js +0 -55
- package/dist/cjs/lib/runDecode.js.map +0 -1
- package/dist/esm/lib/runDecode.d.ts +0 -5
- package/dist/esm/lib/runDecode.js +0 -29
- package/dist/esm/lib/runDecode.js.map +0 -1
package/dist/cjs/FileEntry.js
CHANGED
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "default", {
|
|
|
15
15
|
});
|
|
16
16
|
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
17
17
|
var _extractbaseiterator = require("extract-base-iterator");
|
|
18
|
-
var
|
|
18
|
+
var _gracefulfs = /*#__PURE__*/ _interop_require_default(require("graceful-fs"));
|
|
19
19
|
var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
|
|
20
20
|
function _assert_this_initialized(self) {
|
|
21
21
|
if (self === void 0) {
|
|
@@ -128,7 +128,7 @@ var SevenZipFileEntry = /*#__PURE__*/ function(FileEntry) {
|
|
|
128
128
|
err ? callback(err) : (0, _extractbaseiterator.waitForAccess)(fullPath, callback);
|
|
129
129
|
});
|
|
130
130
|
try {
|
|
131
|
-
var writeStream =
|
|
131
|
+
var writeStream = _gracefulfs.default.createWriteStream(fullPath);
|
|
132
132
|
// Listen for errors on source stream (errors don't propagate through pipe)
|
|
133
133
|
stream.on('error', function(streamErr) {
|
|
134
134
|
// Destroy the write stream on source error.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/FileEntry.ts"],"sourcesContent":["/**\n * FileEntry for 7z archives\n *\n * Wraps a lazy stream - decompression happens when the stream is read.\n * API consistent with zip-iterator and tar-iterator.\n */\n\nimport once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class SevenZipFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n /**\n * Whether this entry's folder supports streaming decompression.\n */\n readonly _canStream: boolean;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock, canStream: boolean) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n this._canStream = canStream;\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n return new Promise((resolve, reject) =>\n this.create(dest, options, (err?: Error, done?: boolean) => {\n err ? reject(err) : resolve(done);\n })\n );\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('7z FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback);\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (streamErr: Error) => {\n // Destroy the write stream on source error.\n // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening\n // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,\n // and removes ALL listeners - including the 'error' listener. The subsequent EBADF\n // error then fires with no handler, causing an uncaught exception.\n // Adding a no-op error handler ensures there's always a listener for any error.\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n writeStream.on('error', () => {});\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(streamErr);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (pipeErr) {\n cb(pipeErr);\n }\n }\n\n destroy() {\n FileEntry.prototype.destroy.call(this);\n if (this.stream) {\n // Use destroy() to prevent decompression (our stream has custom destroy that sets destroyed flag)\n // Fallback to resume() for older Node versions without destroy()\n const s = this.stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') {\n s.destroy();\n }\n this.stream = null;\n }\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n }\n}\n"],"names":["SevenZipFileEntry","attributes","stream","lock","canStream","retain","_canStream","create","dest","options","callback","FileEntry","prototype","call","err","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","Error","cb","once","waitForAccess","writeStream","fs","createWriteStream","on","streamErr","ws","destroy","pipe","oo","pipeErr","s"],"mappings":"AAAA;;;;;CAKC;;;;;;;eAQoBA;;;iEANJ;mCAC8E;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/FileEntry.ts"],"sourcesContent":["/**\n * FileEntry for 7z archives\n *\n * Wraps a lazy stream - decompression happens when the stream is read.\n * API consistent with zip-iterator and tar-iterator.\n */\n\nimport once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'graceful-fs';\nimport oo from 'on-one';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class SevenZipFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n /**\n * Whether this entry's folder supports streaming decompression.\n */\n readonly _canStream: boolean;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock, canStream: boolean) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n this._canStream = canStream;\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n return new Promise((resolve, reject) =>\n this.create(dest, options, (err?: Error, done?: boolean) => {\n err ? reject(err) : resolve(done);\n })\n );\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('7z FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback);\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (streamErr: Error) => {\n // Destroy the write stream on source error.\n // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening\n // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,\n // and removes ALL listeners - including the 'error' listener. The subsequent EBADF\n // error then fires with no handler, causing an uncaught exception.\n // Adding a no-op error handler ensures there's always a listener for any error.\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n writeStream.on('error', () => {});\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(streamErr);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (pipeErr) {\n cb(pipeErr);\n }\n }\n\n destroy() {\n FileEntry.prototype.destroy.call(this);\n if (this.stream) {\n // Use destroy() to prevent decompression (our stream has custom destroy that sets destroyed flag)\n // Fallback to resume() for older Node versions without destroy()\n const s = this.stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') {\n s.destroy();\n }\n this.stream = null;\n }\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n }\n}\n"],"names":["SevenZipFileEntry","attributes","stream","lock","canStream","retain","_canStream","create","dest","options","callback","FileEntry","prototype","call","err","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","Error","cb","once","waitForA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
|
var _extractbaseiterator = /*#__PURE__*/ _interop_require_wildcard(require("extract-base-iterator"));
|
|
12
|
-
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
13
12
|
var _fsremovecompat = require("fs-remove-compat");
|
|
13
|
+
var _gracefulfs = /*#__PURE__*/ _interop_require_default(require("graceful-fs"));
|
|
14
14
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
15
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
16
16
|
var _shorthash = /*#__PURE__*/ _interop_require_default(require("short-hash"));
|
|
@@ -173,16 +173,16 @@ var SevenZipIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
173
173
|
if (typeof source === 'string') {
|
|
174
174
|
// File path input - use FileSource directly
|
|
175
175
|
queue.defer(function(cb) {
|
|
176
|
-
|
|
176
|
+
_gracefulfs.default.stat(source, function(statErr, stats) {
|
|
177
177
|
if (_this.done || cancelled) return;
|
|
178
178
|
if (statErr) return cb(statErr);
|
|
179
|
-
|
|
179
|
+
_gracefulfs.default.open(source, 'r', function(err, fd) {
|
|
180
180
|
if (_this.done || cancelled) return;
|
|
181
181
|
if (err) return cb(err);
|
|
182
182
|
archiveSource = new _SevenZipParserts.FileSource(fd, stats.size);
|
|
183
183
|
// Register cleanup for file descriptor
|
|
184
184
|
_this.lock.registerCleanup(function() {
|
|
185
|
-
|
|
185
|
+
_gracefulfs.default.closeSync(fd);
|
|
186
186
|
});
|
|
187
187
|
cb();
|
|
188
188
|
});
|
|
@@ -207,7 +207,7 @@ var SevenZipIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
207
207
|
archiveSource = result.source;
|
|
208
208
|
// Register cleanup for file descriptor
|
|
209
209
|
_this.lock.registerCleanup(function() {
|
|
210
|
-
|
|
210
|
+
_gracefulfs.default.closeSync(result.fd);
|
|
211
211
|
});
|
|
212
212
|
// Register cleanup for temp file
|
|
213
213
|
_this.lock.registerCleanup(function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/SevenZipIterator.ts"],"sourcesContent":["import BaseIterator, { Lock } from 'extract-base-iterator';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport shortHash from 'short-hash';\nimport tempSuffix from 'temp-suffix';\nimport { tmpdir } from './compat.ts';\nimport streamToSource, { type SourceResult } from './lib/streamToSource.ts';\nimport nextEntry from './nextEntry.ts';\nimport { setPassword } from './sevenz/codecs/index.ts';\nimport { type ArchiveSource, FileSource, type SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\n\nimport type { Entry, ExtractOptions } from './types.ts';\n\n/**\n * Internal iterator interface for SevenZipParser entries\n * @internal\n */\ninterface SevenZipFileIterator {\n next(): SevenZipEntry | null;\n getParser(): SevenZipParser;\n}\n\n/**\n * Iterator wrapper around SevenZipParser entries\n */\nclass EntryIterator implements SevenZipFileIterator {\n private parser: SevenZipParser;\n private entries: SevenZipEntry[];\n private index = 0;\n\n constructor(parser: SevenZipParser) {\n this.parser = parser;\n this.entries = parser.getEntries();\n }\n\n next(): SevenZipEntry | null {\n if (this.index >= this.entries.length) {\n return null;\n }\n return this.entries[this.index++];\n }\n\n getParser(): SevenZipParser {\n return this.parser;\n }\n}\n\nexport default class SevenZipIterator extends BaseIterator<Entry> {\n lock: Lock | null;\n /** @internal - Do not use directly */\n _iterator: unknown;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\n const queue = new Queue(1);\n let cancelled = false;\n let archiveSource: ArchiveSource | null = null;\n const setup = (): void => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Set password (or clear if not provided)\n setPassword(options.password || null);\n\n if (typeof source === 'string') {\n // File path input - use FileSource directly\n queue.defer((cb: (err?: Error) => void) => {\n fs.stat(source, (statErr, stats) => {\n if (this.done || cancelled) return;\n if (statErr) return cb(statErr);\n\n fs.open(source, 'r', (err, fd) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n\n archiveSource = new FileSource(fd, stats.size);\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(fd);\n });\n cb();\n });\n });\n });\n } else {\n // Stream input - write to temp file for random access\n // Register cleanup for source stream\n const stream = source as NodeJS.ReadableStream;\n this.lock.registerCleanup(() => {\n const s = stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') s.destroy();\n });\n\n const tempPath = path.join(tmpdir(), '7z-iterator', shortHash(process.cwd()), tempSuffix('tmp.7z'));\n queue.defer((cb: (err?: Error) => void) => {\n streamToSource(source, { tempPath }, (err?: Error, result?: SourceResult) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n if (!result) return cb(new Error('No result from streamToSource'));\n\n archiveSource = result.source;\n\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(result.fd);\n });\n\n // Register cleanup for temp file\n this.lock.registerCleanup(() => {\n try {\n rmSync(result.tempPath);\n } catch (_e) {\n /* ignore */\n }\n });\n\n cb();\n });\n });\n }\n\n // Parse and build iterator\n queue.defer((cb: (err?: Error) => void) => {\n if (this.done || cancelled) return;\n if (!archiveSource) return cb(new Error('No archive source'));\n\n const parser = new SevenZipParser(archiveSource);\n parser.parse((parseErr) => {\n if (parseErr) {\n cb(parseErr);\n return;\n }\n try {\n this._iterator = new EntryIterator(parser);\n cb();\n } catch (err) {\n cb(err as Error);\n }\n });\n });\n\n // start processing\n queue.await((err?: Error) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return;\n err ? this.end(err) : this.push(nextEntry);\n });\n }\n\n end(err?: Error) {\n if (this.lock) {\n const lock = this.lock;\n this.lock = null; // Clear before release to prevent re-entrancy\n lock.err = err;\n lock.release();\n }\n // Don't call base end here - Lock.__destroy() handles it\n this._iterator = null;\n }\n\n /**\n * Check if streaming extraction is available for any folder in this archive.\n * Streaming is possible when folders use codecs like BZip2, Deflate, or Copy\n * that can decompress incrementally without buffering the entire input.\n *\n * @returns true if at least one folder supports streaming\n */\n canStream(): boolean {\n if (!this._iterator) return false;\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return false;\n\n const entries = parser.getEntries();\n const checkedFolders: { [key: number]: boolean } = {};\n\n for (let i = 0; i < entries.length; i++) {\n const folderIndex = entries[i]._folderIndex;\n if (folderIndex >= 0 && checkedFolders[folderIndex] === undefined) {\n checkedFolders[folderIndex] = parser.canStreamFolder(folderIndex);\n if (checkedFolders[folderIndex]) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n /**\n * Get entries sorted for optimal streaming extraction.\n *\n * Entries are sorted by:\n * 1. Folder index (process one folder at a time)\n * 2. Stream index within folder (for solid block streaming)\n *\n * This ordering allows multi-file solid folders to stream with\n * O(largest file) memory instead of O(folder size).\n *\n * @returns Array of entries in streaming order\n */\n getStreamingOrder(): SevenZipEntry[] {\n if (!this._iterator) return [];\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return [];\n\n const entries = parser.getEntries();\n\n // Create a copy and sort for streaming order\n const sorted: SevenZipEntry[] = [];\n for (let i = 0; i < entries.length; i++) {\n sorted.push(entries[i]);\n }\n\n sorted.sort((a, b) => {\n // First by folder index\n if (a._folderIndex !== b._folderIndex) {\n return a._folderIndex - b._folderIndex;\n }\n // Then by stream index within folder\n return a._streamIndexInFolder - b._streamIndexInFolder;\n });\n\n return sorted;\n }\n}\n"],"names":["SevenZipIterator","EntryIterator","parser","index","entries","getEntries","next","length","getParser","source","options","lock","Lock","onDestroy","err","BaseIterator","prototype","end","call","queue","Queue","cancelled","archiveSource","setup","processing","push","setPassword","password","defer","cb","fs","stat","statErr","stats","done","open","fd","FileSource","size","registerCleanup","closeSync","stream","s","destroy","tempPath","path","join","tmpdir","shortHash","process","cwd","tempSuffix","streamToSource","result","Error","rmSync","_e","SevenZipParser","parse","parseErr","_iterator","await","remove","nextEntry","release","canStream","checkedFolders","i","folderIndex","_folderIndex","undefined","canStreamFolder","getStreamingOrder","sorted","sort","a","b","_streamIndexInFolder"],"mappings":";;;;;;;eAiDqBA;;;2EAjDc;yDACpB;8BACQ;2DACN;8DACC;gEACI;iEACC;wBACA;uEAC2B;kEAC5B;uBACM;gCACuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAanF;;CAEC,GACD,IAAA,AAAMC,8BAAN;;aAAMA,cAKQC,MAAsB;gCAL9BD;aAGIE,QAAQ;QAGd,IAAI,CAACD,MAAM,GAAGA;QACd,IAAI,CAACE,OAAO,GAAGF,OAAOG,UAAU;;iBAP9BJ;IAUJK,OAAAA,IAKC,GALDA,SAAAA;QACE,IAAI,IAAI,CAACH,KAAK,IAAI,IAAI,CAACC,OAAO,CAACG,MAAM,EAAE;YACrC,OAAO;QACT;QACA,OAAO,IAAI,CAACH,OAAO,CAAC,IAAI,CAACD,KAAK,GAAG;IACnC;IAEAK,OAAAA,SAEC,GAFDA,SAAAA;QACE,OAAO,IAAI,CAACN,MAAM;IACpB;WAnBID;;AAsBS,IAAA,AAAMD,iCAAN;;cAAMA;aAAAA,iBAKPS,MAAsC;YAAEC,UAAAA,iEAA0B,CAAC;gCAL5DV;;gBAMjB,kBANiBA;YAMXU;;QACN,MAAKC,IAAI,GAAG,IAAIC,yBAAI;QACpB,MAAKD,IAAI,CAACE,SAAS,GAAG,SAACC;mBAAQC,4BAAY,CAACC,SAAS,CAACC,GAAG,CAACC,IAAI,QAAOJ;;QACrE,IAAMK,QAAQ,IAAIC,gBAAK,CAAC;QACxB,IAAIC,YAAY;QAChB,IAAIC,gBAAsC;QAC1C,IAAMC,QAAQ;YACZF,YAAY;QACd;QACA,MAAKG,UAAU,CAACC,IAAI,CAACF;QAErB,0CAA0C;QAC1CG,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ts"],"sourcesContent":["import BaseIterator, { Lock } from 'extract-base-iterator';\nimport { rmSync } from 'fs-remove-compat';\nimport fs from 'graceful-fs';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport shortHash from 'short-hash';\nimport tempSuffix from 'temp-suffix';\nimport { tmpdir } from './compat.ts';\nimport streamToSource, { type SourceResult } from './lib/streamToSource.ts';\nimport nextEntry from './nextEntry.ts';\nimport { setPassword } from './sevenz/codecs/index.ts';\nimport { type ArchiveSource, FileSource, type SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\n\nimport type { Entry, ExtractOptions } from './types.ts';\n\n/**\n * Internal iterator interface for SevenZipParser entries\n * @internal\n */\ninterface SevenZipFileIterator {\n next(): SevenZipEntry | null;\n getParser(): SevenZipParser;\n}\n\n/**\n * Iterator wrapper around SevenZipParser entries\n */\nclass EntryIterator implements SevenZipFileIterator {\n private parser: SevenZipParser;\n private entries: SevenZipEntry[];\n private index = 0;\n\n constructor(parser: SevenZipParser) {\n this.parser = parser;\n this.entries = parser.getEntries();\n }\n\n next(): SevenZipEntry | null {\n if (this.index >= this.entries.length) {\n return null;\n }\n return this.entries[this.index++];\n }\n\n getParser(): SevenZipParser {\n return this.parser;\n }\n}\n\nexport default class SevenZipIterator extends BaseIterator<Entry> {\n lock: Lock | null;\n /** @internal - Do not use directly */\n _iterator: unknown;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\n const queue = new Queue(1);\n let cancelled = false;\n let archiveSource: ArchiveSource | null = null;\n const setup = (): void => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Set password (or clear if not provided)\n setPassword(options.password || null);\n\n if (typeof source === 'string') {\n // File path input - use FileSource directly\n queue.defer((cb: (err?: Error) => void) => {\n fs.stat(source, (statErr, stats) => {\n if (this.done || cancelled) return;\n if (statErr) return cb(statErr);\n\n fs.open(source, 'r', (err, fd) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n\n archiveSource = new FileSource(fd, stats.size);\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(fd);\n });\n cb();\n });\n });\n });\n } else {\n // Stream input - write to temp file for random access\n // Register cleanup for source stream\n const stream = source as NodeJS.ReadableStream;\n this.lock.registerCleanup(() => {\n const s = stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') s.destroy();\n });\n\n const tempPath = path.join(tmpdir(), '7z-iterator', shortHash(process.cwd()), tempSuffix('tmp.7z'));\n queue.defer((cb: (err?: Error) => void) => {\n streamToSource(source, { tempPath }, (err?: Error, result?: SourceResult) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n if (!result) return cb(new Error('No result from streamToSource'));\n\n archiveSource = result.source;\n\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(result.fd);\n });\n\n // Register cleanup for temp file\n this.lock.registerCleanup(() => {\n try {\n rmSync(result.tempPath);\n } catch (_e) {\n /* ignore */\n }\n });\n\n cb();\n });\n });\n }\n\n // Parse and build iterator\n queue.defer((cb: (err?: Error) => void) => {\n if (this.done || cancelled) return;\n if (!archiveSource) return cb(new Error('No archive source'));\n\n const parser = new SevenZipParser(archiveSource);\n parser.parse((parseErr) => {\n if (parseErr) {\n cb(parseErr);\n return;\n }\n try {\n this._iterator = new EntryIterator(parser);\n cb();\n } catch (err) {\n cb(err as Error);\n }\n });\n });\n\n // start processing\n queue.await((err?: Error) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return;\n err ? this.end(err) : this.push(nextEntry);\n });\n }\n\n end(err?: Error) {\n if (this.lock) {\n const lock = this.lock;\n this.lock = null; // Clear before release to prevent re-entrancy\n lock.err = err;\n lock.release();\n }\n // Don't call base end here - Lock.__destroy() handles it\n this._iterator = null;\n }\n\n /**\n * Check if streaming extraction is available for any folder in this archive.\n * Streaming is possible when folders use codecs like BZip2, Deflate, or Copy\n * that can decompress incrementally without buffering the entire input.\n *\n * @returns true if at least one folder supports streaming\n */\n canStream(): boolean {\n if (!this._iterator) return false;\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return false;\n\n const entries = parser.getEntries();\n const checkedFolders: { [key: number]: boolean } = {};\n\n for (let i = 0; i < entries.length; i++) {\n const folderIndex = entries[i]._folderIndex;\n if (folderIndex >= 0 && checkedFolders[folderIndex] === undefined) {\n checkedFolders[folderIndex] = parser.canStreamFolder(folderIndex);\n if (checkedFolders[folderIndex]) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n /**\n * Get entries sorted for optimal streaming extraction.\n *\n * Entries are sorted by:\n * 1. Folder index (process one folder at a time)\n * 2. Stream index within folder (for solid block streaming)\n *\n * This ordering allows multi-file solid folders to stream with\n * O(largest file) memory instead of O(folder size).\n *\n * @returns Array of entries in streaming order\n */\n getStreamingOrder(): SevenZipEntry[] {\n if (!this._iterator) return [];\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return [];\n\n const entries = parser.getEntries();\n\n // Create a copy and sort for streaming order\n const sorted: SevenZipEntry[] = [];\n for (let i = 0; i < entries.length; i++) {\n sorted.push(entries[i]);\n }\n\n sorted.sort((a, b) => {\n // First by folder index\n if (a._folderIndex !== b._folderIndex) {\n return a._folderIndex - b._folderIndex;\n }\n // Then by stream index within folder\n return a._streamIndexInFolder - b._streamIndexInFolder;\n });\n\n return sorted;\n }\n}\n"],"names":["SevenZipIterator","EntryIterator","parser","index","entries","getEntries","next","length","getParser","source","options","lock","Lock","onDestroy","err","BaseIterator","prototype","end","call","queue","Queue","cancelled","archiveSource","setup","processing","push","setPassword","password","defer","cb","fs","stat","statErr","stats","done","open","fd","FileSource","size","registerCleanup","closeSync","stream","s","destroy","tempPath","path","join","tmpdir","shortHash","process","cwd","tempSuffix","streamToSource","result","Error","rmSync","_e","SevenZipParser","parse","parseErr","_iterator","await","remove","nextEntry","release","canStream","checkedFolders","i","folderIndex","_folderIndex","undefined","can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I,CAACN,QAAQ,OAAO;QAEpB,IAAME,UAAUF,OAAOG,UAAU;QACjC,IAAM6D,iBAA6C,CAAC;QAEpD,IAAK,IAAIC,IAAI,GAAGA,IAAI/D,QAAQG,MAAM,EAAE4D,IAAK;YACvC,IAAMC,cAAchE,OAAO,CAAC+D,EAAE,CAACE,YAAY;YAC3C,IAAID,eAAe,KAAKF,cAAc,CAACE,YAAY,KAAKE,WAAW;gBACjEJ,cAAc,CAACE,YAAY,GAAGlE,OAAOqE,eAAe,CAACH;gBACrD,IAAIF,cAAc,CAACE,YAAY,EAAE;oBAC/B,OAAO;gBACT;YACF;QACF;QAEA,OAAO;IACT;IAEA;;;;;;;;;;;GAWC,GACDI,OAAAA,iBAuBC,GAvBDA,SAAAA;QACE,IAAI,CAAC,IAAI,CAACZ,SAAS,EAAE,OAAO,EAAE;QAC9B,IAAM1D,SAAS,AAAC,IAAI,CAAC0D,SAAS,CAA0BpD,SAAS;QACjE,IAAI,CAACN,QAAQ,OAAO,EAAE;QAEtB,IAAME,UAAUF,OAAOG,UAAU;QAEjC,6CAA6C;QAC7C,IAAMoE,SAA0B,EAAE;QAClC,IAAK,IAAIN,IAAI,GAAGA,IAAI/D,QAAQG,MAAM,EAAE4D,IAAK;YACvCM,OAAOhD,IAAI,CAACrB,OAAO,CAAC+D,EAAE;QACxB;QAEAM,OAAOC,IAAI,CAAC,SAACC,GAAGC;YACd,wBAAwB;YACxB,IAAID,EAAEN,YAAY,KAAKO,EAAEP,YAAY,EAAE;gBACrC,OAAOM,EAAEN,YAAY,GAAGO,EAAEP,YAAY;YACxC;YACA,qCAAqC;YACrC,OAAOM,EAAEE,oBAAoB,GAAGD,EAAEC,oBAAoB;QACxD;QAEA,OAAOJ;IACT;WAnLmBzE;EAAyBe,4BAAY"}
|
|
@@ -16,7 +16,7 @@ Object.defineProperty(exports, /**
|
|
|
16
16
|
});
|
|
17
17
|
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
18
18
|
var _extractbaseiterator = require("extract-base-iterator");
|
|
19
|
-
var
|
|
19
|
+
var _gracefulfs = /*#__PURE__*/ _interop_require_default(require("graceful-fs"));
|
|
20
20
|
var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
|
|
21
21
|
var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
|
|
22
22
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
@@ -30,18 +30,18 @@ function streamToSource(stream, options, callback) {
|
|
|
30
30
|
var tempPath = options.tempPath;
|
|
31
31
|
var end = (0, _calloncefn.default)(callback);
|
|
32
32
|
_mkdirpclassic.default.sync(_path.default.dirname(tempPath));
|
|
33
|
-
var writeStream =
|
|
33
|
+
var writeStream = _gracefulfs.default.createWriteStream(tempPath);
|
|
34
34
|
function onData(chunk) {
|
|
35
35
|
var buf = typeof chunk === 'string' ? (0, _extractbaseiterator.bufferFrom)(chunk) : chunk;
|
|
36
36
|
writeStream.write(buf);
|
|
37
37
|
}
|
|
38
38
|
function onEnd() {
|
|
39
39
|
writeStream.end(function() {
|
|
40
|
-
|
|
40
|
+
_gracefulfs.default.open(tempPath, 'r', function(err, fd) {
|
|
41
41
|
if (err) return end(err);
|
|
42
|
-
|
|
42
|
+
_gracefulfs.default.stat(tempPath, function(statErr, stats) {
|
|
43
43
|
if (statErr) {
|
|
44
|
-
|
|
44
|
+
_gracefulfs.default.closeSync(fd);
|
|
45
45
|
return end(statErr);
|
|
46
46
|
}
|
|
47
47
|
end(null, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/lib/streamToSource.ts"],"sourcesContent":["// Stream to source conversion: writes stream to temp file for random access\nimport once from 'call-once-fn';\nimport { bufferFrom } from 'extract-base-iterator';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport oo from 'on-one';\nimport path from 'path';\nimport { FileSource } from '../sevenz/SevenZipParser.ts';\n\nexport interface StreamToSourceOptions {\n tempPath: string;\n}\n\nexport interface SourceResult {\n source: FileSource;\n fd: number; // Caller must close\n tempPath: string; // Caller must clean up\n}\n\nexport type Callback = (error?: Error, result?: SourceResult) => void;\n\n/**\n * Convert a stream to a FileSource by writing to temp file\n *\n * 7z format requires random access for header parsing, so temp file is necessary for streams.\n * Writes directly to temp file for predictable O(1) memory usage during stream consumption.\n */\nexport default function streamToSource(stream: NodeJS.ReadableStream, options: StreamToSourceOptions, callback: Callback): void {\n const tempPath = options.tempPath;\n\n const end = once(callback);\n\n mkdirp.sync(path.dirname(tempPath));\n const writeStream = fs.createWriteStream(tempPath);\n\n function onData(chunk: Buffer | string): void {\n const buf = typeof chunk === 'string' ? bufferFrom(chunk) : chunk;\n writeStream.write(buf);\n }\n\n function onEnd(): void {\n writeStream.end(() => {\n fs.open(tempPath, 'r', (err, fd) => {\n if (err) return end(err);\n fs.stat(tempPath, (statErr, stats) => {\n if (statErr) {\n fs.closeSync(fd);\n return end(statErr);\n }\n end(null, {\n source: new FileSource(fd, stats.size),\n fd: fd,\n tempPath: tempPath,\n });\n });\n });\n });\n }\n\n function onError(err: Error): void {\n writeStream.end();\n end(err);\n }\n\n stream.on('data', onData);\n oo(stream, ['error'], onError);\n oo(stream, ['end', 'close', 'finish'], onEnd);\n}\n"],"names":["streamToSource","stream","options","callback","tempPath","end","once","mkdirp","sync","path","dirname","writeStream","fs","createWriteStream","onData","chunk","buf","bufferFrom","write","onEnd","open","err","fd","stat","statErr","stats","closeSync","source","FileSource","size","onError","on","oo"],"mappings":"AAAA,4EAA4E;;;;;+BAqB5E;;;;;CAKC,GACD;;;eAAwBA;;;iEA1BP;mCACU;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/lib/streamToSource.ts"],"sourcesContent":["// Stream to source conversion: writes stream to temp file for random access\nimport once from 'call-once-fn';\nimport { bufferFrom } from 'extract-base-iterator';\nimport fs from 'graceful-fs';\nimport mkdirp from 'mkdirp-classic';\nimport oo from 'on-one';\nimport path from 'path';\nimport { FileSource } from '../sevenz/SevenZipParser.ts';\n\nexport interface StreamToSourceOptions {\n tempPath: string;\n}\n\nexport interface SourceResult {\n source: FileSource;\n fd: number; // Caller must close\n tempPath: string; // Caller must clean up\n}\n\nexport type Callback = (error?: Error, result?: SourceResult) => void;\n\n/**\n * Convert a stream to a FileSource by writing to temp file\n *\n * 7z format requires random access for header parsing, so temp file is necessary for streams.\n * Writes directly to temp file for predictable O(1) memory usage during stream consumption.\n */\nexport default function streamToSource(stream: NodeJS.ReadableStream, options: StreamToSourceOptions, callback: Callback): void {\n const tempPath = options.tempPath;\n\n const end = once(callback);\n\n mkdirp.sync(path.dirname(tempPath));\n const writeStream = fs.createWriteStream(tempPath);\n\n function onData(chunk: Buffer | string): void {\n const buf = typeof chunk === 'string' ? bufferFrom(chunk) : chunk;\n writeStream.write(buf);\n }\n\n function onEnd(): void {\n writeStream.end(() => {\n fs.open(tempPath, 'r', (err, fd) => {\n if (err) return end(err);\n fs.stat(tempPath, (statErr, stats) => {\n if (statErr) {\n fs.closeSync(fd);\n return end(statErr);\n }\n end(null, {\n source: new FileSource(fd, stats.size),\n fd: fd,\n tempPath: tempPath,\n });\n });\n });\n });\n }\n\n function onError(err: Error): void {\n writeStream.end();\n end(err);\n }\n\n stream.on('data', onData);\n oo(stream, ['error'], onError);\n oo(stream, ['end', 'close', 'finish'], onEnd);\n}\n"],"names":["streamToSource","stream","options","callback","tempPath","end","once","mkdirp","sync","path","dirname","writeStream","fs","createWriteStream","onData","chunk","buf","bufferFrom","write","onEnd","open","err","fd","stat","statErr","stats","closeSync","source","FileSource","size","onError","on","oo"],"mappings":"AAAA,4EAA4E;;;;;+BAqB5E;;;;;CAKC,GACD;;;eAAwBA;;;iEA1BP;mCACU;iEACZ;oEACI;4DACJ;2DACE;gCACU;;;;;;AAoBZ,SAASA,eAAeC,MAA6B,EAAEC,OAA8B,EAAEC,QAAkB;IACtH,IAAMC,WAAWF,QAAQE,QAAQ;IAEjC,IAAMC,MAAMC,IAAAA,mBAAI,EAACH;IAEjBI,sBAAM,CAACC,IAAI,CAACC,aAAI,CAACC,OAAO,CAACN;IACzB,IAAMO,cAAcC,mBAAE,CAACC,iBAAiB,CAACT;IAEzC,SAASU,OAAOC,KAAsB;QACpC,IAAMC,MAAM,OAAOD,UAAU,WAAWE,IAAAA,+BAAU,EAACF,SAASA;QAC5DJ,YAAYO,KAAK,CAACF;IACpB;IAEA,SAASG;QACPR,YAAYN,GAAG,CAAC;YACdO,mBAAE,CAACQ,IAAI,CAAChB,UAAU,KAAK,SAACiB,KAAKC;gBAC3B,IAAID,KAAK,OAAOhB,IAAIgB;gBACpBT,mBAAE,CAACW,IAAI,CAACnB,UAAU,SAACoB,SAASC;oBAC1B,IAAID,SAAS;wBACXZ,mBAAE,CAACc,SAAS,CAACJ;wBACb,OAAOjB,IAAImB;oBACb;oBACAnB,IAAI,MAAM;wBACRsB,QAAQ,IAAIC,4BAAU,CAACN,IAAIG,MAAMI,IAAI;wBACrCP,IAAIA;wBACJlB,UAAUA;oBACZ;gBACF;YACF;QACF;IACF;IAEA,SAAS0B,QAAQT,GAAU;QACzBV,YAAYN,GAAG;QACfA,IAAIgB;IACN;IAEApB,OAAO8B,EAAE,CAAC,QAAQjB;IAClBkB,IAAAA,cAAE,EAAC/B,QAAQ;QAAC;KAAQ,EAAE6B;IACtBE,IAAAA,cAAE,EAAC/B,QAAQ;QAAC;QAAO;QAAS;KAAS,EAAEkB;AACzC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'extract-base-iterator';
|
|
2
|
-
import type { DecodeCallback } from '
|
|
2
|
+
import type { DecodeCallback } from 'xz-compat';
|
|
3
3
|
export type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;
|
|
4
4
|
/**
|
|
5
5
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'extract-base-iterator';
|
|
2
|
-
import type { DecodeCallback } from '
|
|
2
|
+
import type { DecodeCallback } from 'xz-compat';
|
|
3
3
|
export type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;
|
|
4
4
|
/**
|
|
5
5
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from '
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from 'xz-compat';\n\ntype TransformCallback = (error?: Error | null, data?: Buffer) => void;\n\nexport type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;\n\n/**\n * Create a Transform stream that buffers all input, then decodes in flush\n * This is the common pattern for codecs that can't stream (need full input)\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): InstanceType<typeof Transform> {\n const chunks: Buffer[] = [];\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: TransformCallback) => {\n chunks.push(chunk);\n callback();\n },\n flush: function (callback: TransformCallback) {\n const input = Buffer.concat(chunks);\n const finish = (err?: Error | null, output?: Buffer) => {\n if (err) {\n callback(err);\n return;\n }\n if (output) {\n this.push(output);\n }\n callback();\n };\n\n try {\n const maybeResult = decodeFn(input, properties, unpackSize, finish);\n if (maybeResult && typeof (maybeResult as Promise<Buffer>).then === 'function') {\n (maybeResult as Promise<Buffer>).then(\n (value) => finish(null, value),\n (err) => finish(err as Error)\n );\n return;\n }\n if (Buffer.isBuffer(maybeResult)) {\n finish(null, maybeResult);\n }\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["createBufferingDecoder","decodeFn","properties","unpackSize","chunks","Transform","transform","chunk","_encoding","callback","push","flush","input","Buffer","concat","finish","err","output","maybeResult","then","value","isBuffer"],"mappings":"AAAA,6EAA6E;AAC7E,0FAA0F;;;;;+BAS1F;;;CAGC,GACD;;;eAAwBA;;;mCAXE;AAWX,SAASA,uBAAuBC,QAAkB,EAAEC,UAAmB,EAAEC,UAAmB;IACzG,IAAMC,SAAmB,EAAE;IAE3B,OAAO,IAAIC,8BAAS,CAAC;QACnBC,WAAW,SAACC,OAAeC,WAAmBC;YAC5CL,OAAOM,IAAI,CAACH;YACZE;QACF;QACAE,OAAO,SAAPA,MAAiBF,QAA2B;;YAC1C,IAAMG,QAAQC,OAAOC,MAAM,CAACV;YAC5B,IAAMW,SAAS,SAACC,KAAoBC;gBAClC,IAAID,KAAK;oBACPP,SAASO;oBACT;gBACF;gBACA,IAAIC,QAAQ;oBACV,MAAKP,IAAI,CAACO;gBACZ;gBACAR;YACF;YAEA,IAAI;gBACF,IAAMS,cAAcjB,SAASW,OAAOV,YAAYC,YAAYY;gBAC5D,IAAIG,eAAe,OAAO,AAACA,YAAgCC,IAAI,KAAK,YAAY;oBAC7ED,YAAgCC,IAAI,CACnC,SAACC;+BAAUL,OAAO,MAAMK;uBACxB,SAACJ;+BAAQD,OAAOC;;oBAElB;gBACF;gBACA,IAAIH,OAAOQ,QAAQ,CAACH,cAAc;oBAChCH,OAAO,MAAMG;gBACf;YACF,EAAE,OAAOF,KAAK;gBACZP,SAASO;YACX;QACF;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { BufferLike } from 'extract-base-iterator';
|
|
1
2
|
import type { Transform } from 'stream';
|
|
2
|
-
import { type DecodeCallback as CodecDecodeCallback } from '
|
|
3
|
+
import { type DecodeCallback as CodecDecodeCallback } from 'xz-compat';
|
|
3
4
|
import { getPassword, setPassword } from './Aes.js';
|
|
4
5
|
import { decodeBcj2Multi } from './Bcj2.js';
|
|
5
6
|
export { getPassword, setPassword };
|
|
6
7
|
export interface Codec {
|
|
7
|
-
decode: (input:
|
|
8
|
+
decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;
|
|
8
9
|
createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { BufferLike } from 'extract-base-iterator';
|
|
1
2
|
import type { Transform } from 'stream';
|
|
2
|
-
import { type DecodeCallback as CodecDecodeCallback } from '
|
|
3
|
+
import { type DecodeCallback as CodecDecodeCallback } from 'xz-compat';
|
|
3
4
|
import { getPassword, setPassword } from './Aes.js';
|
|
4
5
|
import { decodeBcj2Multi } from './Bcj2.js';
|
|
5
6
|
export { getPassword, setPassword };
|
|
6
7
|
export interface Codec {
|
|
7
|
-
decode: (input:
|
|
8
|
+
decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;
|
|
8
9
|
createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -37,31 +37,36 @@ _export(exports, {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
var _xzcompat = require("xz-compat");
|
|
40
|
-
var _runDecodets = require("../../lib/runDecode.js");
|
|
41
40
|
var _constantsts = require("../constants.js");
|
|
42
41
|
var _Aests = require("./Aes.js");
|
|
43
42
|
var _Bcj2ts = require("./Bcj2.js");
|
|
44
43
|
var _BZip2ts = require("./BZip2.js");
|
|
45
44
|
var _Copyts = require("./Copy.js");
|
|
46
45
|
var _Deflatets = require("./Deflate.js");
|
|
46
|
+
var schedule = typeof setImmediate === 'function' ? setImmediate : function(fn) {
|
|
47
|
+
return process.nextTick(fn);
|
|
48
|
+
};
|
|
47
49
|
function wrapSyncDecode(fn) {
|
|
48
50
|
return function(input, properties, unpackSize, callback) {
|
|
49
|
-
(
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
schedule(function() {
|
|
52
|
+
try {
|
|
53
|
+
// Convert BufferList to Buffer if needed
|
|
54
|
+
var buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
55
|
+
callback(null, fn(buf, properties, unpackSize));
|
|
56
|
+
} catch (err) {
|
|
57
|
+
callback(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
52
60
|
};
|
|
53
61
|
}
|
|
54
|
-
// Simple wrappers with validation that use xz-compat's optimized
|
|
62
|
+
// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2
|
|
55
63
|
function decodeLzma(input, properties, unpackSize, callback) {
|
|
56
|
-
if (
|
|
64
|
+
if (properties.length < 5) {
|
|
57
65
|
throw new Error('LZMA requires 5-byte properties');
|
|
58
66
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(0, _runDecodets.runDecode)(function(done) {
|
|
63
|
-
(0, _xzcompat.decode7zLzma)(input, properties, unpackSize, done);
|
|
64
|
-
}, callback);
|
|
67
|
+
// Convert BufferList to Buffer if needed
|
|
68
|
+
var buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
69
|
+
(0, _xzcompat.decode7zLzma)(buf, properties, unpackSize, callback);
|
|
65
70
|
}
|
|
66
71
|
function createLzmaDecoder(properties, unpackSize) {
|
|
67
72
|
if (!properties || properties.length < 5) {
|
|
@@ -73,12 +78,12 @@ function createLzmaDecoder(properties, unpackSize) {
|
|
|
73
78
|
return (0, _xzcompat.createLzmaDecoder)(properties, unpackSize);
|
|
74
79
|
}
|
|
75
80
|
function decodeLzma2(input, properties, unpackSize, callback) {
|
|
76
|
-
if (
|
|
81
|
+
if (properties.length < 1) {
|
|
77
82
|
throw new Error('LZMA2 requires properties byte');
|
|
78
83
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
// Convert BufferList to Buffer if needed
|
|
85
|
+
var buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
86
|
+
(0, _xzcompat.decode7zLzma2)(buf, properties, unpackSize, callback);
|
|
82
87
|
}
|
|
83
88
|
function createLzma2Decoder(properties, _unpackSize) {
|
|
84
89
|
if (!properties || properties.length < 1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { type DecodeCallback as CodecDecodeCallback, runDecode } from '../../lib/runDecode.ts';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n runDecode((done) => {\n done(null, fn(input, properties, unpackSize));\n }, callback);\n };\n}\n\nexport interface Codec {\n decode: (input: Buffer, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLjma/decode7zLzma2\nfunction decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n runDecode((done) => {\n decode7zLzma(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n runDecode((done) => {\n decode7zLzma2(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["decodeBcj2Multi","getCodec","getCodecName","getPassword","isBcj2Codec","isCodecSupported","registerCodec","setPassword","wrapSyncDecode","fn","input","properties","unpackSize","callback","runDecode","done","decodeLzma","length","Error","decode7zLzma","createLzmaDecoder","_createLzmaDecoder","decodeLzma2","decode7zLzma2","createLzma2Decoder","_unpackSize","_createLzma2Decoder","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","codec","key","createCodedError","ErrorCode","UNSUPPORTED_CODEC","undefined","CodecId","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","decode","decodeCopy","createDecoder","createCopyDecoder","decodeBcj","createBcjDecoder","decodeBcjArm","createBcjArmDecoder","decodeBcjArmt","createBcjArmtDecoder","decodeBcjArm64","createBcjArm64Decoder","decodeBcjPpc","createBcjPpcDecoder","decodeBcjIa64","createBcjIa64Decoder","decodeBcjSparc","createBcjSparcDecoder","decodeDelta","createDeltaDecoder","decodeDeflate","createDeflateDecoder","decodeBzip2","createBzip2Decoder","decodeAes","createAesDecoder","decodeBcj2","createBcj2Decoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;;;;;;;;;;;;QA2KlEA;eAAAA,uBAAe;;QA/CRC;eAAAA;;QAmBAC;eAAAA;;QA7GPC;eAAAA,kBAAW;;QAoIJC;eAAAA;;QA9BAC;eAAAA;;QApBAC;eAAAA;;QAlFMC;eAAAA,kBAAW;;;wBAV1B;2BAC+D;2BACjB;qBACiB;sBACP;uBACf;sBACF;yBACM;AAKpD,SAASC,eAAeC,EAAuE;IAC7F,OAAO,SAACC,OAAOC,YAAYC,YAAYC;QACrCC,IAAAA,sBAAS,EAAC,SAACC;YACTA,KAAK,MAAMN,GAAGC,OAAOC,YAAYC;QACnC,GAAGC;IACL;AACF;AAOA,4FAA4F;AAC5F,SAASG,WAAWN,KAAa,EAAEC,UAAmB,EAAEC,UAAmB,EAAEC,QAAsC;IACjH,IAAI,CAACF,cAAcA,WAAWM,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IACA,IAAI,OAAON,eAAe,YAAYA,aAAa,GAAG;QACpD,MAAM,IAAIM,MAAM;IAClB;IACAJ,IAAAA,sBAAS,EAAC,SAACC;QACTI,IAAAA,sBAAY,EAACT,OAAOC,YAAYC,YAAYG;IAC9C,GAAGF;AACL;AAEA,SAASO,kBAAkBT,UAAmB,EAAEC,UAAmB;IACjE,IAAI,CAACD,cAAcA,WAAWM,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IACA,IAAI,OAAON,eAAe,YAAYA,aAAa,GAAG;QACpD,MAAM,IAAIM,MAAM;IAClB;IACA,OAAOG,IAAAA,2BAAkB,EAACV,YAAYC;AACxC;AAEA,SAASU,YAAYZ,KAAa,EAAEC,UAAmB,EAAEC,UAAmB,EAAEC,QAAsC;IAClH,IAAI,CAACF,cAAcA,WAAWM,MAAM,GAAG,GAA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AAgB;AAChB3E,cAAcuC,oBAAO,CAACc,OAAO,EAAE;IAC7BG,QAAQtD,eAAe0E,wBAAa;IACpClB,eAAemB,+BAAoB;AACrC;AAEA,cAAc;AACd7E,cAAcuC,oBAAO,CAACe,KAAK,EAAE;IAC3BE,QAAQtD,eAAe4E,oBAAW;IAClCpB,eAAeqB,2BAAkB;AACnC;AAEA,iCAAiC;AACjC/E,cAAcuC,oBAAO,CAACgB,GAAG,EAAE;IACzBC,QAAQtD,eAAe8E,gBAAS;IAChCtB,eAAeuB,uBAAgB;AACjC;AAEA,sCAAsC;AACtC,sFAAsF;AACtFjF,cAAcuC,oBAAO,CAACW,IAAI,EAAE;IAC1BM,QAAQ0B,kBAAU;IAClBxB,eAAeyB,yBAAiB;AAClC,IAEA,kEAAkE"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { BufferLike } from 'extract-base-iterator';\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n type DecodeCallback as CodecDecodeCallback,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n schedule(() => {\n try {\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n callback(null, fn(buf, properties, unpackSize));\n } catch (err) {\n callback(err as Error);\n }\n });\n };\n}\n\nexport interface Codec {\n decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2\nfunction decodeLzma(input: BufferLike, properties: Buffer, unpackSize: number, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma(buf, properties, unpackSize, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: BufferLike, properties: Buffer, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma2(buf, properties, unpackSize, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["decodeBcj2Multi","getCodec","getCodecName","getPassword","isBcj2Codec","isCodecSupported","registerCodec","setPassword","schedule","setImmediate","fn","process","nextTick","wrapSyncDecode","input","properties","unpackSize","callback","buf","Buffer","isBuffer","toBuffer","err","decodeLzma","length","Error","decode7zLzma","createLzmaDecoder","_createLzmaDecoder","decodeLzma2","decode7zLzma2","createLzma2Decoder","_unpackSize","_createLzma2Decoder","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","codec","key","createCodedError","ErrorCode","UNSUPPORTED_CODEC","undefined","CodecId","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","decode","decodeCopy","createDecoder","createCopyDecoder","decodeBcj","createBcjDecoder","decodeBcjArm","createBcjArmDecoder","decodeBcjArmt","createBcjArmtDecoder","decodeBcjArm64","createBcjArm64Decoder","decodeBcjPpc","createBcjPpcDecoder","decodeBcjIa64","createBcjIa64Decoder","decodeBcjSparc","createBcjSparcDecoder","decodeDelta","createDeltaDecoder","decodeDeflate","createDeflateDecoder","decodeBzip2","createBzip2Decoder","decodeAes","createAesDecoder","decodeBcj2","createBcj2Decoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;;;;;;;;;;;;QAiLlEA;eAAAA,uBAAe;;QA/CRC;eAAAA;;QAmBAC;eAAAA;;QAlHPC;eAAAA,kBAAW;;QAyIJC;eAAAA;;QA9BAC;eAAAA;;QApBAC;eAAAA;;QAvFMC;eAAAA,kBAAW;;;wBAT1B;2BAC8C;qBACiB;sBACP;uBACf;sBACF;yBACM;AAKpD,IAAMC,WAAW,OAAOC,iBAAiB,aAAaA,eAAe,SAACC;WAAmBC,QAAQC,QAAQ,CAACF;;AAE1G,SAASG,eAAeH,EAAuE;IAC7F,OAAO,SAACI,OAAOC,YAAYC,YAAYC;QACrCT,SAAS;YACP,IAAI;gBACF,yCAAyC;gBACzC,IAAMU,MAAMC,OAAOC,QAAQ,CAACN,SAASA,QAAQA,MAAMO,QAAQ;gBAC3DJ,SAAS,MAAMP,GAAGQ,KAAKH,YAAYC;YACrC,EAAE,OAAOM,KAAK;gBACZL,SAASK;YACX;QACF;IACF;AACF;AAOA,4FAA4F;AAC5F,SAASC,WAAWT,KAAiB,EAAEC,UAAkB,EAAEC,UAAkB,EAAEC,QAAqC;IAClH,IAAIF,WAAWS,MAAM,GAAG,GAAG;QACzB,MAAM,IAAIC,MAAM;IAClB;IACA,yCAAyC;IACzC,IAAMP,MAAMC,OAAOC,QAAQ,CAACN,SAASA,QAAQA,MAAMO,QAAQ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,cAAc8C,oBAAO,CAACQ,OAAO,EAAE;IAC7BS,QAAQxD,eAAeoE,sBAAY;IACnCV,eAAeW,6BAAmB;AACpC;AAEA,oBAAoB;AACpB5E,cAAc8C,oBAAO,CAACS,QAAQ,EAAE;IAC9BQ,QAAQxD,eAAesE,uBAAa;IACpCZ,eAAea,8BAAoB;AACrC;AAEA,qBAAqB;AACrB9E,cAAc8C,oBAAO,CAACU,SAAS,EAAE;IAC/BO,QAAQxD,eAAewE,wBAAc;IACrCd,eAAee,+BAAqB;AACtC;AAEA,eAAe;AACfhF,cAAc8C,oBAAO,CAACa,KAAK,EAAE;IAC3BI,QAAQxD,eAAe0E,qBAAW;IAClChB,eAAeiB,4BAAkB;AACnC;AAEA,gBAAgB;AAChBlF,cAAc8C,oBAAO,CAACc,OAAO,EAAE;IAC7BG,QAAQxD,eAAe4E,wBAAa;IACpClB,eAAemB,+BAAoB;AACrC;AAEA,cAAc;AACdpF,cAAc8C,oBAAO,CAACe,KAAK,EAAE;IAC3BE,QAAQxD,eAAe8E,oBAAW;IAClCpB,eAAeqB,2BAAkB;AACnC;AAEA,iCAAiC;AACjCtF,cAAc8C,oBAAO,CAACgB,GAAG,EAAE;IACzBC,QAAQxD,eAAegF,gBAAS;IAChCtB,eAAeuB,uBAAgB;AACjC;AAEA,sCAAsC;AACtC,sFAAsF;AACtFxF,cAAc8C,oBAAO,CAACW,IAAI,EAAE;IAC1BM,QAAQ0B,kBAAU;IAClBxB,eAAeyB,yBAAiB;AAClC,IAEA,kEAAkE"}
|
package/dist/esm/FileEntry.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* API consistent with zip-iterator and tar-iterator.
|
|
6
6
|
*/ import once from 'call-once-fn';
|
|
7
7
|
import { FileEntry, waitForAccess } from 'extract-base-iterator';
|
|
8
|
-
import fs from 'fs';
|
|
8
|
+
import fs from 'graceful-fs';
|
|
9
9
|
import oo from 'on-one';
|
|
10
10
|
let SevenZipFileEntry = class SevenZipFileEntry extends FileEntry {
|
|
11
11
|
create(dest, options, callback) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/FileEntry.ts"],"sourcesContent":["/**\n * FileEntry for 7z archives\n *\n * Wraps a lazy stream - decompression happens when the stream is read.\n * API consistent with zip-iterator and tar-iterator.\n */\n\nimport once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class SevenZipFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n /**\n * Whether this entry's folder supports streaming decompression.\n */\n readonly _canStream: boolean;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock, canStream: boolean) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n this._canStream = canStream;\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n return new Promise((resolve, reject) =>\n this.create(dest, options, (err?: Error, done?: boolean) => {\n err ? reject(err) : resolve(done);\n })\n );\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('7z FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback);\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (streamErr: Error) => {\n // Destroy the write stream on source error.\n // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening\n // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,\n // and removes ALL listeners - including the 'error' listener. The subsequent EBADF\n // error then fires with no handler, causing an uncaught exception.\n // Adding a no-op error handler ensures there's always a listener for any error.\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n writeStream.on('error', () => {});\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(streamErr);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (pipeErr) {\n cb(pipeErr);\n }\n }\n\n destroy() {\n FileEntry.prototype.destroy.call(this);\n if (this.stream) {\n // Use destroy() to prevent decompression (our stream has custom destroy that sets destroyed flag)\n // Fallback to resume() for older Node versions without destroy()\n const s = this.stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') {\n s.destroy();\n }\n this.stream = null;\n }\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n }\n}\n"],"names":["once","FileEntry","waitForAccess","fs","oo","SevenZipFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","stream","Error","cb","writeStream","createWriteStream","on","streamErr","ws","destroy","pipe","pipeErr","s","attributes","canStream","retain","_canStream"],"mappings":"AAAA;;;;;CAKC,GAED,OAAOA,UAAU,eAAe;AAChC,SAA8BC,SAAS,EAAmCC,aAAa,QAAQ,wBAAwB;AACvH,OAAOC,QAAQ,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/FileEntry.ts"],"sourcesContent":["/**\n * FileEntry for 7z archives\n *\n * Wraps a lazy stream - decompression happens when the stream is read.\n * API consistent with zip-iterator and tar-iterator.\n */\n\nimport once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'graceful-fs';\nimport oo from 'on-one';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class SevenZipFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n /**\n * Whether this entry's folder supports streaming decompression.\n */\n readonly _canStream: boolean;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock, canStream: boolean) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n this._canStream = canStream;\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n return new Promise((resolve, reject) =>\n this.create(dest, options, (err?: Error, done?: boolean) => {\n err ? reject(err) : resolve(done);\n })\n );\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('7z FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback);\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (streamErr: Error) => {\n // Destroy the write stream on source error.\n // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening\n // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,\n // and removes ALL listeners - including the 'error' listener. The subsequent EBADF\n // error then fires with no handler, causing an uncaught exception.\n // Adding a no-op error handler ensures there's always a listener for any error.\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n writeStream.on('error', () => {});\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(streamErr);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (pipeErr) {\n cb(pipeErr);\n }\n }\n\n destroy() {\n FileEntry.prototype.destroy.call(this);\n if (this.stream) {\n // Use destroy() to prevent decompression (our stream has custom destroy that sets destroyed flag)\n // Fallback to resume() for older Node versions without destroy()\n const s = this.stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') {\n s.destroy();\n }\n this.stream = null;\n }\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n }\n}\n"],"names":["once","FileEntry","waitForAccess","fs","oo","SevenZipFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","stream","Error","cb","writeStream","createWriteStream","on","streamErr","ws","destroy","pipe","pipeErr","s","attributes","canStream","retain","_canStream"],"mappings":"AAAA;;;;;CAKC,GAED,OAAOA,UAAU,eAAe;AAChC,SAA8BC,SAAS,EAAmCC,aAAa,QAAQ,wBAAwB;AACvH,OAAOC,QAAQ,cAAc;AAC7B,OAAOC,QAAQ,SAAS;AAGT,IAAA,AAAMC,oBAAN,MAAMA,0BAA0BJ;IAoB7CK,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B,EAA2B;QACpHA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAE7D,IAAI,OAAOC,aAAa,YAAY;YAClC,OAAOR,UAAUS,SAAS,CAACJ,MAAM,CAACK,IAAI,CAAC,IAAI,EAAEJ,MAAMC,SAAS,CAACI;gBAC3DH,SA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AAI,IAAI,CAACX,MAAM;YACrB,IAAI,OAAOW,EAAEH,OAAO,KAAK,YAAY;gBACnCG,EAAEH,OAAO;YACX;YACA,IAAI,CAACR,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACT,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACC,OAAO;YACjB,IAAI,CAACD,IAAI,GAAG;QACd;IACF;IArFA,YAAYqB,UAA0B,EAAEZ,MAA6B,EAAET,IAAU,EAAEsB,SAAkB,CAAE;QACrG,KAAK,CAACD;QACN,IAAI,CAACZ,MAAM,GAAGA;QACd,IAAI,CAACT,IAAI,GAAGA;QACZ,IAAI,CAACA,IAAI,CAACuB,MAAM;QAChB,IAAI,CAACC,UAAU,GAAGF;IACpB;AAgFF;AA/FA,SAAqB9B,+BA+FpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/SevenZipIterator.ts"],"sourcesContent":["import BaseIterator, { Lock } from 'extract-base-iterator';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport shortHash from 'short-hash';\nimport tempSuffix from 'temp-suffix';\nimport { tmpdir } from './compat.ts';\nimport streamToSource, { type SourceResult } from './lib/streamToSource.ts';\nimport nextEntry from './nextEntry.ts';\nimport { setPassword } from './sevenz/codecs/index.ts';\nimport { type ArchiveSource, FileSource, type SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\n\nimport type { Entry, ExtractOptions } from './types.ts';\n\n/**\n * Internal iterator interface for SevenZipParser entries\n * @internal\n */\ninterface SevenZipFileIterator {\n next(): SevenZipEntry | null;\n getParser(): SevenZipParser;\n}\n\n/**\n * Iterator wrapper around SevenZipParser entries\n */\nclass EntryIterator implements SevenZipFileIterator {\n private parser: SevenZipParser;\n private entries: SevenZipEntry[];\n private index = 0;\n\n constructor(parser: SevenZipParser) {\n this.parser = parser;\n this.entries = parser.getEntries();\n }\n\n next(): SevenZipEntry | null {\n if (this.index >= this.entries.length) {\n return null;\n }\n return this.entries[this.index++];\n }\n\n getParser(): SevenZipParser {\n return this.parser;\n }\n}\n\nexport default class SevenZipIterator extends BaseIterator<Entry> {\n lock: Lock | null;\n /** @internal - Do not use directly */\n _iterator: unknown;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\n const queue = new Queue(1);\n let cancelled = false;\n let archiveSource: ArchiveSource | null = null;\n const setup = (): void => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Set password (or clear if not provided)\n setPassword(options.password || null);\n\n if (typeof source === 'string') {\n // File path input - use FileSource directly\n queue.defer((cb: (err?: Error) => void) => {\n fs.stat(source, (statErr, stats) => {\n if (this.done || cancelled) return;\n if (statErr) return cb(statErr);\n\n fs.open(source, 'r', (err, fd) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n\n archiveSource = new FileSource(fd, stats.size);\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(fd);\n });\n cb();\n });\n });\n });\n } else {\n // Stream input - write to temp file for random access\n // Register cleanup for source stream\n const stream = source as NodeJS.ReadableStream;\n this.lock.registerCleanup(() => {\n const s = stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') s.destroy();\n });\n\n const tempPath = path.join(tmpdir(), '7z-iterator', shortHash(process.cwd()), tempSuffix('tmp.7z'));\n queue.defer((cb: (err?: Error) => void) => {\n streamToSource(source, { tempPath }, (err?: Error, result?: SourceResult) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n if (!result) return cb(new Error('No result from streamToSource'));\n\n archiveSource = result.source;\n\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(result.fd);\n });\n\n // Register cleanup for temp file\n this.lock.registerCleanup(() => {\n try {\n rmSync(result.tempPath);\n } catch (_e) {\n /* ignore */\n }\n });\n\n cb();\n });\n });\n }\n\n // Parse and build iterator\n queue.defer((cb: (err?: Error) => void) => {\n if (this.done || cancelled) return;\n if (!archiveSource) return cb(new Error('No archive source'));\n\n const parser = new SevenZipParser(archiveSource);\n parser.parse((parseErr) => {\n if (parseErr) {\n cb(parseErr);\n return;\n }\n try {\n this._iterator = new EntryIterator(parser);\n cb();\n } catch (err) {\n cb(err as Error);\n }\n });\n });\n\n // start processing\n queue.await((err?: Error) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return;\n err ? this.end(err) : this.push(nextEntry);\n });\n }\n\n end(err?: Error) {\n if (this.lock) {\n const lock = this.lock;\n this.lock = null; // Clear before release to prevent re-entrancy\n lock.err = err;\n lock.release();\n }\n // Don't call base end here - Lock.__destroy() handles it\n this._iterator = null;\n }\n\n /**\n * Check if streaming extraction is available for any folder in this archive.\n * Streaming is possible when folders use codecs like BZip2, Deflate, or Copy\n * that can decompress incrementally without buffering the entire input.\n *\n * @returns true if at least one folder supports streaming\n */\n canStream(): boolean {\n if (!this._iterator) return false;\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return false;\n\n const entries = parser.getEntries();\n const checkedFolders: { [key: number]: boolean } = {};\n\n for (let i = 0; i < entries.length; i++) {\n const folderIndex = entries[i]._folderIndex;\n if (folderIndex >= 0 && checkedFolders[folderIndex] === undefined) {\n checkedFolders[folderIndex] = parser.canStreamFolder(folderIndex);\n if (checkedFolders[folderIndex]) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n /**\n * Get entries sorted for optimal streaming extraction.\n *\n * Entries are sorted by:\n * 1. Folder index (process one folder at a time)\n * 2. Stream index within folder (for solid block streaming)\n *\n * This ordering allows multi-file solid folders to stream with\n * O(largest file) memory instead of O(folder size).\n *\n * @returns Array of entries in streaming order\n */\n getStreamingOrder(): SevenZipEntry[] {\n if (!this._iterator) return [];\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return [];\n\n const entries = parser.getEntries();\n\n // Create a copy and sort for streaming order\n const sorted: SevenZipEntry[] = [];\n for (let i = 0; i < entries.length; i++) {\n sorted.push(entries[i]);\n }\n\n sorted.sort((a, b) => {\n // First by folder index\n if (a._folderIndex !== b._folderIndex) {\n return a._folderIndex - b._folderIndex;\n }\n // Then by stream index within folder\n return a._streamIndexInFolder - b._streamIndexInFolder;\n });\n\n return sorted;\n }\n}\n"],"names":["BaseIterator","Lock","fs","rmSync","path","Queue","shortHash","tempSuffix","tmpdir","streamToSource","nextEntry","setPassword","FileSource","SevenZipParser","EntryIterator","next","index","entries","length","getParser","parser","getEntries","SevenZipIterator","end","err","lock","release","_iterator","canStream","checkedFolders","i","folderIndex","_folderIndex","undefined","canStreamFolder","getStreamingOrder","sorted","push","sort","a","b","_streamIndexInFolder","source","options","onDestroy","prototype","call","queue","cancelled","archiveSource","setup","processing","password","defer","cb","stat","statErr","stats","done","open","fd","size","registerCleanup","closeSync","stream","s","destroy","tempPath","join","process","cwd","result","Error","_e","parse","parseErr","await","remove"],"mappings":"AAAA,OAAOA,gBAAgBC,IAAI,QAAQ,wBAAwB;AAC3D,OAAOC,QAAQ,KAAK;AACpB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,eAAe,aAAa;AACnC,OAAOC,gBAAgB,cAAc;AACrC,SAASC,MAAM,QAAQ,cAAc;AACrC,OAAOC,oBAA2C,0BAA0B;AAC5E,OAAOC,eAAe,iBAAiB;AACvC,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SAA6BC,UAAU,EAAsBC,cAAc,QAAQ,6BAA6B;AAahH;;CAEC,GACD,IAAA,AAAMC,gBAAN,MAAMA;IAUJC,OAA6B;QAC3B,IAAI,IAAI,CAACC,KAAK,IAAI,IAAI,CAACC,OAAO,CAACC,MAAM,EAAE;YACrC,OAAO;QACT;QACA,OAAO,IAAI,CAACD,OAAO,CAAC,IAAI,CAACD,KAAK,GAAG;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AAC,CAACC;gBACZ,IAAIA,UAAU;oBACZrB,GAAGqB;oBACH;gBACF;gBACA,IAAI;oBACF,IAAI,CAAChD,SAAS,GAAG,IAAIb,cAAcM;oBACnCkC;gBACF,EAAE,OAAO9B,KAAK;oBACZ8B,GAAG9B;gBACL;YACF;QACF;QAEA,mBAAmB;QACnBuB,MAAM6B,KAAK,CAAC,CAACpD;YACX,IAAI,CAAC2B,UAAU,CAAC0B,MAAM,CAAC3B;YACvB,IAAI,IAAI,CAACQ,IAAI,IAAIV,WAAW;YAC5BxB,MAAM,IAAI,CAACD,GAAG,CAACC,OAAO,IAAI,CAACa,IAAI,CAAC3B;QAClC;IACF;AA6EF;AApLA,SAAqBY,8BAoLpB"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/SevenZipIterator.ts"],"sourcesContent":["import BaseIterator, { Lock } from 'extract-base-iterator';\nimport { rmSync } from 'fs-remove-compat';\nimport fs from 'graceful-fs';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport shortHash from 'short-hash';\nimport tempSuffix from 'temp-suffix';\nimport { tmpdir } from './compat.ts';\nimport streamToSource, { type SourceResult } from './lib/streamToSource.ts';\nimport nextEntry from './nextEntry.ts';\nimport { setPassword } from './sevenz/codecs/index.ts';\nimport { type ArchiveSource, FileSource, type SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\n\nimport type { Entry, ExtractOptions } from './types.ts';\n\n/**\n * Internal iterator interface for SevenZipParser entries\n * @internal\n */\ninterface SevenZipFileIterator {\n next(): SevenZipEntry | null;\n getParser(): SevenZipParser;\n}\n\n/**\n * Iterator wrapper around SevenZipParser entries\n */\nclass EntryIterator implements SevenZipFileIterator {\n private parser: SevenZipParser;\n private entries: SevenZipEntry[];\n private index = 0;\n\n constructor(parser: SevenZipParser) {\n this.parser = parser;\n this.entries = parser.getEntries();\n }\n\n next(): SevenZipEntry | null {\n if (this.index >= this.entries.length) {\n return null;\n }\n return this.entries[this.index++];\n }\n\n getParser(): SevenZipParser {\n return this.parser;\n }\n}\n\nexport default class SevenZipIterator extends BaseIterator<Entry> {\n lock: Lock | null;\n /** @internal - Do not use directly */\n _iterator: unknown;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\n const queue = new Queue(1);\n let cancelled = false;\n let archiveSource: ArchiveSource | null = null;\n const setup = (): void => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Set password (or clear if not provided)\n setPassword(options.password || null);\n\n if (typeof source === 'string') {\n // File path input - use FileSource directly\n queue.defer((cb: (err?: Error) => void) => {\n fs.stat(source, (statErr, stats) => {\n if (this.done || cancelled) return;\n if (statErr) return cb(statErr);\n\n fs.open(source, 'r', (err, fd) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n\n archiveSource = new FileSource(fd, stats.size);\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(fd);\n });\n cb();\n });\n });\n });\n } else {\n // Stream input - write to temp file for random access\n // Register cleanup for source stream\n const stream = source as NodeJS.ReadableStream;\n this.lock.registerCleanup(() => {\n const s = stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') s.destroy();\n });\n\n const tempPath = path.join(tmpdir(), '7z-iterator', shortHash(process.cwd()), tempSuffix('tmp.7z'));\n queue.defer((cb: (err?: Error) => void) => {\n streamToSource(source, { tempPath }, (err?: Error, result?: SourceResult) => {\n if (this.done || cancelled) return;\n if (err) return cb(err);\n if (!result) return cb(new Error('No result from streamToSource'));\n\n archiveSource = result.source;\n\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(result.fd);\n });\n\n // Register cleanup for temp file\n this.lock.registerCleanup(() => {\n try {\n rmSync(result.tempPath);\n } catch (_e) {\n /* ignore */\n }\n });\n\n cb();\n });\n });\n }\n\n // Parse and build iterator\n queue.defer((cb: (err?: Error) => void) => {\n if (this.done || cancelled) return;\n if (!archiveSource) return cb(new Error('No archive source'));\n\n const parser = new SevenZipParser(archiveSource);\n parser.parse((parseErr) => {\n if (parseErr) {\n cb(parseErr);\n return;\n }\n try {\n this._iterator = new EntryIterator(parser);\n cb();\n } catch (err) {\n cb(err as Error);\n }\n });\n });\n\n // start processing\n queue.await((err?: Error) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return;\n err ? this.end(err) : this.push(nextEntry);\n });\n }\n\n end(err?: Error) {\n if (this.lock) {\n const lock = this.lock;\n this.lock = null; // Clear before release to prevent re-entrancy\n lock.err = err;\n lock.release();\n }\n // Don't call base end here - Lock.__destroy() handles it\n this._iterator = null;\n }\n\n /**\n * Check if streaming extraction is available for any folder in this archive.\n * Streaming is possible when folders use codecs like BZip2, Deflate, or Copy\n * that can decompress incrementally without buffering the entire input.\n *\n * @returns true if at least one folder supports streaming\n */\n canStream(): boolean {\n if (!this._iterator) return false;\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return false;\n\n const entries = parser.getEntries();\n const checkedFolders: { [key: number]: boolean } = {};\n\n for (let i = 0; i < entries.length; i++) {\n const folderIndex = entries[i]._folderIndex;\n if (folderIndex >= 0 && checkedFolders[folderIndex] === undefined) {\n checkedFolders[folderIndex] = parser.canStreamFolder(folderIndex);\n if (checkedFolders[folderIndex]) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n /**\n * Get entries sorted for optimal streaming extraction.\n *\n * Entries are sorted by:\n * 1. Folder index (process one folder at a time)\n * 2. Stream index within folder (for solid block streaming)\n *\n * This ordering allows multi-file solid folders to stream with\n * O(largest file) memory instead of O(folder size).\n *\n * @returns Array of entries in streaming order\n */\n getStreamingOrder(): SevenZipEntry[] {\n if (!this._iterator) return [];\n const parser = (this._iterator as SevenZipFileIterator).getParser();\n if (!parser) return [];\n\n const entries = parser.getEntries();\n\n // Create a copy and sort for streaming order\n const sorted: SevenZipEntry[] = [];\n for (let i = 0; i < entries.length; i++) {\n sorted.push(entries[i]);\n }\n\n sorted.sort((a, b) => {\n // First by folder index\n if (a._folderIndex !== b._folderIndex) {\n return a._folderIndex - b._folderIndex;\n }\n // Then by stream index within folder\n return a._streamIndexInFolder - b._streamIndexInFolder;\n });\n\n return sorted;\n }\n}\n"],"names":["BaseIterator","Lock","rmSync","fs","path","Queue","shortHash","tempSuffix","tmpdir","streamToSource","nextEntry","setPassword","FileSource","SevenZipParser","EntryIterator","next","index","entries","length","getParser","parser","getEntries","SevenZipIterator","end","err","lock","release","_iterator","canStream","checkedFolders","i","folderIndex","_folderIndex","undefined","canStreamFolder","getStreamingOrder","sorted","push","sort","a","b","_streamIndexInFolder","source","options","onDestroy","prototype","call","queue","cancelled","archiveSource","setup","processing","password","defer","cb","stat","statErr","stats","done","open","fd","size","registerCleanup","closeSync","stream","s","destroy","tempPath","join","process","cwd","result","Error","_e","parse","parseErr","await","remove"],"mappings":"AAAA,OAAOA,gBAAgBC,IAAI,QAAQ,wBAAwB;AAC3D,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,cAAc;AAC7B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,eAAe,aAAa;AACnC,OAAOC,gBAAgB,cAAc;AACrC,SAASC,MAAM,QAAQ,cAAc;AACrC,OAAOC,oBAA2C,0BAA0B;AAC5E,OAAOC,eAAe,iBAAiB;AACvC,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SAA6BC,UAAU,EAAsBC,cAAc,QAAQ,6BAA6B;AAahH;;CAEC,GACD,IAAA,AAAMC,gBAAN,MAAMA;IAUJC,OAA6B;QAC3B,IAAI,IAAI,CAACC,KAAK,IAAI,IAAI,CAACC,OAAO,CAACC,MAAM,EAAE;YACrC,OAAO;QACT;QACA,OAAO,IAAI,CAACD,OAAO,CAAC,IAAI,CAACD,KAAK,GAAG;IACnC;IAEAG,YAA4B;QAC1B,OAAO,IAAI,CAACC,MAAM;IACpB;IAdA,YAA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AAI;oBACF,IAAI,CAAChD,SAAS,GAAG,IAAIb,cAAcM;oBACnCkC;gBACF,EAAE,OAAO9B,KAAK;oBACZ8B,GAAG9B;gBACL;YACF;QACF;QAEA,mBAAmB;QACnBuB,MAAM6B,KAAK,CAAC,CAACpD;YACX,IAAI,CAAC2B,UAAU,CAAC0B,MAAM,CAAC3B;YACvB,IAAI,IAAI,CAACQ,IAAI,IAAIV,WAAW;YAC5BxB,MAAM,IAAI,CAACD,GAAG,CAACC,OAAO,IAAI,CAACa,IAAI,CAAC3B;QAClC;IACF;AA6EF;AApLA,SAAqBY,8BAoLpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Stream to source conversion: writes stream to temp file for random access
|
|
2
2
|
import once from 'call-once-fn';
|
|
3
3
|
import { bufferFrom } from 'extract-base-iterator';
|
|
4
|
-
import fs from 'fs';
|
|
4
|
+
import fs from 'graceful-fs';
|
|
5
5
|
import mkdirp from 'mkdirp-classic';
|
|
6
6
|
import oo from 'on-one';
|
|
7
7
|
import path from 'path';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/lib/streamToSource.ts"],"sourcesContent":["// Stream to source conversion: writes stream to temp file for random access\nimport once from 'call-once-fn';\nimport { bufferFrom } from 'extract-base-iterator';\nimport fs from 'fs';\nimport mkdirp from 'mkdirp-classic';\nimport oo from 'on-one';\nimport path from 'path';\nimport { FileSource } from '../sevenz/SevenZipParser.ts';\n\nexport interface StreamToSourceOptions {\n tempPath: string;\n}\n\nexport interface SourceResult {\n source: FileSource;\n fd: number; // Caller must close\n tempPath: string; // Caller must clean up\n}\n\nexport type Callback = (error?: Error, result?: SourceResult) => void;\n\n/**\n * Convert a stream to a FileSource by writing to temp file\n *\n * 7z format requires random access for header parsing, so temp file is necessary for streams.\n * Writes directly to temp file for predictable O(1) memory usage during stream consumption.\n */\nexport default function streamToSource(stream: NodeJS.ReadableStream, options: StreamToSourceOptions, callback: Callback): void {\n const tempPath = options.tempPath;\n\n const end = once(callback);\n\n mkdirp.sync(path.dirname(tempPath));\n const writeStream = fs.createWriteStream(tempPath);\n\n function onData(chunk: Buffer | string): void {\n const buf = typeof chunk === 'string' ? bufferFrom(chunk) : chunk;\n writeStream.write(buf);\n }\n\n function onEnd(): void {\n writeStream.end(() => {\n fs.open(tempPath, 'r', (err, fd) => {\n if (err) return end(err);\n fs.stat(tempPath, (statErr, stats) => {\n if (statErr) {\n fs.closeSync(fd);\n return end(statErr);\n }\n end(null, {\n source: new FileSource(fd, stats.size),\n fd: fd,\n tempPath: tempPath,\n });\n });\n });\n });\n }\n\n function onError(err: Error): void {\n writeStream.end();\n end(err);\n }\n\n stream.on('data', onData);\n oo(stream, ['error'], onError);\n oo(stream, ['end', 'close', 'finish'], onEnd);\n}\n"],"names":["once","bufferFrom","fs","mkdirp","oo","path","FileSource","streamToSource","stream","options","callback","tempPath","end","sync","dirname","writeStream","createWriteStream","onData","chunk","buf","write","onEnd","open","err","fd","stat","statErr","stats","closeSync","source","size","onError","on"],"mappings":"AAAA,4EAA4E;AAC5E,OAAOA,UAAU,eAAe;AAChC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,OAAOC,QAAQ,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/lib/streamToSource.ts"],"sourcesContent":["// Stream to source conversion: writes stream to temp file for random access\nimport once from 'call-once-fn';\nimport { bufferFrom } from 'extract-base-iterator';\nimport fs from 'graceful-fs';\nimport mkdirp from 'mkdirp-classic';\nimport oo from 'on-one';\nimport path from 'path';\nimport { FileSource } from '../sevenz/SevenZipParser.ts';\n\nexport interface StreamToSourceOptions {\n tempPath: string;\n}\n\nexport interface SourceResult {\n source: FileSource;\n fd: number; // Caller must close\n tempPath: string; // Caller must clean up\n}\n\nexport type Callback = (error?: Error, result?: SourceResult) => void;\n\n/**\n * Convert a stream to a FileSource by writing to temp file\n *\n * 7z format requires random access for header parsing, so temp file is necessary for streams.\n * Writes directly to temp file for predictable O(1) memory usage during stream consumption.\n */\nexport default function streamToSource(stream: NodeJS.ReadableStream, options: StreamToSourceOptions, callback: Callback): void {\n const tempPath = options.tempPath;\n\n const end = once(callback);\n\n mkdirp.sync(path.dirname(tempPath));\n const writeStream = fs.createWriteStream(tempPath);\n\n function onData(chunk: Buffer | string): void {\n const buf = typeof chunk === 'string' ? bufferFrom(chunk) : chunk;\n writeStream.write(buf);\n }\n\n function onEnd(): void {\n writeStream.end(() => {\n fs.open(tempPath, 'r', (err, fd) => {\n if (err) return end(err);\n fs.stat(tempPath, (statErr, stats) => {\n if (statErr) {\n fs.closeSync(fd);\n return end(statErr);\n }\n end(null, {\n source: new FileSource(fd, stats.size),\n fd: fd,\n tempPath: tempPath,\n });\n });\n });\n });\n }\n\n function onError(err: Error): void {\n writeStream.end();\n end(err);\n }\n\n stream.on('data', onData);\n oo(stream, ['error'], onError);\n oo(stream, ['end', 'close', 'finish'], onEnd);\n}\n"],"names":["once","bufferFrom","fs","mkdirp","oo","path","FileSource","streamToSource","stream","options","callback","tempPath","end","sync","dirname","writeStream","createWriteStream","onData","chunk","buf","write","onEnd","open","err","fd","stat","statErr","stats","closeSync","source","size","onError","on"],"mappings":"AAAA,4EAA4E;AAC5E,OAAOA,UAAU,eAAe;AAChC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,OAAOC,QAAQ,cAAc;AAC7B,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,QAAQ,SAAS;AACxB,OAAOC,UAAU,OAAO;AACxB,SAASC,UAAU,QAAQ,8BAA8B;AAczD;;;;;CAKC,GACD,eAAe,SAASC,eAAeC,MAA6B,EAAEC,OAA8B,EAAEC,QAAkB;IACtH,MAAMC,WAAWF,QAAQE,QAAQ;IAEjC,MAAMC,MAAMZ,KAAKU;IAEjBP,OAAOU,IAAI,CAACR,KAAKS,OAAO,CAACH;IACzB,MAAMI,cAAcb,GAAGc,iBAAiB,CAACL;IAEzC,SAASM,OAAOC,KAAsB;QACpC,MAAMC,MAAM,OAAOD,UAAU,WAAWjB,WAAWiB,SAASA;QAC5DH,YAAYK,KAAK,CAACD;IACpB;IAEA,SAASE;QACPN,YAAYH,GAAG,CAAC;YACdV,GAAGoB,IAAI,CAACX,UAAU,KAAK,CAACY,KAAKC;gBAC3B,IAAID,KAAK,OAAOX,IAAIW;gBACpBrB,GAAGuB,IAAI,CAACd,UAAU,CAACe,SAASC;oBAC1B,IAAID,SAAS;wBACXxB,GAAG0B,SAAS,CAACJ;wBACb,OAAOZ,IAAIc;oBACb;oBACAd,IAAI,MAAM;wBACRiB,QAAQ,IAAIvB,WAAWkB,IAAIG,MAAMG,IAAI;wBACrCN,IAAIA;wBACJb,UAAUA;oBACZ;gBACF;YACF;QACF;IACF;IAEA,SAASoB,QAAQR,GAAU;QACzBR,YAAYH,GAAG;QACfA,IAAIW;IACN;IAEAf,OAAOwB,EAAE,CAAC,QAAQf;IAClBb,GAAGI,QAAQ;QAAC;KAAQ,EAAEuB;IACtB3B,GAAGI,QAAQ;QAAC;QAAO;QAAS;KAAS,EAAEa;AACzC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'extract-base-iterator';
|
|
2
|
-
import type { DecodeCallback } from '
|
|
2
|
+
import type { DecodeCallback } from 'xz-compat';
|
|
3
3
|
export type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;
|
|
4
4
|
/**
|
|
5
5
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from '
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from 'xz-compat';\n\ntype TransformCallback = (error?: Error | null, data?: Buffer) => void;\n\nexport type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;\n\n/**\n * Create a Transform stream that buffers all input, then decodes in flush\n * This is the common pattern for codecs that can't stream (need full input)\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): InstanceType<typeof Transform> {\n const chunks: Buffer[] = [];\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: TransformCallback) => {\n chunks.push(chunk);\n callback();\n },\n flush: function (callback: TransformCallback) {\n const input = Buffer.concat(chunks);\n const finish = (err?: Error | null, output?: Buffer) => {\n if (err) {\n callback(err);\n return;\n }\n if (output) {\n this.push(output);\n }\n callback();\n };\n\n try {\n const maybeResult = decodeFn(input, properties, unpackSize, finish);\n if (maybeResult && typeof (maybeResult as Promise<Buffer>).then === 'function') {\n (maybeResult as Promise<Buffer>).then(\n (value) => finish(null, value),\n (err) => finish(err as Error)\n );\n return;\n }\n if (Buffer.isBuffer(maybeResult)) {\n finish(null, maybeResult);\n }\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["Transform","createBufferingDecoder","decodeFn","properties","unpackSize","chunks","transform","chunk","_encoding","callback","push","flush","input","Buffer","concat","finish","err","output","maybeResult","then","value","isBuffer"],"mappings":"AAAA,6EAA6E;AAC7E,0FAA0F;AAE1F,SAASA,SAAS,QAAQ,wBAAwB;AAOlD;;;CAGC,GACD,eAAe,SAASC,uBAAuBC,QAAkB,EAAEC,UAAmB,EAAEC,UAAmB;IACzG,MAAMC,SAAmB,EAAE;IAE3B,OAAO,IAAIL,UAAU;QACnBM,WAAW,CAACC,OAAeC,WAAmBC;YAC5CJ,OAAOK,IAAI,CAACH;YACZE;QACF;QACAE,OAAO,SAAUF,QAA2B;YAC1C,MAAMG,QAAQC,OAAOC,MAAM,CAACT;YAC5B,MAAMU,SAAS,CAACC,KAAoBC;gBAClC,IAAID,KAAK;oBACPP,SAASO;oBACT;gBACF;gBACA,IAAIC,QAAQ;oBACV,IAAI,CAACP,IAAI,CAACO;gBACZ;gBACAR;YACF;YAEA,IAAI;gBACF,MAAMS,cAAchB,SAASU,OAAOT,YAAYC,YAAYW;gBAC5D,IAAIG,eAAe,OAAO,AAACA,YAAgCC,IAAI,KAAK,YAAY;oBAC7ED,YAAgCC,IAAI,CACnC,CAACC,QAAUL,OAAO,MAAMK,QACxB,CAACJ,MAAQD,OAAOC;oBAElB;gBACF;gBACA,IAAIH,OAAOQ,QAAQ,CAACH,cAAc;oBAChCH,OAAO,MAAMG;gBACf;YACF,EAAE,OAAOF,KAAK;gBACZP,SAASO;YACX;QACF;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { BufferLike } from 'extract-base-iterator';
|
|
1
2
|
import type { Transform } from 'stream';
|
|
2
|
-
import { type DecodeCallback as CodecDecodeCallback } from '
|
|
3
|
+
import { type DecodeCallback as CodecDecodeCallback } from 'xz-compat';
|
|
3
4
|
import { getPassword, setPassword } from './Aes.js';
|
|
4
5
|
import { decodeBcj2Multi } from './Bcj2.js';
|
|
5
6
|
export { getPassword, setPassword };
|
|
6
7
|
export interface Codec {
|
|
7
|
-
decode: (input:
|
|
8
|
+
decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;
|
|
8
9
|
createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Codec registry for 7z decompression
|
|
2
2
|
// Each codec provides a decode function and optionally a streaming decoder
|
|
3
3
|
import { createLzma2Decoder as _createLzma2Decoder, createLzmaDecoder as _createLzmaDecoder, createBcjArm64Decoder, createBcjArmDecoder, createBcjArmtDecoder, createBcjDecoder, createBcjIa64Decoder, createBcjPpcDecoder, createBcjSparcDecoder, createDeltaDecoder, decode7zLzma, decode7zLzma2, decodeBcj, decodeBcjArm, decodeBcjArm64, decodeBcjArmt, decodeBcjIa64, decodeBcjPpc, decodeBcjSparc, decodeDelta } from 'xz-compat';
|
|
4
|
-
import { runDecode } from '../../lib/runDecode.js';
|
|
5
4
|
import { CodecId, createCodedError, ErrorCode } from '../constants.js';
|
|
6
5
|
import { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.js';
|
|
7
6
|
import { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.js';
|
|
@@ -10,24 +9,28 @@ import { createCopyDecoder, decodeCopy } from './Copy.js';
|
|
|
10
9
|
import { createDeflateDecoder, decodeDeflate } from './Deflate.js';
|
|
11
10
|
// Re-export password functions for API access
|
|
12
11
|
export { getPassword, setPassword };
|
|
12
|
+
const schedule = typeof setImmediate === 'function' ? setImmediate : (fn)=>process.nextTick(fn);
|
|
13
13
|
function wrapSyncDecode(fn) {
|
|
14
14
|
return (input, properties, unpackSize, callback)=>{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
schedule(()=>{
|
|
16
|
+
try {
|
|
17
|
+
// Convert BufferList to Buffer if needed
|
|
18
|
+
const buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
19
|
+
callback(null, fn(buf, properties, unpackSize));
|
|
20
|
+
} catch (err) {
|
|
21
|
+
callback(err);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
// Simple wrappers with validation that use xz-compat's optimized
|
|
26
|
+
// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2
|
|
21
27
|
function decodeLzma(input, properties, unpackSize, callback) {
|
|
22
|
-
if (
|
|
28
|
+
if (properties.length < 5) {
|
|
23
29
|
throw new Error('LZMA requires 5-byte properties');
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
runDecode((done)=>{
|
|
29
|
-
decode7zLzma(input, properties, unpackSize, done);
|
|
30
|
-
}, callback);
|
|
31
|
+
// Convert BufferList to Buffer if needed
|
|
32
|
+
const buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
33
|
+
decode7zLzma(buf, properties, unpackSize, callback);
|
|
31
34
|
}
|
|
32
35
|
function createLzmaDecoder(properties, unpackSize) {
|
|
33
36
|
if (!properties || properties.length < 5) {
|
|
@@ -39,12 +42,12 @@ function createLzmaDecoder(properties, unpackSize) {
|
|
|
39
42
|
return _createLzmaDecoder(properties, unpackSize);
|
|
40
43
|
}
|
|
41
44
|
function decodeLzma2(input, properties, unpackSize, callback) {
|
|
42
|
-
if (
|
|
45
|
+
if (properties.length < 1) {
|
|
43
46
|
throw new Error('LZMA2 requires properties byte');
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
// Convert BufferList to Buffer if needed
|
|
49
|
+
const buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
50
|
+
decode7zLzma2(buf, properties, unpackSize, callback);
|
|
48
51
|
}
|
|
49
52
|
function createLzma2Decoder(properties, _unpackSize) {
|
|
50
53
|
if (!properties || properties.length < 1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { type DecodeCallback as CodecDecodeCallback, runDecode } from '../../lib/runDecode.ts';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n runDecode((done) => {\n done(null, fn(input, properties, unpackSize));\n }, callback);\n };\n}\n\nexport interface Codec {\n decode: (input: Buffer, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLjma/decode7zLzma2\nfunction decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n runDecode((done) => {\n decode7zLzma(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n runDecode((done) => {\n decode7zLzma2(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["createLzma2Decoder","_createLzma2Decoder","createLzmaDecoder","_createLzmaDecoder","createBcjArm64Decoder","createBcjArmDecoder","createBcjArmtDecoder","createBcjDecoder","createBcjIa64Decoder","createBcjPpcDecoder","createBcjSparcDecoder","createDeltaDecoder","decode7zLzma","decode7zLzma2","decodeBcj","decodeBcjArm","decodeBcjArm64","decodeBcjArmt","decodeBcjIa64","decodeBcjPpc","decodeBcjSparc","decodeDelta","runDecode","CodecId","createCodedError","ErrorCode","createAesDecoder","decodeAes","getPassword","setPassword","createBcj2Decoder","decodeBcj2","decodeBcj2Multi","createBzip2Decoder","decodeBzip2","createCopyDecoder","decodeCopy","createDeflateDecoder","decodeDeflate","wrapSyncDecode","fn","input","properties","unpackSize","callback","done","decodeLzma","length","Error","decodeLzma2","_unpackSize","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","registerCodec","codec","getCodec","key","UNSUPPORTED_CODEC","isCodecSupported","undefined","getCodecName","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","isBcj2Codec","decode","createDecoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAG3E,SACEA,sBAAsBC,mBAAmB,EACzCC,qBAAqBC,kBAAkB,EACvCC,qBAAqB,EACrBC,mBAAmB,EACnBC,oBAAoB,EACpBC,gBAAgB,EAChBC,oBAAoB,EACpBC,mBAAmB,EACnBC,qBAAqB,EACrBC,kBAAkB,EAClBC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,aAAa,EACbC,aAAa,EACbC,YAAY,EACZC,cAAc,EACdC,WAAW,QACN,YAAY;AACnB,SAAqDC,SAAS,QAAQ,yBAAyB;AAC/F,SAASC,OAAO,EAAEC,gBAAgB,EAAEC,SAAS,QAAQ,kBAAkB;AACvE,SAASC,gBAAgB,EAAEC,SAAS,EAAEC,WAAW,EAAEC,WAAW,QAAQ,WAAW;AACjF,SAASC,iBAAiB,EAAEC,UAAU,EAAEC,eAAe,QAAQ,YAAY;AAC3E,SAASC,kBAAkB,EAAEC,WAAW,Q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{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { BufferLike } from 'extract-base-iterator';\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n type DecodeCallback as CodecDecodeCallback,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n schedule(() => {\n try {\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n callback(null, fn(buf, properties, unpackSize));\n } catch (err) {\n callback(err as Error);\n }\n });\n };\n}\n\nexport interface Codec {\n decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2\nfunction decodeLzma(input: BufferLike, properties: Buffer, unpackSize: number, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma(buf, properties, unpackSize, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: BufferLike, properties: Buffer, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma2(buf, properties, unpackSize, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["createLzma2Decoder","_createLzma2Decoder","createLzmaDecoder","_createLzmaDecoder","createBcjArm64Decoder","createBcjArmDecoder","createBcjArmtDecoder","createBcjDecoder","createBcjIa64Decoder","createBcjPpcDecoder","createBcjSparcDecoder","createDeltaDecoder","decode7zLzma","decode7zLzma2","decodeBcj","decodeBcjArm","decodeBcjArm64","decodeBcjArmt","decodeBcjIa64","decodeBcjPpc","decodeBcjSparc","decodeDelta","CodecId","createCodedError","ErrorCode","createAesDecoder","decodeAes","getPassword","setPassword","createBcj2Decoder","decodeBcj2","decodeBcj2Multi","createBzip2Decoder","decodeBzip2","createCopyDecoder","decodeCopy","createDeflateDecoder","decodeDeflate","schedule","setImmediate","fn","process","nextTick","wrapSyncDecode","input","properties","unpackSize","callback","buf","Buffer","isBuffer","toBuffer","err","decodeLzma","length","Error","decodeLzma2","_unpackSize","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","registerCodec","codec","getCodec","key","UNSUPPORTED_CODEC","isCodecSupported","undefined","getCodecName","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","isBcj2Codec","decode","createDecoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAI3E,SACEA,sBAAsBC,mBAAmB,EACzCC,qBAAqBC,kBAAkB,EAEvCC,qBAAqB,EACrBC,mBAAmB,EAC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C9BS,QAAQpD,eAAezB;IACvB8E,eAAexF;AACjB;AAEA,qBAAqB;AACrB8D,cAAchD,QAAQiE,SAAS,EAAE;IAC/BQ,QAAQpD,eAAevB;IACvB4E,eAAetF;AACjB;AAEA,eAAe;AACf4D,cAAchD,QAAQoE,KAAK,EAAE;IAC3BK,QAAQpD,eAAetB;IACvB2E,eAAerF;AACjB;AAEA,gBAAgB;AAChB2D,cAAchD,QAAQqE,OAAO,EAAE;IAC7BI,QAAQpD,eAAeN;IACvB2D,eAAe5D;AACjB;AAEA,cAAc;AACdkC,cAAchD,QAAQsE,KAAK,EAAE;IAC3BG,QAAQpD,eAAeV;IACvB+D,eAAehE;AACjB;AAEA,iCAAiC;AACjCsC,cAAchD,QAAQuE,GAAG,EAAE;IACzBE,QAAQpD,eAAejB;IACvBsE,eAAevE;AACjB;AAEA,sCAAsC;AACtC,sFAAsF;AACtF6C,cAAchD,QAAQkE,IAAI,EAAE;IAC1BO,QAAQjE;IACRkE,eAAenE;AACjB,IAEA,kEAAkE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "7z-iterator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Extract contents from 7z archives using an iterator API. Pure JavaScript, works on Node.js 0.8+",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extract",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"call-once-fn": "^1.1.6",
|
|
57
57
|
"extract-base-iterator": "^3.0.0",
|
|
58
58
|
"fs-remove-compat": "^1.0.0",
|
|
59
|
+
"graceful-fs": "^4.2.11",
|
|
59
60
|
"mkdirp-classic": "^0.5.2",
|
|
60
61
|
"on-one": "^1.0.10",
|
|
61
62
|
"os-shim": "^0.1.3",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;
|
|
2
|
-
type Executor<T> = (callback: DecodeCallback<T>) => void;
|
|
3
|
-
export declare function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void;
|
|
4
|
-
export declare function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void;
|
|
5
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;
|
|
2
|
-
type Executor<T> = (callback: DecodeCallback<T>) => void;
|
|
3
|
-
export declare function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void;
|
|
4
|
-
export declare function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void;
|
|
5
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get runDecode () {
|
|
13
|
-
return runDecode;
|
|
14
|
-
},
|
|
15
|
-
get runSync () {
|
|
16
|
-
return runSync;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
20
|
-
function _interop_require_default(obj) {
|
|
21
|
-
return obj && obj.__esModule ? obj : {
|
|
22
|
-
default: obj
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
var schedule = typeof setImmediate === 'function' ? setImmediate : function(fn) {
|
|
26
|
-
return process.nextTick(fn);
|
|
27
|
-
};
|
|
28
|
-
function runDecode(executor, callback) {
|
|
29
|
-
if (typeof callback === 'function') {
|
|
30
|
-
executor((0, _calloncefn.default)(callback));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (typeof Promise === 'undefined') {
|
|
34
|
-
throw new Error('Promises are not available in this runtime. Please provide a callback.');
|
|
35
|
-
}
|
|
36
|
-
return new Promise(function(resolve, reject) {
|
|
37
|
-
executor((0, _calloncefn.default)(function(err, value) {
|
|
38
|
-
if (err) {
|
|
39
|
-
reject(err);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
resolve(value);
|
|
43
|
-
}));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function runSync(fn, callback) {
|
|
47
|
-
schedule(function() {
|
|
48
|
-
try {
|
|
49
|
-
callback(null, fn());
|
|
50
|
-
} catch (err) {
|
|
51
|
-
callback(err);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/lib/runDecode.ts"],"sourcesContent":["import once from 'call-once-fn';\n\nexport type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;\n\ntype Executor<T> = (callback: DecodeCallback<T>) => void;\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nexport function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void {\n if (typeof callback === 'function') {\n executor(once(callback));\n return;\n }\n\n if (typeof Promise === 'undefined') {\n throw new Error('Promises are not available in this runtime. Please provide a callback.');\n }\n\n return new Promise<T>((resolve, reject) => {\n executor(\n once((err, value) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(value as T);\n })\n );\n });\n}\n\nexport function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void {\n schedule(() => {\n try {\n callback(null, fn());\n } catch (err) {\n callback(err as Error);\n }\n });\n}\n"],"names":["runDecode","runSync","schedule","setImmediate","fn","process","nextTick","executor","callback","once","Promise","Error","resolve","reject","err","value"],"mappings":";;;;;;;;;;;QAQgBA;eAAAA;;QAuBAC;eAAAA;;;iEA/BC;;;;;;AAMjB,IAAMC,WAAW,OAAOC,iBAAiB,aAAaA,eAAe,SAACC;WAAmBC,QAAQC,QAAQ,CAACF;;AAEnG,SAASJ,UAAaO,QAAqB,EAAEC,QAA4B;IAC9E,IAAI,OAAOA,aAAa,YAAY;QAClCD,SAASE,IAAAA,mBAAI,EAACD;QACd;IACF;IAEA,IAAI,OAAOE,YAAY,aAAa;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAO,IAAID,QAAW,SAACE,SAASC;QAC9BN,SACEE,IAAAA,mBAAI,EAAC,SAACK,KAAKC;YACT,IAAID,KAAK;gBACPD,OAAOC;gBACP;YACF;YACAF,QAAQG;QACV;IAEJ;AACF;AAEO,SAASd,QAAWG,EAAW,EAAEI,QAA2B;IACjEN,SAAS;QACP,IAAI;YACFM,SAAS,MAAMJ;QACjB,EAAE,OAAOU,KAAK;YACZN,SAASM;QACX;IACF;AACF"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;
|
|
2
|
-
type Executor<T> = (callback: DecodeCallback<T>) => void;
|
|
3
|
-
export declare function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void;
|
|
4
|
-
export declare function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void;
|
|
5
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import once from 'call-once-fn';
|
|
2
|
-
const schedule = typeof setImmediate === 'function' ? setImmediate : (fn)=>process.nextTick(fn);
|
|
3
|
-
export function runDecode(executor, callback) {
|
|
4
|
-
if (typeof callback === 'function') {
|
|
5
|
-
executor(once(callback));
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
if (typeof Promise === 'undefined') {
|
|
9
|
-
throw new Error('Promises are not available in this runtime. Please provide a callback.');
|
|
10
|
-
}
|
|
11
|
-
return new Promise((resolve, reject)=>{
|
|
12
|
-
executor(once((err, value)=>{
|
|
13
|
-
if (err) {
|
|
14
|
-
reject(err);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
resolve(value);
|
|
18
|
-
}));
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function runSync(fn, callback) {
|
|
22
|
-
schedule(()=>{
|
|
23
|
-
try {
|
|
24
|
-
callback(null, fn());
|
|
25
|
-
} catch (err) {
|
|
26
|
-
callback(err);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/iterators/7z-iterator/src/lib/runDecode.ts"],"sourcesContent":["import once from 'call-once-fn';\n\nexport type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;\n\ntype Executor<T> = (callback: DecodeCallback<T>) => void;\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nexport function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void {\n if (typeof callback === 'function') {\n executor(once(callback));\n return;\n }\n\n if (typeof Promise === 'undefined') {\n throw new Error('Promises are not available in this runtime. Please provide a callback.');\n }\n\n return new Promise<T>((resolve, reject) => {\n executor(\n once((err, value) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(value as T);\n })\n );\n });\n}\n\nexport function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void {\n schedule(() => {\n try {\n callback(null, fn());\n } catch (err) {\n callback(err as Error);\n }\n });\n}\n"],"names":["once","schedule","setImmediate","fn","process","nextTick","runDecode","executor","callback","Promise","Error","resolve","reject","err","value","runSync"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAMhC,MAAMC,WAAW,OAAOC,iBAAiB,aAAaA,eAAe,CAACC,KAAmBC,QAAQC,QAAQ,CAACF;AAE1G,OAAO,SAASG,UAAaC,QAAqB,EAAEC,QAA4B;IAC9E,IAAI,OAAOA,aAAa,YAAY;QAClCD,SAASP,KAAKQ;QACd;IACF;IAEA,IAAI,OAAOC,YAAY,aAAa;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAO,IAAID,QAAW,CAACE,SAASC;QAC9BL,SACEP,KAAK,CAACa,KAAKC;YACT,IAAID,KAAK;gBACPD,OAAOC;gBACP;YACF;YACAF,QAAQG;QACV;IAEJ;AACF;AAEA,OAAO,SAASC,QAAWZ,EAAW,EAAEK,QAA2B;IACjEP,SAAS;QACP,IAAI;YACFO,SAAS,MAAML;QACjB,EAAE,OAAOU,KAAK;YACZL,SAASK;QACX;IACF;AACF"}
|