7z-iterator 0.2.13 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/FileEntry.d.cts +3 -3
- package/dist/cjs/FileEntry.d.ts +3 -3
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/SevenZipIterator.d.cts +4 -4
- package/dist/cjs/SevenZipIterator.d.ts +4 -4
- package/dist/cjs/SevenZipIterator.js +70 -9
- package/dist/cjs/SevenZipIterator.js.map +1 -1
- package/dist/cjs/sevenz/ArchiveSource.d.cts +40 -0
- package/dist/cjs/sevenz/ArchiveSource.d.ts +40 -0
- package/dist/cjs/sevenz/ArchiveSource.js +82 -0
- package/dist/cjs/sevenz/ArchiveSource.js.map +1 -0
- package/dist/cjs/sevenz/NumberCodec.js.map +1 -1
- package/dist/cjs/sevenz/SevenZipParser.d.cts +21 -30
- package/dist/cjs/sevenz/SevenZipParser.d.ts +21 -30
- package/dist/cjs/sevenz/SevenZipParser.js +24 -54
- package/dist/cjs/sevenz/SevenZipParser.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Aes.js.map +1 -1
- package/dist/cjs/types.d.cts +4 -12
- package/dist/cjs/types.d.ts +4 -12
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/FileEntry.d.ts +3 -3
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/SevenZipIterator.d.ts +4 -4
- package/dist/esm/SevenZipIterator.js +26 -8
- package/dist/esm/SevenZipIterator.js.map +1 -1
- package/dist/esm/sevenz/ArchiveSource.d.ts +40 -0
- package/dist/esm/sevenz/ArchiveSource.js +54 -0
- package/dist/esm/sevenz/ArchiveSource.js.map +1 -0
- package/dist/esm/sevenz/SevenZipParser.d.ts +21 -30
- package/dist/esm/sevenz/SevenZipParser.js +21 -46
- package/dist/esm/sevenz/SevenZipParser.js.map +1 -1
- package/dist/esm/types.d.ts +4 -12
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/package.json +15 -16
- package/dist/cjs/lib/Lock.d.cts +0 -12
- package/dist/cjs/lib/Lock.d.ts +0 -12
- package/dist/cjs/lib/Lock.js +0 -71
- package/dist/cjs/lib/Lock.js.map +0 -1
- package/dist/esm/lib/Lock.d.ts +0 -12
- package/dist/esm/lib/Lock.js +0 -47
- package/dist/esm/lib/Lock.js.map +0 -1
package/dist/cjs/FileEntry.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type FileAttributes, FileEntry, type NoParamCallback } from 'extract-base-iterator';
|
|
1
|
+
import { type FileAttributes, FileEntry, type Lock, type NoParamCallback } from 'extract-base-iterator';
|
|
2
2
|
import type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.js';
|
|
3
|
-
import type { ExtractOptions
|
|
3
|
+
import type { ExtractOptions } from './types.js';
|
|
4
4
|
export default class SevenZipFileEntry extends FileEntry {
|
|
5
5
|
private lock;
|
|
6
6
|
private entry;
|
|
7
7
|
private parser;
|
|
8
|
-
constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock:
|
|
8
|
+
constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock: Lock);
|
|
9
9
|
create(dest: string, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | Promise<boolean>;
|
|
10
10
|
_writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined;
|
|
11
11
|
destroy(): void;
|
package/dist/cjs/FileEntry.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type FileAttributes, FileEntry, type NoParamCallback } from 'extract-base-iterator';
|
|
1
|
+
import { type FileAttributes, FileEntry, type Lock, type NoParamCallback } from 'extract-base-iterator';
|
|
2
2
|
import type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.js';
|
|
3
|
-
import type { ExtractOptions
|
|
3
|
+
import type { ExtractOptions } from './types.js';
|
|
4
4
|
export default class SevenZipFileEntry extends FileEntry {
|
|
5
5
|
private lock;
|
|
6
6
|
private entry;
|
|
7
7
|
private parser;
|
|
8
|
-
constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock:
|
|
8
|
+
constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock: Lock);
|
|
9
9
|
create(dest: string, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | Promise<boolean>;
|
|
10
10
|
_writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined;
|
|
11
11
|
destroy(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/FileEntry.ts"],"sourcesContent":["import { type FileAttributes, FileEntry, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\nimport type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\nimport type { ExtractOptions
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/FileEntry.ts"],"sourcesContent":["import { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\nimport type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class SevenZipFileEntry extends FileEntry {\n private lock: Lock;\n private entry: SevenZipEntry;\n private parser: SevenZipParser;\n\n constructor(attributes: FileAttributes, entry: SevenZipEntry, parser: SevenZipParser, lock: Lock) {\n super(attributes);\n this.entry = entry;\n this.parser = parser;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n\n if (typeof callback === 'function') {\n options = options || {};\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): undefined {\n if (!this.entry || !this.parser) {\n callback(new Error('7z FileEntry missing entry. Check for calling create multiple times'));\n return;\n }\n\n // Use callback-based async decompression\n this.parser.getEntryStreamAsync(this.entry, (err, stream) => {\n if (err) return callback(err);\n if (!stream) return callback(new Error('No stream returned'));\n\n const res = stream.pipe(fs.createWriteStream(fullPath));\n oo(res, ['error', 'end', 'close', 'finish'], (writeErr?: Error) => {\n writeErr ? callback(writeErr) : waitForAccess(fullPath, callback);\n });\n });\n }\n\n destroy() {\n FileEntry.prototype.destroy.call(this);\n this.entry = null;\n this.parser = null;\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n }\n}\n"],"names":["SevenZipFileEntry","attributes","entry","parser","lock","retain","create","dest","options","callback","FileEntry","prototype","call","err","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","Error","getEntryStreamAsync","stream","res","pipe","fs","createWriteStream","oo","writeErr","waitForAccess","destroy"],"mappings":";;;;;;;eAMqBA;;;mCAN0E;yDAChF;4DACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAA,AAAMA,kCAAN;;cAAMA;aAAAA,kBAKPC,UAA0B,EAAEC,KAAoB,EAAEC,MAAsB,EAAEC,IAAU;gCAL7EJ;;gBAMjB,kBANiBA;YAMXC;;QACN,MAAKC,KAAK,GAAGA;QACb,MAAKC,MAAM,GAAGA;QACd,MAAKC,IAAI,GAAGA;QACZ,MAAKA,IAAI,CAACC,MAAM;;;iBAVCL;IAanBM,OAAAA,MAqBC,GArBDA,SAAAA,OAAOC,IAAY,EAAEC,OAAyC,EAAEC,QAAyB;;Q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C,MAAM,GAAG;QACd,IAAI,IAAI,CAACC,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACU,OAAO;YACjB,IAAI,CAACV,IAAI,GAAG;QACd;IACF;WA9DmBJ;EAA0BU,8BAAS"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import BaseIterator from 'extract-base-iterator';
|
|
2
|
-
import type {
|
|
3
|
-
export default class SevenZipIterator extends BaseIterator {
|
|
4
|
-
lock:
|
|
1
|
+
import BaseIterator, { Lock } from 'extract-base-iterator';
|
|
2
|
+
import type { Entry, ExtractOptions, SevenZipFileIterator } from './types.js';
|
|
3
|
+
export default class SevenZipIterator extends BaseIterator<Entry> {
|
|
4
|
+
lock: Lock | null;
|
|
5
5
|
iterator: SevenZipFileIterator;
|
|
6
6
|
constructor(source: string | NodeJS.ReadableStream, options?: ExtractOptions);
|
|
7
7
|
end(err?: Error): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import BaseIterator from 'extract-base-iterator';
|
|
2
|
-
import type {
|
|
3
|
-
export default class SevenZipIterator extends BaseIterator {
|
|
4
|
-
lock:
|
|
1
|
+
import BaseIterator, { Lock } from 'extract-base-iterator';
|
|
2
|
+
import type { Entry, ExtractOptions, SevenZipFileIterator } from './types.js';
|
|
3
|
+
export default class SevenZipIterator extends BaseIterator<Entry> {
|
|
4
|
+
lock: Lock | null;
|
|
5
5
|
iterator: SevenZipFileIterator;
|
|
6
6
|
constructor(source: string | NodeJS.ReadableStream, options?: ExtractOptions);
|
|
7
7
|
end(err?: Error): void;
|
|
@@ -8,14 +8,14 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return SevenZipIterator;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var _extractbaseiterator = /*#__PURE__*/
|
|
11
|
+
var _extractbaseiterator = /*#__PURE__*/ _interop_require_wildcard(require("extract-base-iterator"));
|
|
12
12
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
13
|
+
var _fsremovecompat = require("fs-remove-compat");
|
|
13
14
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
15
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
15
16
|
var _shorthash = /*#__PURE__*/ _interop_require_default(require("short-hash"));
|
|
16
17
|
var _tempsuffix = /*#__PURE__*/ _interop_require_default(require("temp-suffix"));
|
|
17
18
|
var _compatts = require("./compat.js");
|
|
18
|
-
var _Lockts = /*#__PURE__*/ _interop_require_default(require("./lib/Lock.js"));
|
|
19
19
|
var _streamToSourcets = /*#__PURE__*/ _interop_require_default(require("./lib/streamToSource.js"));
|
|
20
20
|
var _nextEntryts = /*#__PURE__*/ _interop_require_default(require("./nextEntry.js"));
|
|
21
21
|
var _indexts = require("./sevenz/codecs/index.js");
|
|
@@ -59,6 +59,47 @@ function _interop_require_default(obj) {
|
|
|
59
59
|
default: obj
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
63
|
+
if (typeof WeakMap !== "function") return null;
|
|
64
|
+
var cacheBabelInterop = new WeakMap();
|
|
65
|
+
var cacheNodeInterop = new WeakMap();
|
|
66
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
67
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
68
|
+
})(nodeInterop);
|
|
69
|
+
}
|
|
70
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
71
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
72
|
+
return obj;
|
|
73
|
+
}
|
|
74
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
75
|
+
return {
|
|
76
|
+
default: obj
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
80
|
+
if (cache && cache.has(obj)) {
|
|
81
|
+
return cache.get(obj);
|
|
82
|
+
}
|
|
83
|
+
var newObj = {
|
|
84
|
+
__proto__: null
|
|
85
|
+
};
|
|
86
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
87
|
+
for(var key in obj){
|
|
88
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
89
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
90
|
+
if (desc && (desc.get || desc.set)) {
|
|
91
|
+
Object.defineProperty(newObj, key, desc);
|
|
92
|
+
} else {
|
|
93
|
+
newObj[key] = obj[key];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
newObj.default = obj;
|
|
98
|
+
if (cache) {
|
|
99
|
+
cache.set(obj, newObj);
|
|
100
|
+
}
|
|
101
|
+
return newObj;
|
|
102
|
+
}
|
|
62
103
|
function _possible_constructor_return(self, call) {
|
|
63
104
|
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
64
105
|
return call;
|
|
@@ -116,8 +157,10 @@ var SevenZipIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
116
157
|
_this = _call_super(this, SevenZipIterator, [
|
|
117
158
|
options
|
|
118
159
|
]);
|
|
119
|
-
_this.lock = new
|
|
120
|
-
_this.lock.
|
|
160
|
+
_this.lock = new _extractbaseiterator.Lock();
|
|
161
|
+
_this.lock.onDestroy = function(err) {
|
|
162
|
+
return _extractbaseiterator.default.prototype.end.call(_this, err);
|
|
163
|
+
};
|
|
121
164
|
var queue = new _queuecb.default(1);
|
|
122
165
|
var cancelled = false;
|
|
123
166
|
var archiveSource = null;
|
|
@@ -138,15 +181,22 @@ var SevenZipIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
138
181
|
if (_this.done || cancelled) return;
|
|
139
182
|
if (err) return cb(err);
|
|
140
183
|
archiveSource = new _SevenZipParserts.FileSource(fd, stats.size);
|
|
141
|
-
|
|
184
|
+
// Register cleanup for file descriptor
|
|
185
|
+
_this.lock.registerCleanup(function() {
|
|
186
|
+
_fs.default.closeSync(fd);
|
|
187
|
+
});
|
|
142
188
|
cb();
|
|
143
189
|
});
|
|
144
190
|
});
|
|
145
191
|
});
|
|
146
192
|
} else {
|
|
147
193
|
// Stream input - use hybrid memory/temp-file approach
|
|
148
|
-
//
|
|
149
|
-
|
|
194
|
+
// Register cleanup for source stream
|
|
195
|
+
var stream = source;
|
|
196
|
+
_this.lock.registerCleanup(function() {
|
|
197
|
+
var s = stream;
|
|
198
|
+
if (typeof s.destroy === 'function') s.destroy();
|
|
199
|
+
});
|
|
150
200
|
var tempPath = _path.default.join((0, _compatts.tmpdir)(), '7z-iterator', (0, _shorthash.default)(process.cwd()), (0, _tempsuffix.default)('tmp.7z'));
|
|
151
201
|
queue.defer(function(cb) {
|
|
152
202
|
(0, _streamToSourcets.default)(source, {
|
|
@@ -158,10 +208,21 @@ var SevenZipIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
158
208
|
if (!result) return cb(new Error('No result from streamToSource'));
|
|
159
209
|
archiveSource = result.source;
|
|
160
210
|
if (result.fd !== undefined) {
|
|
161
|
-
|
|
211
|
+
var fd = result.fd;
|
|
212
|
+
// Register cleanup for file descriptor
|
|
213
|
+
_this.lock.registerCleanup(function() {
|
|
214
|
+
_fs.default.closeSync(fd);
|
|
215
|
+
});
|
|
162
216
|
}
|
|
163
217
|
if (result.tempPath) {
|
|
164
|
-
|
|
218
|
+
var tp = result.tempPath;
|
|
219
|
+
// Register cleanup for temp file
|
|
220
|
+
_this.lock.registerCleanup(function() {
|
|
221
|
+
try {
|
|
222
|
+
(0, _fsremovecompat.rmSync)(tp);
|
|
223
|
+
} catch (_e) {
|
|
224
|
+
/* ignore */ }
|
|
225
|
+
});
|
|
165
226
|
}
|
|
166
227
|
cb();
|
|
167
228
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/SevenZipIterator.ts"],"sourcesContent":["import BaseIterator from 'extract-base-iterator';\nimport fs from '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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/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, SevenZipFileIterator } from './types.ts';\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 iterator: SevenZipFileIterator;\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 = (): undefined => {\n cancelled = true;\n return undefined;\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 - use hybrid memory/temp-file approach\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(\n source,\n {\n memoryThreshold: options.memoryThreshold,\n tempPath: tempPath,\n },\n (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 if (result.fd !== undefined) {\n const fd = result.fd;\n // Register cleanup for file descriptor\n this.lock.registerCleanup(() => {\n fs.closeSync(fd);\n });\n }\n if (result.tempPath) {\n const tp = result.tempPath;\n // Register cleanup for temp file\n this.lock.registerCleanup(() => {\n try {\n rmSync(tp);\n } catch (_e) {\n /* ignore */\n }\n });\n }\n cb();\n }\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 try {\n const parser = new SevenZipParser(archiveSource);\n parser.parse();\n this.iterator = new EntryIterator(parser);\n cb();\n } catch (parseErr) {\n cb(parseErr as Error);\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"],"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","undefined","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","memoryThreshold","result","Error","tp","rmSync","_e","SevenZipParser","parse","iterator","parseErr","await","remove","nextEntry","release"],"mappings":";;;;;;;eAwCqBA;;;2EAxCc;yDACpB;8BACQ;2DACN;8DACC;gEACI;iEACC;wBACA;uEAC2B;kEAC5B;uBACM;gCACuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAInF;;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,iBAIPS,MAAsC;YAAEC,UAAAA,iEAA0B,CAAC;gCAJ5DV;;gBAKjB,kBALiBA;YAKXU;;QACN,MAAKC,IAAI,GAAG,IAAIC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AACwC,oBAAS;QAC3C;;;iBA3GiBlE;IA8GnBiB,OAAAA,GASC,GATDA,SAAAA,IAAIH,GAAW;QACb,IAAI,IAAI,CAACH,IAAI,EAAE;YACb,IAAMA,OAAO,IAAI,CAACA,IAAI;YACtB,IAAI,CAACA,IAAI,GAAG,MAAM,8CAA8C;YAChEA,KAAKG,GAAG,GAAGA;YACXH,KAAKwD,OAAO;QACd;QACA,yDAAyD;QACzD,IAAI,CAACL,QAAQ,GAAG;IAClB;WAvHmB9D;EAAyBe,4BAAY"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArchiveSource - Abstraction for reading 7z archive data
|
|
3
|
+
*
|
|
4
|
+
* Provides a common interface for reading archive data from either
|
|
5
|
+
* a file descriptor or an in-memory buffer.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Archive source abstraction - allows reading from file descriptor or buffer
|
|
9
|
+
*/
|
|
10
|
+
export interface ArchiveSource {
|
|
11
|
+
read(position: number, length: number): Buffer;
|
|
12
|
+
getSize(): number;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Buffer-based archive source
|
|
17
|
+
*
|
|
18
|
+
* Used when the entire archive is already in memory.
|
|
19
|
+
*/
|
|
20
|
+
export declare class BufferSource implements ArchiveSource {
|
|
21
|
+
private buffer;
|
|
22
|
+
constructor(buffer: Buffer);
|
|
23
|
+
read(position: number, length: number): Buffer;
|
|
24
|
+
getSize(): number;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* File descriptor based archive source
|
|
29
|
+
*
|
|
30
|
+
* Used for reading directly from a file on disk.
|
|
31
|
+
* More memory efficient for large archives.
|
|
32
|
+
*/
|
|
33
|
+
export declare class FileSource implements ArchiveSource {
|
|
34
|
+
private fd;
|
|
35
|
+
private size;
|
|
36
|
+
constructor(fd: number, size: number);
|
|
37
|
+
read(position: number, length: number): Buffer;
|
|
38
|
+
getSize(): number;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArchiveSource - Abstraction for reading 7z archive data
|
|
3
|
+
*
|
|
4
|
+
* Provides a common interface for reading archive data from either
|
|
5
|
+
* a file descriptor or an in-memory buffer.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Archive source abstraction - allows reading from file descriptor or buffer
|
|
9
|
+
*/
|
|
10
|
+
export interface ArchiveSource {
|
|
11
|
+
read(position: number, length: number): Buffer;
|
|
12
|
+
getSize(): number;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Buffer-based archive source
|
|
17
|
+
*
|
|
18
|
+
* Used when the entire archive is already in memory.
|
|
19
|
+
*/
|
|
20
|
+
export declare class BufferSource implements ArchiveSource {
|
|
21
|
+
private buffer;
|
|
22
|
+
constructor(buffer: Buffer);
|
|
23
|
+
read(position: number, length: number): Buffer;
|
|
24
|
+
getSize(): number;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* File descriptor based archive source
|
|
29
|
+
*
|
|
30
|
+
* Used for reading directly from a file on disk.
|
|
31
|
+
* More memory efficient for large archives.
|
|
32
|
+
*/
|
|
33
|
+
export declare class FileSource implements ArchiveSource {
|
|
34
|
+
private fd;
|
|
35
|
+
private size;
|
|
36
|
+
constructor(fd: number, size: number);
|
|
37
|
+
read(position: number, length: number): Buffer;
|
|
38
|
+
getSize(): number;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArchiveSource - Abstraction for reading 7z archive data
|
|
3
|
+
*
|
|
4
|
+
* Provides a common interface for reading archive data from either
|
|
5
|
+
* a file descriptor or an in-memory buffer.
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
get BufferSource () {
|
|
18
|
+
return BufferSource;
|
|
19
|
+
},
|
|
20
|
+
get FileSource () {
|
|
21
|
+
return FileSource;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _extractbaseiterator = require("extract-base-iterator");
|
|
25
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
26
|
+
function _class_call_check(instance, Constructor) {
|
|
27
|
+
if (!(instance instanceof Constructor)) {
|
|
28
|
+
throw new TypeError("Cannot call a class as a function");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var BufferSource = /*#__PURE__*/ function() {
|
|
37
|
+
"use strict";
|
|
38
|
+
function BufferSource(buffer) {
|
|
39
|
+
_class_call_check(this, BufferSource);
|
|
40
|
+
this.buffer = buffer;
|
|
41
|
+
}
|
|
42
|
+
var _proto = BufferSource.prototype;
|
|
43
|
+
_proto.read = function read(position, length) {
|
|
44
|
+
return this.buffer.slice(position, position + length);
|
|
45
|
+
};
|
|
46
|
+
_proto.getSize = function getSize() {
|
|
47
|
+
return this.buffer.length;
|
|
48
|
+
};
|
|
49
|
+
_proto.close = function close() {
|
|
50
|
+
// Nothing to close for buffer
|
|
51
|
+
};
|
|
52
|
+
return BufferSource;
|
|
53
|
+
}();
|
|
54
|
+
var FileSource = /*#__PURE__*/ function() {
|
|
55
|
+
"use strict";
|
|
56
|
+
function FileSource(fd, size) {
|
|
57
|
+
_class_call_check(this, FileSource);
|
|
58
|
+
this.fd = fd;
|
|
59
|
+
this.size = size;
|
|
60
|
+
}
|
|
61
|
+
var _proto = FileSource.prototype;
|
|
62
|
+
_proto.read = function read(position, length) {
|
|
63
|
+
var buf = (0, _extractbaseiterator.allocBuffer)(length);
|
|
64
|
+
var bytesRead = _fs.default.readSync(this.fd, buf, 0, length, position);
|
|
65
|
+
if (bytesRead < length) {
|
|
66
|
+
return buf.slice(0, bytesRead);
|
|
67
|
+
}
|
|
68
|
+
return buf;
|
|
69
|
+
};
|
|
70
|
+
_proto.getSize = function getSize() {
|
|
71
|
+
return this.size;
|
|
72
|
+
};
|
|
73
|
+
_proto.close = function close() {
|
|
74
|
+
try {
|
|
75
|
+
_fs.default.closeSync(this.fd);
|
|
76
|
+
} catch (_e) {
|
|
77
|
+
// Ignore close errors
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return FileSource;
|
|
81
|
+
}();
|
|
82
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/ArchiveSource.ts"],"sourcesContent":["/**\n * ArchiveSource - Abstraction for reading 7z archive data\n *\n * Provides a common interface for reading archive data from either\n * a file descriptor or an in-memory buffer.\n */\n\nimport { allocBuffer } from 'extract-base-iterator';\nimport fs from 'fs';\n\n/**\n * Archive source abstraction - allows reading from file descriptor or buffer\n */\nexport interface ArchiveSource {\n read(position: number, length: number): Buffer;\n getSize(): number;\n close(): void;\n}\n\n/**\n * Buffer-based archive source\n *\n * Used when the entire archive is already in memory.\n */\nexport class BufferSource implements ArchiveSource {\n private buffer: Buffer;\n\n constructor(buffer: Buffer) {\n this.buffer = buffer;\n }\n\n read(position: number, length: number): Buffer {\n return this.buffer.slice(position, position + length);\n }\n\n getSize(): number {\n return this.buffer.length;\n }\n\n close(): void {\n // Nothing to close for buffer\n }\n}\n\n/**\n * File descriptor based archive source\n *\n * Used for reading directly from a file on disk.\n * More memory efficient for large archives.\n */\nexport class FileSource implements ArchiveSource {\n private fd: number;\n private size: number;\n\n constructor(fd: number, size: number) {\n this.fd = fd;\n this.size = size;\n }\n\n read(position: number, length: number): Buffer {\n const buf = allocBuffer(length);\n const bytesRead = fs.readSync(this.fd, buf, 0, length, position);\n if (bytesRead < length) {\n return buf.slice(0, bytesRead);\n }\n return buf;\n }\n\n getSize(): number {\n return this.size;\n }\n\n close(): void {\n try {\n fs.closeSync(this.fd);\n } catch (_e) {\n // Ignore close errors\n }\n }\n}\n"],"names":["BufferSource","FileSource","buffer","read","position","length","slice","getSize","close","fd","size","buf","allocBuffer","bytesRead","fs","readSync","closeSync","_e"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAmBYA;eAAAA;;QA0BAC;eAAAA;;;mCA3Ce;yDACb;;;;;;;;;;;AAgBR,IAAA,AAAMD,6BAAN;;aAAMA,aAGCE,MAAc;gCAHfF;QAIT,IAAI,CAACE,MAAM,GAAGA;;iBAJLF;IAOXG,OAAAA,IAEC,GAFDA,SAAAA,KAAKC,QAAgB,EAAEC,MAAc;QACnC,OAAO,IAAI,CAACH,MAAM,CAACI,KAAK,CAACF,UAAUA,WAAWC;IAChD;IAEAE,OAAAA,OAEC,GAFDA,SAAAA;QACE,OAAO,IAAI,CAACL,MAAM,CAACG,MAAM;IAC3B;IAEAG,OAAAA,KAEC,GAFDA,SAAAA;IACE,8BAA8B;IAChC;WAjBWR;;AA0BN,IAAA,AAAMC,2BAAN;;aAAMA,WAICQ,EAAU,EAAEC,IAAY;gCAJzBT;QAKT,IAAI,CAACQ,EAAE,GAAGA;QACV,IAAI,CAACC,IAAI,GAAGA;;iBANHT;IASXE,OAAAA,IAOC,GAPDA,SAAAA,KAAKC,QAAgB,EAAEC,MAAc;QACnC,IAAMM,MAAMC,IAAAA,gCAAW,EAACP;QACxB,IAAMQ,YAAYC,WAAE,CAACC,QAAQ,CAAC,IAAI,CAACN,EAAE,EAAEE,KAAK,GAAGN,QAAQD;QACvD,IAAIS,YAAYR,QAAQ;YACtB,OAAOM,IAAIL,KAAK,CAAC,GAAGO;QACtB;QACA,OAAOF;IACT;IAEAJ,OAAAA,OAEC,GAFDA,SAAAA;QACE,OAAO,IAAI,CAACG,IAAI;IAClB;IAEAF,OAAAA,KAMC,GANDA,SAAAA;QACE,IAAI;YACFM,WAAE,CAACE,SAAS,CAAC,IAAI,CAACP,EAAE;QACtB,EAAE,OAAOQ,IAAI;QACX,sBAAsB;QACxB;IACF;WA5BWhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/NumberCodec.ts"],"sourcesContent":["// Variable-length integer encoding for 7z format\n// Reference: https://py7zr.readthedocs.io/en/latest/archive_format.html\n//\n// 7z uses a space-efficient encoding where the first byte determines length:\n// 0xxxxxxx -> 1 byte (0-127)\n// 10xxxxxx xxxxxxxx -> 2 bytes (0-16383)\n// 110xxxxx + 2 bytes -> 3 bytes\n// 1110xxxx + 3 bytes -> 4 bytes\n// 11110xxx + 4 bytes -> 5 bytes\n// 111110xx + 5 bytes -> 6 bytes\n// 1111110x + 6 bytes -> 7 bytes\n// 11111110 + 7 bytes -> 8 bytes\n// 11111111 + 8 bytes -> 9 bytes (full 64-bit)\n//\n// NOTE: Returns JavaScript number which is accurate up to 2^53 - 1 (~9 PB).\n// This covers all practical file sizes.\n\nimport { readUInt64LE } from 'extract-base-iterator';\n\nexport interface NumberReadResult {\n value: number;\n bytesRead: number;\n}\n\n/**\n * Read a variable-length encoded number from a buffer\n * Uses 7z's variable-length uint64 encoding where the first byte indicates\n * how many additional bytes follow based on its value:\n * - 0x00-0x7F: 0 extra bytes (7 bits of data)\n * - 0x80-0xBF: 1 extra byte (14 bits of data)\n * - 0xC0-0xDF: 2 extra bytes (21 bits of data)\n * - 0xE0-0xEF: 3 extra bytes (28 bits of data)\n * - etc.\n * - 0xFF: 8 extra bytes (full 64-bit value)\n *\n * @param buf - Buffer containing encoded number\n * @param offset - Offset to start reading from\n * @returns Object with value and number of bytes consumed\n */\nexport function readNumber(buf: Buffer, offset: number): NumberReadResult {\n const firstByte = buf[offset];\n\n // Special case: 0xFF means 8 extra bytes (full 64-bit value)\n if (firstByte === 0xff) {\n return {\n value: readUInt64LE(buf, offset + 1),\n bytesRead: 9,\n };\n }\n\n // Determine number of extra bytes based on first byte value thresholds\n // This matches the 7z format specification\n let extraBytes = 0;\n let mask = 0x80;\n\n if (firstByte <= 0x7f) {\n extraBytes = 0;\n mask = 0x80;\n } else if (firstByte <= 0xbf) {\n extraBytes = 1;\n mask = 0x40;\n } else if (firstByte <= 0xdf) {\n extraBytes = 2;\n mask = 0x20;\n } else if (firstByte <= 0xef) {\n extraBytes = 3;\n mask = 0x10;\n } else if (firstByte <= 0xf7) {\n extraBytes = 4;\n mask = 0x08;\n } else if (firstByte <= 0xfb) {\n extraBytes = 5;\n mask = 0x04;\n } else if (firstByte <= 0xfd) {\n extraBytes = 6;\n mask = 0x02;\n } else {\n // 0xFE\n extraBytes = 7;\n mask = 0x01;\n }\n\n // Get high part from first byte (bits below the length indicator)\n const highPart = firstByte & (mask - 1);\n\n // Read extra bytes as LITTLE-ENDIAN\n let value = 0;\n for (let i = 0; i < extraBytes; i++) {\n value += buf[offset + 1 + i] * 256 ** i;\n }\n\n // Combine: value + (highPart << (extraBytes * 8))\n value += highPart * 256 ** extraBytes;\n\n return {\n value: value,\n bytesRead: 1 + extraBytes,\n };\n}\n\n/**\n * Read a raw 64-bit little-endian number (used in some fixed-size fields)\n * @param buf - Buffer containing the number\n * @param offset - Offset to start reading from\n * @returns The number value\n */\nexport function readRawNumber(buf: Buffer, offset: number): number {\n return readUInt64LE(buf, offset);\n}\n\n/**\n * Calculate the encoded size of a number\n * @param value - The number to encode\n * @returns Number of bytes needed to encode the value\n */\nexport function encodedSize(value: number): number {\n if (value < 0x80) return 1; // 7 bits\n if (value < 0x4000) return 2; // 14 bits\n if (value < 0x200000) return 3; // 21 bits\n if (value < 0x10000000) return 4; // 28 bits\n if (value < 0x800000000) return 5; // 35 bits\n if (value < 0x40000000000) return 6; // 42 bits\n if (value < 0x2000000000000) return 7; // 49 bits\n // 2^56 = 72057594037927936 (use calculated value to avoid precision loss)\n if (value < 72057594037927936) return 8; // 56 bits\n return 9; // 64 bits\n}\n\n/**\n * Read a boolean encoded as a single byte\n * @param buf - Buffer to read from\n * @param offset - Offset to read from\n * @returns true if byte is non-zero\n */\nexport function readBoolean(buf: Buffer, offset: number): boolean {\n return buf[offset] !== 0;\n}\n\n/**\n * Read a \"defined\" bitmask for an array of items.\n * Used when some items in a list have optional values.\n *\n * Format: If \"allDefined\" byte is 0, a bitmask follows indicating which items have values.\n * If \"allDefined\" byte is non-zero, all items are defined.\n *\n * @param buf - Buffer to read from\n * @param offset - Offset to start reading\n * @param count - Number of items\n * @returns Object with defined array and bytes consumed\n */\nexport function readDefinedVector(buf: Buffer, offset: number, count: number): { defined: boolean[]; bytesRead: number } {\n const allDefined = buf[offset] !== 0;\n let bytesRead = 1;\n const defined: boolean[] = [];\n\n if (allDefined) {\n // All items are defined\n for (let i = 0; i < count; i++) {\n defined.push(true);\n }\n } else {\n // Read bitmask\n const bitsNeeded = count;\n const bytesNeeded = Math.ceil(bitsNeeded / 8);\n\n for (let byteIdx = 0; byteIdx < bytesNeeded; byteIdx++) {\n const byte = buf[offset + 1 + byteIdx];\n for (let bit = 7; bit >= 0 && defined.length < count; bit--) {\n defined.push((byte & (1 << bit)) !== 0);\n }\n }\n bytesRead += bytesNeeded;\n }\n\n return { defined: defined, bytesRead: bytesRead };\n}\n\n/**\n * Read an array of variable-length numbers\n * @param buf - Buffer to read from\n * @param offset - Offset to start reading\n * @param count - Number of items to read\n * @returns Object with values array and bytes consumed\n */\nexport function readNumberArray(buf: Buffer, offset: number, count: number): { values: number[]; bytesRead: number } {\n const values: number[] = [];\n let totalBytesRead = 0;\n\n for (let i = 0; i < count; i++) {\n const result = readNumber(buf, offset + totalBytesRead);\n values.push(result.value);\n totalBytesRead += result.bytesRead;\n }\n\n return { values: values, bytesRead: totalBytesRead };\n}\n"],"names":["encodedSize","readBoolean","readDefinedVector","readNumber","readNumberArray","readRawNumber","buf","offset","firstByte","value","readUInt64LE","bytesRead","extraBytes","mask","highPart","i","count","allDefined","defined","push","bitsNeeded","bytesNeeded","Math","ceil","byteIdx","byte","bit","length","values","totalBytesRead","result"],"mappings":"AAAA,iDAAiD;AACjD,wEAAwE;AACxE,EAAE;AACF,6EAA6E;AAC7E,iDAAiD;AACjD,mDAAmD;AACnD,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,uDAAuD;AACvD,EAAE;AACF,4EAA4E;AAC5E,wCAAwC;;;;;;;;;;;;QAoGxBA;eAAAA;;QAmBAC;eAAAA;;QAgBAC;eAAAA;;QA/GAC;eAAAA;;QAiJAC;eAAAA;;QA9EAC;eAAAA;;;mCAzFa;AAsBtB,SAASF,WAAWG,GAAW,EAAEC,MAAc;IACpD,IAAMC,YAAYF,GAAG,CAACC,OAAO;IAE7B,6DAA6D;IAC7D,IAAIC,cAAc,MAAM;QACtB,OAAO;YACLC,OAAOC,IAAAA,iCAAY,EAACJ,KAAKC,SAAS;YAClCI,WAAW;QACb;IACF;IAEA,uEAAuE;IACvE,2CAA2C;IAC3C,IAAIC,aAAa;IACjB,IAAIC,OAAO;IAEX,IAAIL,aAAa,MAAM;QACrBI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO;QACL,OAAO;QACPD,aAAa;QACbC,OAAO;IACT;IAEA,kEAAkE;IAClE,IAAMC,WAAWN,YAAaK,OAAO;IAErC,oCAAoC;IACpC,IAAIJ,QAAQ;IACZ,IAAK,IAAIM,IAAI,GAAGA,IAAIH,YAAYG,IAAK;QACnCN,SAASH,GAAG,CAACC,SAAS,IAAIQ,EAAE,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/NumberCodec.ts"],"sourcesContent":["// Variable-length integer encoding for 7z format\n// Reference: https://py7zr.readthedocs.io/en/latest/archive_format.html\n//\n// 7z uses a space-efficient encoding where the first byte determines length:\n// 0xxxxxxx -> 1 byte (0-127)\n// 10xxxxxx xxxxxxxx -> 2 bytes (0-16383)\n// 110xxxxx + 2 bytes -> 3 bytes\n// 1110xxxx + 3 bytes -> 4 bytes\n// 11110xxx + 4 bytes -> 5 bytes\n// 111110xx + 5 bytes -> 6 bytes\n// 1111110x + 6 bytes -> 7 bytes\n// 11111110 + 7 bytes -> 8 bytes\n// 11111111 + 8 bytes -> 9 bytes (full 64-bit)\n//\n// NOTE: Returns JavaScript number which is accurate up to 2^53 - 1 (~9 PB).\n// This covers all practical file sizes.\n\nimport { readUInt64LE } from 'extract-base-iterator';\n\nexport interface NumberReadResult {\n value: number;\n bytesRead: number;\n}\n\n/**\n * Read a variable-length encoded number from a buffer\n * Uses 7z's variable-length uint64 encoding where the first byte indicates\n * how many additional bytes follow based on its value:\n * - 0x00-0x7F: 0 extra bytes (7 bits of data)\n * - 0x80-0xBF: 1 extra byte (14 bits of data)\n * - 0xC0-0xDF: 2 extra bytes (21 bits of data)\n * - 0xE0-0xEF: 3 extra bytes (28 bits of data)\n * - etc.\n * - 0xFF: 8 extra bytes (full 64-bit value)\n *\n * @param buf - Buffer containing encoded number\n * @param offset - Offset to start reading from\n * @returns Object with value and number of bytes consumed\n */\nexport function readNumber(buf: Buffer, offset: number): NumberReadResult {\n const firstByte = buf[offset];\n\n // Special case: 0xFF means 8 extra bytes (full 64-bit value)\n if (firstByte === 0xff) {\n return {\n value: readUInt64LE(buf, offset + 1),\n bytesRead: 9,\n };\n }\n\n // Determine number of extra bytes based on first byte value thresholds\n // This matches the 7z format specification\n let extraBytes = 0;\n let mask = 0x80;\n\n if (firstByte <= 0x7f) {\n extraBytes = 0;\n mask = 0x80;\n } else if (firstByte <= 0xbf) {\n extraBytes = 1;\n mask = 0x40;\n } else if (firstByte <= 0xdf) {\n extraBytes = 2;\n mask = 0x20;\n } else if (firstByte <= 0xef) {\n extraBytes = 3;\n mask = 0x10;\n } else if (firstByte <= 0xf7) {\n extraBytes = 4;\n mask = 0x08;\n } else if (firstByte <= 0xfb) {\n extraBytes = 5;\n mask = 0x04;\n } else if (firstByte <= 0xfd) {\n extraBytes = 6;\n mask = 0x02;\n } else {\n // 0xFE\n extraBytes = 7;\n mask = 0x01;\n }\n\n // Get high part from first byte (bits below the length indicator)\n const highPart = firstByte & (mask - 1);\n\n // Read extra bytes as LITTLE-ENDIAN\n let value = 0;\n for (let i = 0; i < extraBytes; i++) {\n value += buf[offset + 1 + i] * 256 ** i;\n }\n\n // Combine: value + (highPart << (extraBytes * 8))\n value += highPart * 256 ** extraBytes;\n\n return {\n value: value,\n bytesRead: 1 + extraBytes,\n };\n}\n\n/**\n * Read a raw 64-bit little-endian number (used in some fixed-size fields)\n * @param buf - Buffer containing the number\n * @param offset - Offset to start reading from\n * @returns The number value\n */\nexport function readRawNumber(buf: Buffer, offset: number): number {\n return readUInt64LE(buf, offset);\n}\n\n/**\n * Calculate the encoded size of a number\n * @param value - The number to encode\n * @returns Number of bytes needed to encode the value\n */\nexport function encodedSize(value: number): number {\n if (value < 0x80) return 1; // 7 bits\n if (value < 0x4000) return 2; // 14 bits\n if (value < 0x200000) return 3; // 21 bits\n if (value < 0x10000000) return 4; // 28 bits\n if (value < 0x800000000) return 5; // 35 bits\n if (value < 0x40000000000) return 6; // 42 bits\n if (value < 0x2000000000000) return 7; // 49 bits\n // 2^56 = 72057594037927936 (use calculated value to avoid precision loss)\n if (value < 72057594037927936) return 8; // 56 bits\n return 9; // 64 bits\n}\n\n/**\n * Read a boolean encoded as a single byte\n * @param buf - Buffer to read from\n * @param offset - Offset to read from\n * @returns true if byte is non-zero\n */\nexport function readBoolean(buf: Buffer, offset: number): boolean {\n return buf[offset] !== 0;\n}\n\n/**\n * Read a \"defined\" bitmask for an array of items.\n * Used when some items in a list have optional values.\n *\n * Format: If \"allDefined\" byte is 0, a bitmask follows indicating which items have values.\n * If \"allDefined\" byte is non-zero, all items are defined.\n *\n * @param buf - Buffer to read from\n * @param offset - Offset to start reading\n * @param count - Number of items\n * @returns Object with defined array and bytes consumed\n */\nexport function readDefinedVector(buf: Buffer, offset: number, count: number): { defined: boolean[]; bytesRead: number } {\n const allDefined = buf[offset] !== 0;\n let bytesRead = 1;\n const defined: boolean[] = [];\n\n if (allDefined) {\n // All items are defined\n for (let i = 0; i < count; i++) {\n defined.push(true);\n }\n } else {\n // Read bitmask\n const bitsNeeded = count;\n const bytesNeeded = Math.ceil(bitsNeeded / 8);\n\n for (let byteIdx = 0; byteIdx < bytesNeeded; byteIdx++) {\n const byte = buf[offset + 1 + byteIdx];\n for (let bit = 7; bit >= 0 && defined.length < count; bit--) {\n defined.push((byte & (1 << bit)) !== 0);\n }\n }\n bytesRead += bytesNeeded;\n }\n\n return { defined: defined, bytesRead: bytesRead };\n}\n\n/**\n * Read an array of variable-length numbers\n * @param buf - Buffer to read from\n * @param offset - Offset to start reading\n * @param count - Number of items to read\n * @returns Object with values array and bytes consumed\n */\nexport function readNumberArray(buf: Buffer, offset: number, count: number): { values: number[]; bytesRead: number } {\n const values: number[] = [];\n let totalBytesRead = 0;\n\n for (let i = 0; i < count; i++) {\n const result = readNumber(buf, offset + totalBytesRead);\n values.push(result.value);\n totalBytesRead += result.bytesRead;\n }\n\n return { values: values, bytesRead: totalBytesRead };\n}\n"],"names":["encodedSize","readBoolean","readDefinedVector","readNumber","readNumberArray","readRawNumber","buf","offset","firstByte","value","readUInt64LE","bytesRead","extraBytes","mask","highPart","i","count","allDefined","defined","push","bitsNeeded","bytesNeeded","Math","ceil","byteIdx","byte","bit","length","values","totalBytesRead","result"],"mappings":"AAAA,iDAAiD;AACjD,wEAAwE;AACxE,EAAE;AACF,6EAA6E;AAC7E,iDAAiD;AACjD,mDAAmD;AACnD,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,uDAAuD;AACvD,EAAE;AACF,4EAA4E;AAC5E,wCAAwC;;;;;;;;;;;;QAoGxBA;eAAAA;;QAmBAC;eAAAA;;QAgBAC;eAAAA;;QA/GAC;eAAAA;;QAiJAC;eAAAA;;QA9EAC;eAAAA;;;mCAzFa;AAsBtB,SAASF,WAAWG,GAAW,EAAEC,MAAc;IACpD,IAAMC,YAAYF,GAAG,CAACC,OAAO;IAE7B,6DAA6D;IAC7D,IAAIC,cAAc,MAAM;QACtB,OAAO;YACLC,OAAOC,IAAAA,iCAAY,EAACJ,KAAKC,SAAS;YAClCI,WAAW;QACb;IACF;IAEA,uEAAuE;IACvE,2CAA2C;IAC3C,IAAIC,aAAa;IACjB,IAAIC,OAAO;IAEX,IAAIL,aAAa,MAAM;QACrBI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aAAa;QACbC,OAAO;IACT,OAAO,IAAIL,aAAa,MAAM;QAC5BI,aA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GAAGA,IAAIC,OAAOD,IAAK;YAC9BG,QAAQC,IAAI,CAAC;QACf;IACF,OAAO;QACL,eAAe;QACf,IAAMC,aAAaJ;QACnB,IAAMK,cAAcC,KAAKC,IAAI,CAACH,aAAa;QAE3C,IAAK,IAAII,UAAU,GAAGA,UAAUH,aAAaG,UAAW;YACtD,IAAMC,OAAOnB,GAAG,CAACC,SAAS,IAAIiB,QAAQ;YACtC,IAAK,IAAIE,MAAM,GAAGA,OAAO,KAAKR,QAAQS,MAAM,GAAGX,OAAOU,MAAO;gBAC3DR,QAAQC,IAAI,CAAC,AAACM,CAAAA,OAAQ,KAAKC,GAAG,MAAO;YACvC;QACF;QACAf,aAAaU;IACf;IAEA,OAAO;QAAEH,SAASA;QAASP,WAAWA;IAAU;AAClD;AASO,SAASP,gBAAgBE,GAAW,EAAEC,MAAc,EAAES,KAAa;IACxE,IAAMY,SAAmB,EAAE;IAC3B,IAAIC,iBAAiB;IAErB,IAAK,IAAId,IAAI,GAAGA,IAAIC,OAAOD,IAAK;QAC9B,IAAMe,SAAS3B,WAAWG,KAAKC,SAASsB;QACxCD,OAAOT,IAAI,CAACW,OAAOrB,KAAK;QACxBoB,kBAAkBC,OAAOnB,SAAS;IACpC;IAEA,OAAO;QAAEiB,QAAQA;QAAQjB,WAAWkB;IAAe;AACrD"}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SevenZipParser - Main 7z archive parser
|
|
3
|
+
*
|
|
4
|
+
* Handles reading archive structure and providing file streams.
|
|
5
|
+
*
|
|
6
|
+
* Parser Flow:
|
|
7
|
+
* 1. Read signature header (32 bytes) to get header location
|
|
8
|
+
* 2. Read encoded header from nextHeaderOffset
|
|
9
|
+
* 3. If header is compressed, decompress it first
|
|
10
|
+
* 4. Parse streams info (folder structure, pack positions)
|
|
11
|
+
* 5. Parse files info (names, sizes, attributes)
|
|
12
|
+
* 6. Build entry list for iteration
|
|
13
|
+
*
|
|
14
|
+
* Decompression:
|
|
15
|
+
* - 7z uses "folders" as decompression units
|
|
16
|
+
* - Solid archives: multiple files share one folder (decompress once)
|
|
17
|
+
* - Non-solid: one file per folder
|
|
18
|
+
* - Supports LZMA, LZMA2, COPY, BCJ2, and other codecs
|
|
19
|
+
*/
|
|
1
20
|
import Stream from 'stream';
|
|
21
|
+
import type { ArchiveSource } from './ArchiveSource.js';
|
|
2
22
|
type Readable = Stream.Readable;
|
|
23
|
+
export { type ArchiveSource, BufferSource, FileSource } from './ArchiveSource.js';
|
|
3
24
|
export interface SevenZipEntry {
|
|
4
25
|
name: string;
|
|
5
26
|
path: string;
|
|
@@ -16,35 +37,6 @@ export interface SevenZipEntry {
|
|
|
16
37
|
_hasStream: boolean;
|
|
17
38
|
_crc?: number;
|
|
18
39
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Archive source abstraction - allows reading from file descriptor or buffer
|
|
21
|
-
*/
|
|
22
|
-
export interface ArchiveSource {
|
|
23
|
-
read(position: number, length: number): Buffer;
|
|
24
|
-
getSize(): number;
|
|
25
|
-
close(): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Buffer-based archive source
|
|
29
|
-
*/
|
|
30
|
-
export declare class BufferSource implements ArchiveSource {
|
|
31
|
-
private buffer;
|
|
32
|
-
constructor(buffer: Buffer);
|
|
33
|
-
read(position: number, length: number): Buffer;
|
|
34
|
-
getSize(): number;
|
|
35
|
-
close(): void;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* File descriptor based archive source
|
|
39
|
-
*/
|
|
40
|
-
export declare class FileSource implements ArchiveSource {
|
|
41
|
-
private fd;
|
|
42
|
-
private size;
|
|
43
|
-
constructor(fd: number, size: number);
|
|
44
|
-
read(position: number, length: number): Buffer;
|
|
45
|
-
getSize(): number;
|
|
46
|
-
close(): void;
|
|
47
|
-
}
|
|
48
40
|
/**
|
|
49
41
|
* SevenZipParser - parses 7z archives and provides entry iteration
|
|
50
42
|
*/
|
|
@@ -122,4 +114,3 @@ export declare class SevenZipParser {
|
|
|
122
114
|
*/
|
|
123
115
|
close(): void;
|
|
124
116
|
}
|
|
125
|
-
export {};
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SevenZipParser - Main 7z archive parser
|
|
3
|
+
*
|
|
4
|
+
* Handles reading archive structure and providing file streams.
|
|
5
|
+
*
|
|
6
|
+
* Parser Flow:
|
|
7
|
+
* 1. Read signature header (32 bytes) to get header location
|
|
8
|
+
* 2. Read encoded header from nextHeaderOffset
|
|
9
|
+
* 3. If header is compressed, decompress it first
|
|
10
|
+
* 4. Parse streams info (folder structure, pack positions)
|
|
11
|
+
* 5. Parse files info (names, sizes, attributes)
|
|
12
|
+
* 6. Build entry list for iteration
|
|
13
|
+
*
|
|
14
|
+
* Decompression:
|
|
15
|
+
* - 7z uses "folders" as decompression units
|
|
16
|
+
* - Solid archives: multiple files share one folder (decompress once)
|
|
17
|
+
* - Non-solid: one file per folder
|
|
18
|
+
* - Supports LZMA, LZMA2, COPY, BCJ2, and other codecs
|
|
19
|
+
*/
|
|
1
20
|
import Stream from 'stream';
|
|
21
|
+
import type { ArchiveSource } from './ArchiveSource.js';
|
|
2
22
|
type Readable = Stream.Readable;
|
|
23
|
+
export { type ArchiveSource, BufferSource, FileSource } from './ArchiveSource.js';
|
|
3
24
|
export interface SevenZipEntry {
|
|
4
25
|
name: string;
|
|
5
26
|
path: string;
|
|
@@ -16,35 +37,6 @@ export interface SevenZipEntry {
|
|
|
16
37
|
_hasStream: boolean;
|
|
17
38
|
_crc?: number;
|
|
18
39
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Archive source abstraction - allows reading from file descriptor or buffer
|
|
21
|
-
*/
|
|
22
|
-
export interface ArchiveSource {
|
|
23
|
-
read(position: number, length: number): Buffer;
|
|
24
|
-
getSize(): number;
|
|
25
|
-
close(): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Buffer-based archive source
|
|
29
|
-
*/
|
|
30
|
-
export declare class BufferSource implements ArchiveSource {
|
|
31
|
-
private buffer;
|
|
32
|
-
constructor(buffer: Buffer);
|
|
33
|
-
read(position: number, length: number): Buffer;
|
|
34
|
-
getSize(): number;
|
|
35
|
-
close(): void;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* File descriptor based archive source
|
|
39
|
-
*/
|
|
40
|
-
export declare class FileSource implements ArchiveSource {
|
|
41
|
-
private fd;
|
|
42
|
-
private size;
|
|
43
|
-
constructor(fd: number, size: number);
|
|
44
|
-
read(position: number, length: number): Buffer;
|
|
45
|
-
getSize(): number;
|
|
46
|
-
close(): void;
|
|
47
|
-
}
|
|
48
40
|
/**
|
|
49
41
|
* SevenZipParser - parses 7z archives and provides entry iteration
|
|
50
42
|
*/
|
|
@@ -122,4 +114,3 @@ export declare class SevenZipParser {
|
|
|
122
114
|
*/
|
|
123
115
|
close(): void;
|
|
124
116
|
}
|
|
125
|
-
export {};
|