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
|
@@ -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":["FileEntry","waitForAccess","fs","oo","SevenZipFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","entry","parser","Error","getEntryStreamAsync","stream","res","pipe","createWriteStream","writeErr","destroy","attributes","retain"],"mappings":"AAAA,SAA8BA,SAAS,EAAmCC,aAAa,QAAQ,wBAAwB;AACvH,OAAOC,QAAQ,KAAK;AACpB,OAAOC,QAAQ,SAAS;AAIT,IAAA,AAAMC,oBAAN,MAAMA,0BAA0BJ;IAa7CK,OAAOC,IAAY,EAAEC,OAAyC,EAAEC,QAAyB,EAAgC;QACvH,IAAI,OAAOD,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QAEA,IAAI,OAAOC,aAAa,YAAY;YAClCD,UAAUA,WAAW,CAAC;YACtB,OAAOP,UAAUS,SAAS,CAACJ,MAAM,CAACK,IAAI,CAAC,IAAI,EAAEJ,MAAMC,SAAS,CAACI;gBAC3DH,SAASG;gBACT,IAAI,IAAI,CAACC,IAAI,EAAE;oBACb,IAAI,CAACA,IAAI,CAACC,OAAO;oBACjB,IAAI,CAACD,IAAI,GAAG;gBACd;YACF;QACF;QACA,OAAO,I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aseIterator 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,11 +1,11 @@
|
|
|
1
|
-
import BaseIterator from 'extract-base-iterator';
|
|
1
|
+
import BaseIterator, { Lock } from 'extract-base-iterator';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import { rmSync } from 'fs-remove-compat';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import Queue from 'queue-cb';
|
|
5
6
|
import shortHash from 'short-hash';
|
|
6
7
|
import tempSuffix from 'temp-suffix';
|
|
7
8
|
import { tmpdir } from './compat.js';
|
|
8
|
-
import Lock from './lib/Lock.js';
|
|
9
9
|
import streamToSource from './lib/streamToSource.js';
|
|
10
10
|
import nextEntry from './nextEntry.js';
|
|
11
11
|
import { setPassword } from './sevenz/codecs/index.js';
|
|
@@ -42,7 +42,7 @@ let SevenZipIterator = class SevenZipIterator extends BaseIterator {
|
|
|
42
42
|
constructor(source, options = {}){
|
|
43
43
|
super(options);
|
|
44
44
|
this.lock = new Lock();
|
|
45
|
-
this.lock.
|
|
45
|
+
this.lock.onDestroy = (err)=>BaseIterator.prototype.end.call(this, err);
|
|
46
46
|
const queue = new Queue(1);
|
|
47
47
|
let cancelled = false;
|
|
48
48
|
let archiveSource = null;
|
|
@@ -63,15 +63,22 @@ let SevenZipIterator = class SevenZipIterator extends BaseIterator {
|
|
|
63
63
|
if (this.done || cancelled) return;
|
|
64
64
|
if (err) return cb(err);
|
|
65
65
|
archiveSource = new FileSource(fd, stats.size);
|
|
66
|
-
|
|
66
|
+
// Register cleanup for file descriptor
|
|
67
|
+
this.lock.registerCleanup(()=>{
|
|
68
|
+
fs.closeSync(fd);
|
|
69
|
+
});
|
|
67
70
|
cb();
|
|
68
71
|
});
|
|
69
72
|
});
|
|
70
73
|
});
|
|
71
74
|
} else {
|
|
72
75
|
// Stream input - use hybrid memory/temp-file approach
|
|
73
|
-
//
|
|
74
|
-
|
|
76
|
+
// Register cleanup for source stream
|
|
77
|
+
const stream = source;
|
|
78
|
+
this.lock.registerCleanup(()=>{
|
|
79
|
+
const s = stream;
|
|
80
|
+
if (typeof s.destroy === 'function') s.destroy();
|
|
81
|
+
});
|
|
75
82
|
const tempPath = path.join(tmpdir(), '7z-iterator', shortHash(process.cwd()), tempSuffix('tmp.7z'));
|
|
76
83
|
queue.defer((cb)=>{
|
|
77
84
|
streamToSource(source, {
|
|
@@ -83,10 +90,21 @@ let SevenZipIterator = class SevenZipIterator extends BaseIterator {
|
|
|
83
90
|
if (!result) return cb(new Error('No result from streamToSource'));
|
|
84
91
|
archiveSource = result.source;
|
|
85
92
|
if (result.fd !== undefined) {
|
|
86
|
-
|
|
93
|
+
const fd = result.fd;
|
|
94
|
+
// Register cleanup for file descriptor
|
|
95
|
+
this.lock.registerCleanup(()=>{
|
|
96
|
+
fs.closeSync(fd);
|
|
97
|
+
});
|
|
87
98
|
}
|
|
88
99
|
if (result.tempPath) {
|
|
89
|
-
|
|
100
|
+
const tp = result.tempPath;
|
|
101
|
+
// Register cleanup for temp file
|
|
102
|
+
this.lock.registerCleanup(()=>{
|
|
103
|
+
try {
|
|
104
|
+
rmSync(tp);
|
|
105
|
+
} catch (_e) {
|
|
106
|
+
/* ignore */ }
|
|
107
|
+
});
|
|
90
108
|
}
|
|
91
109
|
cb();
|
|
92
110
|
});
|
|
@@ -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":["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","source","options","onDestroy","prototype","call","queue","cancelled","archiveSource","setup","undefined","processing","push","password","defer","cb","stat","statErr","stats","done","open","fd","size","registerCleanup","closeSync","stream","s","destroy","tempPath","join","process","cwd","memoryThreshold","result","Error","tp","_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;AAIhH;;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,YAAYA,MAAsB,CAAE;aAF5BJ,QAAQ;QAGd,IAAI,CAACI,MAAM,GAAGA;QACd,IAAI,CAACH,OAAO,GAAGG,OAAOC,UAAU;IAClC;AAYF;AA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C,SAAS,IAAIP,eAAesB;gBAClCf,OAAO4C,KAAK;gBACZ,IAAI,CAACrC,QAAQ,GAAG,IAAIb,cAAcM;gBAClCsB;YACF,EAAE,OAAOuB,UAAU;gBACjBvB,GAAGuB;YACL;QACF;QAEA,mBAAmB;QACnBhC,MAAMiC,KAAK,CAAC,CAAC1C;YACX,IAAI,CAACc,UAAU,CAAC6B,MAAM,CAAC/B;YACvB,IAAI,IAAI,CAACU,IAAI,IAAIZ,WAAW;YAC5BV,MAAM,IAAI,CAACD,GAAG,CAACC,OAAO,IAAI,CAACe,IAAI,CAAC7B;QAClC;IACF;AAYF;AAxHA,SAAqBY,8BAwHpB"}
|
|
@@ -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,54 @@
|
|
|
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
|
+
*/ import { allocBuffer } from 'extract-base-iterator';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
/**
|
|
9
|
+
* Buffer-based archive source
|
|
10
|
+
*
|
|
11
|
+
* Used when the entire archive is already in memory.
|
|
12
|
+
*/ export class BufferSource {
|
|
13
|
+
read(position, length) {
|
|
14
|
+
return this.buffer.slice(position, position + length);
|
|
15
|
+
}
|
|
16
|
+
getSize() {
|
|
17
|
+
return this.buffer.length;
|
|
18
|
+
}
|
|
19
|
+
close() {
|
|
20
|
+
// Nothing to close for buffer
|
|
21
|
+
}
|
|
22
|
+
constructor(buffer){
|
|
23
|
+
this.buffer = buffer;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* File descriptor based archive source
|
|
28
|
+
*
|
|
29
|
+
* Used for reading directly from a file on disk.
|
|
30
|
+
* More memory efficient for large archives.
|
|
31
|
+
*/ export class FileSource {
|
|
32
|
+
read(position, length) {
|
|
33
|
+
const buf = allocBuffer(length);
|
|
34
|
+
const bytesRead = fs.readSync(this.fd, buf, 0, length, position);
|
|
35
|
+
if (bytesRead < length) {
|
|
36
|
+
return buf.slice(0, bytesRead);
|
|
37
|
+
}
|
|
38
|
+
return buf;
|
|
39
|
+
}
|
|
40
|
+
getSize() {
|
|
41
|
+
return this.size;
|
|
42
|
+
}
|
|
43
|
+
close() {
|
|
44
|
+
try {
|
|
45
|
+
fs.closeSync(this.fd);
|
|
46
|
+
} catch (_e) {
|
|
47
|
+
// Ignore close errors
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
constructor(fd, size){
|
|
51
|
+
this.fd = fd;
|
|
52
|
+
this.size = size;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -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":["allocBuffer","fs","BufferSource","read","position","length","buffer","slice","getSize","close","FileSource","buf","bytesRead","readSync","fd","size","closeSync","_e"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,WAAW,QAAQ,wBAAwB;AACpD,OAAOC,QAAQ,KAAK;AAWpB;;;;CAIC,GACD,OAAO,MAAMC;IAOXC,KAAKC,QAAgB,EAAEC,MAAc,EAAU;QAC7C,OAAO,IAAI,CAACC,MAAM,CAACC,KAAK,CAACH,UAAUA,WAAWC;IAChD;IAEAG,UAAkB;QAChB,OAAO,IAAI,CAACF,MAAM,CAACD,MAAM;IAC3B;IAEAI,QAAc;IACZ,8BAA8B;IAChC;IAdA,YAAYH,MAAc,CAAE;QAC1B,IAAI,CAACA,MAAM,GAAGA;IAChB;AAaF;AAEA;;;;;CAKC,GACD,OAAO,MAAMI;IASXP,KAAKC,QAAgB,EAAEC,MAAc,EAAU;QAC7C,MAAMM,MAAMX,YAAYK;QACxB,MAAMO,YAAYX,GAAGY,QAAQ,CAAC,IAAI,CAACC,EAAE,EAAEH,KAAK,GAAGN,QAAQD;QACvD,IAAIQ,YAAYP,QAAQ;YACtB,OAAOM,IAAIJ,KAAK,CAAC,GAAGK;QACtB;QACA,OAAOD;IACT;IAEAH,UAAkB;QAChB,OAAO,IAAI,CAACO,IAAI;IAClB;IAEAN,QAAc;QACZ,IAAI;YACFR,GAAGe,SAAS,CAAC,IAAI,CAACF,EAAE;QACtB,EAAE,OAAOG,IAAI;QACX,sBAAsB;QACxB;IACF;IAxBA,YAAYH,EAAU,EAAEC,IAAY,CAAE;QACpC,IAAI,CAACD,EAAE,GAAGA;QACV,IAAI,CAACC,IAAI,GAAGA;IACd;AAsBF"}
|
|
@@ -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,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
*/ import { crc32 } from 'extract-base-iterator';
|
|
5
20
|
import oo from 'on-one';
|
|
6
21
|
import Stream from 'stream';
|
|
7
22
|
import { decodeBcj2Multi, getCodec, getCodecName, isBcj2Codec, isCodecSupported } from './codecs/index.js';
|
|
@@ -16,48 +31,8 @@ if (major > 0) {
|
|
|
16
31
|
import { createCodedError, ErrorCode, FileAttribute, PropertyId, SIGNATURE_HEADER_SIZE } from './constants.js';
|
|
17
32
|
import { parseEncodedHeader, parseHeaderContent, parseSignatureHeader } from './headers.js';
|
|
18
33
|
import { readNumber } from './NumberCodec.js';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*/ export class BufferSource {
|
|
22
|
-
read(position, length) {
|
|
23
|
-
return this.buffer.slice(position, position + length);
|
|
24
|
-
}
|
|
25
|
-
getSize() {
|
|
26
|
-
return this.buffer.length;
|
|
27
|
-
}
|
|
28
|
-
close() {
|
|
29
|
-
// Nothing to close for buffer
|
|
30
|
-
}
|
|
31
|
-
constructor(buffer){
|
|
32
|
-
this.buffer = buffer;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* File descriptor based archive source
|
|
37
|
-
*/ export class FileSource {
|
|
38
|
-
read(position, length) {
|
|
39
|
-
const buf = allocBuffer(length);
|
|
40
|
-
const bytesRead = fs.readSync(this.fd, buf, 0, length, position);
|
|
41
|
-
if (bytesRead < length) {
|
|
42
|
-
return buf.slice(0, bytesRead);
|
|
43
|
-
}
|
|
44
|
-
return buf;
|
|
45
|
-
}
|
|
46
|
-
getSize() {
|
|
47
|
-
return this.size;
|
|
48
|
-
}
|
|
49
|
-
close() {
|
|
50
|
-
try {
|
|
51
|
-
fs.closeSync(this.fd);
|
|
52
|
-
} catch (_e) {
|
|
53
|
-
// Ignore close errors
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
constructor(fd, size){
|
|
57
|
-
this.fd = fd;
|
|
58
|
-
this.size = size;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
34
|
+
// Re-export for backwards compatibility
|
|
35
|
+
export { BufferSource, FileSource } from './ArchiveSource.js';
|
|
61
36
|
/**
|
|
62
37
|
* SevenZipParser - parses 7z archives and provides entry iteration
|
|
63
38
|
*/ export class SevenZipParser {
|