7z-iterator 1.1.2 → 1.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.d.cts +12 -4
- package/dist/cjs/FileEntry.d.ts +12 -4
- package/dist/cjs/FileEntry.js +52 -24
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/SevenZipIterator.d.cts +25 -2
- package/dist/cjs/SevenZipIterator.d.ts +25 -2
- package/dist/cjs/SevenZipIterator.js +68 -21
- package/dist/cjs/SevenZipIterator.js.map +1 -1
- package/dist/cjs/index.d.cts +0 -2
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/index.js +3 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/streamToSource.d.cts +8 -11
- package/dist/cjs/lib/streamToSource.d.ts +8 -11
- package/dist/cjs/lib/streamToSource.js +21 -67
- package/dist/cjs/lib/streamToSource.js.map +1 -1
- package/dist/cjs/lzma/Lzma2ChunkParser.d.cts +73 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.d.ts +73 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.js +148 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.js.map +1 -0
- package/dist/cjs/lzma/index.d.cts +13 -0
- package/dist/cjs/lzma/index.d.ts +13 -0
- package/dist/cjs/lzma/index.js +63 -0
- package/dist/cjs/lzma/index.js.map +1 -0
- package/dist/cjs/lzma/stream/transforms.d.cts +38 -0
- package/dist/cjs/lzma/stream/transforms.d.ts +38 -0
- package/dist/cjs/lzma/stream/transforms.js +149 -0
- package/dist/cjs/lzma/stream/transforms.js.map +1 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +30 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +30 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.js +135 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +82 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +82 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.js +440 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.js.map +1 -0
- package/dist/cjs/lzma/sync/RangeDecoder.d.cts +69 -0
- package/dist/cjs/lzma/sync/RangeDecoder.d.ts +69 -0
- package/dist/cjs/lzma/sync/RangeDecoder.js +162 -0
- package/dist/cjs/lzma/sync/RangeDecoder.js.map +1 -0
- package/dist/cjs/lzma/types.d.cts +110 -0
- package/dist/cjs/lzma/types.d.ts +110 -0
- package/dist/cjs/lzma/types.js +264 -0
- package/dist/cjs/lzma/types.js.map +1 -0
- package/dist/cjs/nextEntry.js +24 -26
- package/dist/cjs/nextEntry.js.map +1 -1
- package/dist/cjs/sevenz/ArchiveSource.d.cts +16 -0
- package/dist/cjs/sevenz/ArchiveSource.d.ts +16 -0
- package/dist/cjs/sevenz/ArchiveSource.js +69 -0
- package/dist/cjs/sevenz/ArchiveSource.js.map +1 -1
- package/dist/cjs/sevenz/FolderStreamSplitter.d.cts +101 -0
- package/dist/cjs/sevenz/FolderStreamSplitter.d.ts +101 -0
- package/dist/cjs/sevenz/FolderStreamSplitter.js +229 -0
- package/dist/cjs/sevenz/FolderStreamSplitter.js.map +1 -0
- package/dist/cjs/sevenz/SevenZipParser.d.cts +71 -10
- package/dist/cjs/sevenz/SevenZipParser.d.ts +71 -10
- package/dist/cjs/sevenz/SevenZipParser.js +574 -203
- package/dist/cjs/sevenz/SevenZipParser.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BZip2.js +2 -1
- package/dist/cjs/sevenz/codecs/BZip2.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Bcj.d.cts +5 -4
- package/dist/cjs/sevenz/codecs/Bcj.d.ts +5 -4
- package/dist/cjs/sevenz/codecs/Bcj.js +102 -8
- package/dist/cjs/sevenz/codecs/Bcj.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjArm.d.cts +5 -4
- package/dist/cjs/sevenz/codecs/BcjArm.d.ts +5 -4
- package/dist/cjs/sevenz/codecs/BcjArm.js +51 -9
- package/dist/cjs/sevenz/codecs/BcjArm.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Copy.d.cts +2 -4
- package/dist/cjs/sevenz/codecs/Copy.d.ts +2 -4
- package/dist/cjs/sevenz/codecs/Copy.js +2 -15
- package/dist/cjs/sevenz/codecs/Copy.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Deflate.d.cts +6 -4
- package/dist/cjs/sevenz/codecs/Deflate.d.ts +6 -4
- package/dist/cjs/sevenz/codecs/Deflate.js +4 -9
- package/dist/cjs/sevenz/codecs/Deflate.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Delta.d.cts +5 -4
- package/dist/cjs/sevenz/codecs/Delta.d.ts +5 -4
- package/dist/cjs/sevenz/codecs/Delta.js +29 -10
- package/dist/cjs/sevenz/codecs/Delta.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Lzma.d.cts +5 -2
- package/dist/cjs/sevenz/codecs/Lzma.d.ts +5 -2
- package/dist/cjs/sevenz/codecs/Lzma.js +13 -28
- package/dist/cjs/sevenz/codecs/Lzma.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Lzma2.d.cts +9 -3
- package/dist/cjs/sevenz/codecs/Lzma2.d.ts +9 -3
- package/dist/cjs/sevenz/codecs/Lzma2.js +17 -198
- package/dist/cjs/sevenz/codecs/Lzma2.js.map +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.d.cts +2 -2
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.d.ts +2 -2
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.js +2 -15
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/cjs/types.d.cts +2 -16
- package/dist/cjs/types.d.ts +2 -16
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/FileEntry.d.ts +12 -4
- package/dist/esm/FileEntry.js +52 -26
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/SevenZipIterator.d.ts +25 -2
- package/dist/esm/SevenZipIterator.js +69 -22
- package/dist/esm/SevenZipIterator.js.map +1 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/streamToSource.d.ts +8 -11
- package/dist/esm/lib/streamToSource.js +22 -68
- package/dist/esm/lib/streamToSource.js.map +1 -1
- package/dist/esm/lzma/Lzma2ChunkParser.d.ts +73 -0
- package/dist/esm/lzma/Lzma2ChunkParser.js +137 -0
- package/dist/esm/lzma/Lzma2ChunkParser.js.map +1 -0
- package/dist/esm/lzma/index.d.ts +13 -0
- package/dist/esm/lzma/index.js +15 -0
- package/dist/esm/lzma/index.js.map +1 -0
- package/dist/esm/lzma/stream/transforms.d.ts +38 -0
- package/dist/esm/lzma/stream/transforms.js +150 -0
- package/dist/esm/lzma/stream/transforms.js.map +1 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +30 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.js +115 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -0
- package/dist/esm/lzma/sync/LzmaDecoder.d.ts +82 -0
- package/dist/esm/lzma/sync/LzmaDecoder.js +403 -0
- package/dist/esm/lzma/sync/LzmaDecoder.js.map +1 -0
- package/dist/esm/lzma/sync/RangeDecoder.d.ts +69 -0
- package/dist/esm/lzma/sync/RangeDecoder.js +132 -0
- package/dist/esm/lzma/sync/RangeDecoder.js.map +1 -0
- package/dist/esm/lzma/types.d.ts +110 -0
- package/dist/esm/lzma/types.js +154 -0
- package/dist/esm/lzma/types.js.map +1 -0
- package/dist/esm/nextEntry.js +24 -26
- package/dist/esm/nextEntry.js.map +1 -1
- package/dist/esm/sevenz/ArchiveSource.d.ts +16 -0
- package/dist/esm/sevenz/ArchiveSource.js +70 -1
- package/dist/esm/sevenz/ArchiveSource.js.map +1 -1
- package/dist/esm/sevenz/FolderStreamSplitter.d.ts +101 -0
- package/dist/esm/sevenz/FolderStreamSplitter.js +207 -0
- package/dist/esm/sevenz/FolderStreamSplitter.js.map +1 -0
- package/dist/esm/sevenz/SevenZipParser.d.ts +71 -10
- package/dist/esm/sevenz/SevenZipParser.js +414 -198
- package/dist/esm/sevenz/SevenZipParser.js.map +1 -1
- package/dist/esm/sevenz/codecs/BZip2.js +2 -1
- package/dist/esm/sevenz/codecs/BZip2.js.map +1 -1
- package/dist/esm/sevenz/codecs/Bcj.d.ts +5 -4
- package/dist/esm/sevenz/codecs/Bcj.js +106 -6
- package/dist/esm/sevenz/codecs/Bcj.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjArm.d.ts +5 -4
- package/dist/esm/sevenz/codecs/BcjArm.js +55 -7
- package/dist/esm/sevenz/codecs/BcjArm.js.map +1 -1
- package/dist/esm/sevenz/codecs/Copy.d.ts +2 -4
- package/dist/esm/sevenz/codecs/Copy.js +1 -9
- package/dist/esm/sevenz/codecs/Copy.js.map +1 -1
- package/dist/esm/sevenz/codecs/Deflate.d.ts +6 -4
- package/dist/esm/sevenz/codecs/Deflate.js +9 -7
- package/dist/esm/sevenz/codecs/Deflate.js.map +1 -1
- package/dist/esm/sevenz/codecs/Delta.d.ts +5 -4
- package/dist/esm/sevenz/codecs/Delta.js +33 -8
- package/dist/esm/sevenz/codecs/Delta.js.map +1 -1
- package/dist/esm/sevenz/codecs/Lzma.d.ts +5 -2
- package/dist/esm/sevenz/codecs/Lzma.js +17 -24
- package/dist/esm/sevenz/codecs/Lzma.js.map +1 -1
- package/dist/esm/sevenz/codecs/Lzma2.d.ts +9 -3
- package/dist/esm/sevenz/codecs/Lzma2.js +15 -196
- package/dist/esm/sevenz/codecs/Lzma2.js.map +1 -1
- package/dist/esm/sevenz/codecs/createBufferingDecoder.d.ts +2 -2
- package/dist/esm/sevenz/codecs/createBufferingDecoder.js +1 -9
- package/dist/esm/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/esm/types.d.ts +2 -16
- package/dist/esm/types.js.map +1 -1
- package/package.json +3 -3
- package/assets/lzma-purejs/LICENSE +0 -11
- package/assets/lzma-purejs/index.js +0 -19
- package/assets/lzma-purejs/lib/LZ/OutWindow.js +0 -78
- package/assets/lzma-purejs/lib/LZ.js +0 -6
- package/assets/lzma-purejs/lib/LZMA/Base.js +0 -48
- package/assets/lzma-purejs/lib/LZMA/Decoder.js +0 -328
- package/assets/lzma-purejs/lib/LZMA.js +0 -6
- package/assets/lzma-purejs/lib/RangeCoder/BitTreeDecoder.js +0 -41
- package/assets/lzma-purejs/lib/RangeCoder/Decoder.js +0 -58
- package/assets/lzma-purejs/lib/RangeCoder/Encoder.js +0 -106
- package/assets/lzma-purejs/lib/RangeCoder.js +0 -10
- package/assets/lzma-purejs/lib/Stream.js +0 -41
- package/assets/lzma-purejs/lib/Util.js +0 -114
- package/assets/lzma-purejs/lib/makeBuffer.js +0 -25
- package/assets/lzma-purejs/package-lock.json +0 -13
- package/assets/lzma-purejs/package.json +0 -8
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Stream to source conversion: writes stream to temp file for random access
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, /**
|
|
7
|
-
* Convert a stream to
|
|
7
|
+
* Convert a stream to a FileSource by writing to temp file
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* 2. If threshold exceeded, write all buffered data to temp file and continue streaming
|
|
12
|
-
* 3. When done, return BufferSource for memory buffer or FileSource for temp file
|
|
9
|
+
* 7z format requires random access for header parsing, so temp file is necessary for streams.
|
|
10
|
+
* Writes directly to temp file for predictable O(1) memory usage during stream consumption.
|
|
13
11
|
*/ "default", {
|
|
14
12
|
enumerable: true,
|
|
15
13
|
get: function() {
|
|
@@ -28,79 +26,35 @@ function _interop_require_default(obj) {
|
|
|
28
26
|
default: obj
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
|
-
// Default memory threshold: 100 MB
|
|
32
|
-
var DEFAULT_MEMORY_THRESHOLD = 100 * 1024 * 1024;
|
|
33
29
|
function streamToSource(stream, options, callback) {
|
|
34
|
-
var threshold = options.memoryThreshold !== undefined ? options.memoryThreshold : DEFAULT_MEMORY_THRESHOLD;
|
|
35
30
|
var tempPath = options.tempPath;
|
|
36
|
-
var chunks = [];
|
|
37
|
-
var totalSize = 0;
|
|
38
|
-
var writeStream = null;
|
|
39
|
-
var useTempFile = false;
|
|
40
31
|
var end = (0, _calloncefn.default)(callback);
|
|
32
|
+
_mkdirpclassic.default.sync(_path.default.dirname(tempPath));
|
|
33
|
+
var writeStream = _fs.default.createWriteStream(tempPath);
|
|
41
34
|
function onData(chunk) {
|
|
42
|
-
// Convert string chunks to Buffer
|
|
43
35
|
var buf = typeof chunk === 'string' ? (0, _extractbaseiterator.bufferFrom)(chunk) : chunk;
|
|
44
|
-
|
|
45
|
-
if (!useTempFile && totalSize <= threshold) {
|
|
46
|
-
// Still under threshold - buffer in memory
|
|
47
|
-
chunks.push(buf);
|
|
48
|
-
} else if (!useTempFile) {
|
|
49
|
-
// Just exceeded threshold - switch to temp file
|
|
50
|
-
useTempFile = true;
|
|
51
|
-
if (!tempPath) {
|
|
52
|
-
end(new Error('memoryThreshold exceeded but no tempPath provided'));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
_mkdirpclassic.default.sync(_path.default.dirname(tempPath));
|
|
56
|
-
writeStream = _fs.default.createWriteStream(tempPath);
|
|
57
|
-
// Write all buffered chunks to temp file
|
|
58
|
-
for(var i = 0; i < chunks.length; i++){
|
|
59
|
-
writeStream.write(chunks[i]);
|
|
60
|
-
}
|
|
61
|
-
chunks = []; // Allow GC
|
|
62
|
-
// Write current chunk
|
|
63
|
-
writeStream.write(buf);
|
|
64
|
-
} else {
|
|
65
|
-
// Already using temp file - write directly
|
|
66
|
-
if (writeStream) {
|
|
67
|
-
writeStream.write(buf);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
36
|
+
writeStream.write(buf);
|
|
70
37
|
}
|
|
71
38
|
function onEnd() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
source: new _SevenZipParserts.FileSource(fd, stats.size),
|
|
85
|
-
fd: fd,
|
|
86
|
-
tempPath: filePath
|
|
87
|
-
});
|
|
39
|
+
writeStream.end(function() {
|
|
40
|
+
_fs.default.open(tempPath, 'r', function(err, fd) {
|
|
41
|
+
if (err) return end(err);
|
|
42
|
+
_fs.default.stat(tempPath, function(statErr, stats) {
|
|
43
|
+
if (statErr) {
|
|
44
|
+
_fs.default.closeSync(fd);
|
|
45
|
+
return end(statErr);
|
|
46
|
+
}
|
|
47
|
+
end(null, {
|
|
48
|
+
source: new _SevenZipParserts.FileSource(fd, stats.size),
|
|
49
|
+
fd: fd,
|
|
50
|
+
tempPath: tempPath
|
|
88
51
|
});
|
|
89
52
|
});
|
|
90
53
|
});
|
|
91
|
-
}
|
|
92
|
-
// Use memory buffer
|
|
93
|
-
var fullBuffer = Buffer.concat(chunks);
|
|
94
|
-
end(null, {
|
|
95
|
-
source: new _SevenZipParserts.BufferSource(fullBuffer)
|
|
96
|
-
});
|
|
97
|
-
}
|
|
54
|
+
});
|
|
98
55
|
}
|
|
99
56
|
function onError(err) {
|
|
100
|
-
|
|
101
|
-
if (writeStream) {
|
|
102
|
-
writeStream.end();
|
|
103
|
-
}
|
|
57
|
+
writeStream.end();
|
|
104
58
|
end(err);
|
|
105
59
|
}
|
|
106
60
|
stream.on('data', onData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lib/streamToSource.ts"],"sourcesContent":["//
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/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;yDACZ;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,WAAE,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,WAAE,CAACQ,IAAI,CAAChB,UAAU,KAAK,SAACiB,KAAKC;gBAC3B,IAAID,KAAK,OAAOhB,IAAIgB;gBACpBT,WAAE,CAACW,IAAI,CAACnB,UAAU,SAACoB,SAASC;oBAC1B,IAAID,SAAS;wBACXZ,WAAE,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"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA2 Chunk Parser
|
|
3
|
+
*
|
|
4
|
+
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
+
* Used by both synchronous and streaming decoders.
|
|
6
|
+
*
|
|
7
|
+
* LZMA2 control byte ranges:
|
|
8
|
+
* 0x00 = End of stream
|
|
9
|
+
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
+
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
+
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
+
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
+
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
+
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* LZMA properties extracted from chunk header
|
|
18
|
+
*/
|
|
19
|
+
export interface LzmaChunkProps {
|
|
20
|
+
lc: number;
|
|
21
|
+
lp: number;
|
|
22
|
+
pb: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parsed LZMA2 chunk information
|
|
26
|
+
*/
|
|
27
|
+
export interface Lzma2Chunk {
|
|
28
|
+
/** Chunk type */
|
|
29
|
+
type: 'end' | 'uncompressed' | 'lzma';
|
|
30
|
+
/** Total bytes consumed by header (including control byte) */
|
|
31
|
+
headerSize: number;
|
|
32
|
+
/** Whether to reset dictionary */
|
|
33
|
+
dictReset: boolean;
|
|
34
|
+
/** Whether to reset state/probabilities */
|
|
35
|
+
stateReset: boolean;
|
|
36
|
+
/** New LZMA properties (only for control >= 0xC0) */
|
|
37
|
+
newProps: LzmaChunkProps | null;
|
|
38
|
+
/** Uncompressed data size */
|
|
39
|
+
uncompSize: number;
|
|
40
|
+
/** Compressed data size (0 for uncompressed chunks) */
|
|
41
|
+
compSize: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of parsing attempt
|
|
45
|
+
*/
|
|
46
|
+
export type ParseResult = {
|
|
47
|
+
success: true;
|
|
48
|
+
chunk: Lzma2Chunk;
|
|
49
|
+
} | {
|
|
50
|
+
success: false;
|
|
51
|
+
needBytes: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Parse an LZMA2 chunk header
|
|
55
|
+
*
|
|
56
|
+
* @param input - Input buffer
|
|
57
|
+
* @param offset - Offset to start parsing
|
|
58
|
+
* @returns Parsed chunk info or number of bytes needed
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult;
|
|
61
|
+
/** Result type for hasCompleteChunk with totalSize included on success */
|
|
62
|
+
export type CompleteChunkResult = {
|
|
63
|
+
success: true;
|
|
64
|
+
chunk: Lzma2Chunk;
|
|
65
|
+
totalSize: number;
|
|
66
|
+
} | {
|
|
67
|
+
success: false;
|
|
68
|
+
needBytes: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Check if we have enough data for the complete chunk (header + data)
|
|
72
|
+
*/
|
|
73
|
+
export declare function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA2 Chunk Parser
|
|
3
|
+
*
|
|
4
|
+
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
+
* Used by both synchronous and streaming decoders.
|
|
6
|
+
*
|
|
7
|
+
* LZMA2 control byte ranges:
|
|
8
|
+
* 0x00 = End of stream
|
|
9
|
+
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
+
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
+
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
+
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
+
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
+
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* LZMA properties extracted from chunk header
|
|
18
|
+
*/
|
|
19
|
+
export interface LzmaChunkProps {
|
|
20
|
+
lc: number;
|
|
21
|
+
lp: number;
|
|
22
|
+
pb: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parsed LZMA2 chunk information
|
|
26
|
+
*/
|
|
27
|
+
export interface Lzma2Chunk {
|
|
28
|
+
/** Chunk type */
|
|
29
|
+
type: 'end' | 'uncompressed' | 'lzma';
|
|
30
|
+
/** Total bytes consumed by header (including control byte) */
|
|
31
|
+
headerSize: number;
|
|
32
|
+
/** Whether to reset dictionary */
|
|
33
|
+
dictReset: boolean;
|
|
34
|
+
/** Whether to reset state/probabilities */
|
|
35
|
+
stateReset: boolean;
|
|
36
|
+
/** New LZMA properties (only for control >= 0xC0) */
|
|
37
|
+
newProps: LzmaChunkProps | null;
|
|
38
|
+
/** Uncompressed data size */
|
|
39
|
+
uncompSize: number;
|
|
40
|
+
/** Compressed data size (0 for uncompressed chunks) */
|
|
41
|
+
compSize: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of parsing attempt
|
|
45
|
+
*/
|
|
46
|
+
export type ParseResult = {
|
|
47
|
+
success: true;
|
|
48
|
+
chunk: Lzma2Chunk;
|
|
49
|
+
} | {
|
|
50
|
+
success: false;
|
|
51
|
+
needBytes: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Parse an LZMA2 chunk header
|
|
55
|
+
*
|
|
56
|
+
* @param input - Input buffer
|
|
57
|
+
* @param offset - Offset to start parsing
|
|
58
|
+
* @returns Parsed chunk info or number of bytes needed
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult;
|
|
61
|
+
/** Result type for hasCompleteChunk with totalSize included on success */
|
|
62
|
+
export type CompleteChunkResult = {
|
|
63
|
+
success: true;
|
|
64
|
+
chunk: Lzma2Chunk;
|
|
65
|
+
totalSize: number;
|
|
66
|
+
} | {
|
|
67
|
+
success: false;
|
|
68
|
+
needBytes: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Check if we have enough data for the complete chunk (header + data)
|
|
72
|
+
*/
|
|
73
|
+
export declare function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA2 Chunk Parser
|
|
3
|
+
*
|
|
4
|
+
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
+
* Used by both synchronous and streaming decoders.
|
|
6
|
+
*
|
|
7
|
+
* LZMA2 control byte ranges:
|
|
8
|
+
* 0x00 = End of stream
|
|
9
|
+
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
+
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
+
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
+
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
+
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
+
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
+
*/ /**
|
|
16
|
+
* LZMA properties extracted from chunk header
|
|
17
|
+
*/ "use strict";
|
|
18
|
+
Object.defineProperty(exports, "__esModule", {
|
|
19
|
+
value: true
|
|
20
|
+
});
|
|
21
|
+
function _export(target, all) {
|
|
22
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
_export(exports, {
|
|
28
|
+
get hasCompleteChunk () {
|
|
29
|
+
return hasCompleteChunk;
|
|
30
|
+
},
|
|
31
|
+
get parseLzma2ChunkHeader () {
|
|
32
|
+
return parseLzma2ChunkHeader;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
function parseLzma2ChunkHeader(input, offset) {
|
|
36
|
+
if (offset >= input.length) {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
needBytes: 1
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var control = input[offset];
|
|
43
|
+
// End of stream
|
|
44
|
+
if (control === 0x00) {
|
|
45
|
+
return {
|
|
46
|
+
success: true,
|
|
47
|
+
chunk: {
|
|
48
|
+
type: 'end',
|
|
49
|
+
headerSize: 1,
|
|
50
|
+
dictReset: false,
|
|
51
|
+
stateReset: false,
|
|
52
|
+
newProps: null,
|
|
53
|
+
uncompSize: 0,
|
|
54
|
+
compSize: 0
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Uncompressed chunk
|
|
59
|
+
if (control === 0x01 || control === 0x02) {
|
|
60
|
+
// Need 3 bytes: control + 2 size bytes
|
|
61
|
+
if (offset + 3 > input.length) {
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
needBytes: 3 - (input.length - offset)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var uncompSize = (input[offset + 1] << 8 | input[offset + 2]) + 1;
|
|
68
|
+
return {
|
|
69
|
+
success: true,
|
|
70
|
+
chunk: {
|
|
71
|
+
type: 'uncompressed',
|
|
72
|
+
headerSize: 3,
|
|
73
|
+
dictReset: control === 0x01,
|
|
74
|
+
stateReset: false,
|
|
75
|
+
newProps: null,
|
|
76
|
+
uncompSize: uncompSize,
|
|
77
|
+
compSize: 0
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// LZMA compressed chunk
|
|
82
|
+
if (control >= 0x80) {
|
|
83
|
+
var hasNewProps = control >= 0xc0;
|
|
84
|
+
var minHeaderSize = hasNewProps ? 6 : 5; // control + 2 uncomp + 2 comp + (1 props)
|
|
85
|
+
if (offset + minHeaderSize > input.length) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
needBytes: minHeaderSize - (input.length - offset)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Parse sizes
|
|
92
|
+
var uncompHigh = control & 0x1f;
|
|
93
|
+
var uncompSize1 = (uncompHigh << 16 | input[offset + 1] << 8 | input[offset + 2]) + 1;
|
|
94
|
+
var compSize = (input[offset + 3] << 8 | input[offset + 4]) + 1;
|
|
95
|
+
// Parse properties if present
|
|
96
|
+
var newProps = null;
|
|
97
|
+
if (hasNewProps) {
|
|
98
|
+
var propsByte = input[offset + 5];
|
|
99
|
+
var lc = propsByte % 9;
|
|
100
|
+
var remainder = ~~(propsByte / 9);
|
|
101
|
+
var lp = remainder % 5;
|
|
102
|
+
var pb = ~~(remainder / 5);
|
|
103
|
+
newProps = {
|
|
104
|
+
lc: lc,
|
|
105
|
+
lp: lp,
|
|
106
|
+
pb: pb
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
success: true,
|
|
111
|
+
chunk: {
|
|
112
|
+
type: 'lzma',
|
|
113
|
+
headerSize: minHeaderSize,
|
|
114
|
+
dictReset: control >= 0xe0,
|
|
115
|
+
stateReset: control >= 0xa0,
|
|
116
|
+
newProps: newProps,
|
|
117
|
+
uncompSize: uncompSize1,
|
|
118
|
+
compSize: compSize
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// Invalid control byte
|
|
123
|
+
throw new Error("Invalid LZMA2 control byte: 0x".concat(control.toString(16)));
|
|
124
|
+
}
|
|
125
|
+
function hasCompleteChunk(input, offset) {
|
|
126
|
+
var result = parseLzma2ChunkHeader(input, offset);
|
|
127
|
+
if (result.success === false) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
needBytes: result.needBytes
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
var chunk = result.chunk;
|
|
134
|
+
var dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
|
|
135
|
+
var totalSize = chunk.headerSize + dataSize;
|
|
136
|
+
if (offset + totalSize > input.length) {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
needBytes: totalSize - (input.length - offset)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
success: true,
|
|
144
|
+
chunk: chunk,
|
|
145
|
+
totalSize: totalSize
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/* 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/lzma/Lzma2ChunkParser.ts"],"sourcesContent":["/**\n * LZMA2 Chunk Parser\n *\n * Shared parsing logic for LZMA2 chunk headers.\n * Used by both synchronous and streaming decoders.\n *\n * LZMA2 control byte ranges:\n * 0x00 = End of stream\n * 0x01 = Uncompressed chunk, dictionary reset\n * 0x02 = Uncompressed chunk, no dictionary reset\n * 0x80-0x9F = LZMA chunk, no reset (solid mode)\n * 0xA0-0xBF = LZMA chunk, reset state (probabilities)\n * 0xC0-0xDF = LZMA chunk, reset state + new properties\n * 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties\n */\n\n/**\n * LZMA properties extracted from chunk header\n */\nexport interface LzmaChunkProps {\n lc: number;\n lp: number;\n pb: number;\n}\n\n/**\n * Parsed LZMA2 chunk information\n */\nexport interface Lzma2Chunk {\n /** Chunk type */\n type: 'end' | 'uncompressed' | 'lzma';\n /** Total bytes consumed by header (including control byte) */\n headerSize: number;\n /** Whether to reset dictionary */\n dictReset: boolean;\n /** Whether to reset state/probabilities */\n stateReset: boolean;\n /** New LZMA properties (only for control >= 0xC0) */\n newProps: LzmaChunkProps | null;\n /** Uncompressed data size */\n uncompSize: number;\n /** Compressed data size (0 for uncompressed chunks) */\n compSize: number;\n}\n\n/**\n * Result of parsing attempt\n */\nexport type ParseResult = { success: true; chunk: Lzma2Chunk } | { success: false; needBytes: number };\n\n/**\n * Parse an LZMA2 chunk header\n *\n * @param input - Input buffer\n * @param offset - Offset to start parsing\n * @returns Parsed chunk info or number of bytes needed\n */\nexport function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult {\n if (offset >= input.length) {\n return { success: false, needBytes: 1 };\n }\n\n const control = input[offset];\n\n // End of stream\n if (control === 0x00) {\n return {\n success: true,\n chunk: {\n type: 'end',\n headerSize: 1,\n dictReset: false,\n stateReset: false,\n newProps: null,\n uncompSize: 0,\n compSize: 0,\n },\n };\n }\n\n // Uncompressed chunk\n if (control === 0x01 || control === 0x02) {\n // Need 3 bytes: control + 2 size bytes\n if (offset + 3 > input.length) {\n return { success: false, needBytes: 3 - (input.length - offset) };\n }\n\n const uncompSize = ((input[offset + 1] << 8) | input[offset + 2]) + 1;\n\n return {\n success: true,\n chunk: {\n type: 'uncompressed',\n headerSize: 3,\n dictReset: control === 0x01,\n stateReset: false,\n newProps: null,\n uncompSize,\n compSize: 0,\n },\n };\n }\n\n // LZMA compressed chunk\n if (control >= 0x80) {\n const hasNewProps = control >= 0xc0;\n const minHeaderSize = hasNewProps ? 6 : 5; // control + 2 uncomp + 2 comp + (1 props)\n\n if (offset + minHeaderSize > input.length) {\n return { success: false, needBytes: minHeaderSize - (input.length - offset) };\n }\n\n // Parse sizes\n const uncompHigh = control & 0x1f;\n const uncompSize = ((uncompHigh << 16) | (input[offset + 1] << 8) | input[offset + 2]) + 1;\n const compSize = ((input[offset + 3] << 8) | input[offset + 4]) + 1;\n\n // Parse properties if present\n let newProps: LzmaChunkProps | null = null;\n if (hasNewProps) {\n const propsByte = input[offset + 5];\n const lc = propsByte % 9;\n const remainder = ~~(propsByte / 9);\n const lp = remainder % 5;\n const pb = ~~(remainder / 5);\n newProps = { lc, lp, pb };\n }\n\n return {\n success: true,\n chunk: {\n type: 'lzma',\n headerSize: minHeaderSize,\n dictReset: control >= 0xe0,\n stateReset: control >= 0xa0,\n newProps,\n uncompSize,\n compSize,\n },\n };\n }\n\n // Invalid control byte\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n}\n\n/** Result type for hasCompleteChunk with totalSize included on success */\nexport type CompleteChunkResult = { success: true; chunk: Lzma2Chunk; totalSize: number } | { success: false; needBytes: number };\n\n/**\n * Check if we have enough data for the complete chunk (header + data)\n */\nexport function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (result.success === false) {\n return { success: false, needBytes: result.needBytes };\n }\n\n const { chunk } = result;\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n const totalSize = chunk.headerSize + dataSize;\n\n if (offset + totalSize > input.length) {\n return { success: false, needBytes: totalSize - (input.length - offset) };\n }\n\n return { success: true, chunk, totalSize };\n}\n"],"names":["hasCompleteChunk","parseLzma2ChunkHeader","input","offset","length","success","needBytes","control","chunk","type","headerSize","dictReset","stateReset","newProps","uncompSize","compSize","hasNewProps","minHeaderSize","uncompHigh","propsByte","lc","remainder","lp","pb","Error","toString","result","dataSize","totalSize"],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Decoder Module
|
|
3
|
+
*
|
|
4
|
+
* Provides both synchronous and streaming LZMA1/LZMA2 decoders.
|
|
5
|
+
*
|
|
6
|
+
* Synchronous API: Use when input is a complete Buffer
|
|
7
|
+
* Streaming API: Use with Transform streams for memory-efficient decompression
|
|
8
|
+
*/
|
|
9
|
+
export { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.js';
|
|
10
|
+
export { decodeLzma2, Lzma2Decoder } from './sync/Lzma2Decoder.js';
|
|
11
|
+
export { decodeLzma, LzmaDecoder } from './sync/LzmaDecoder.js';
|
|
12
|
+
export { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.js';
|
|
13
|
+
export * from './types.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Decoder Module
|
|
3
|
+
*
|
|
4
|
+
* Provides both synchronous and streaming LZMA1/LZMA2 decoders.
|
|
5
|
+
*
|
|
6
|
+
* Synchronous API: Use when input is a complete Buffer
|
|
7
|
+
* Streaming API: Use with Transform streams for memory-efficient decompression
|
|
8
|
+
*/
|
|
9
|
+
export { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.js';
|
|
10
|
+
export { decodeLzma2, Lzma2Decoder } from './sync/Lzma2Decoder.js';
|
|
11
|
+
export { decodeLzma, LzmaDecoder } from './sync/LzmaDecoder.js';
|
|
12
|
+
export { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.js';
|
|
13
|
+
export * from './types.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Decoder Module
|
|
3
|
+
*
|
|
4
|
+
* Provides both synchronous and streaming LZMA1/LZMA2 decoders.
|
|
5
|
+
*
|
|
6
|
+
* Synchronous API: Use when input is a complete Buffer
|
|
7
|
+
* Streaming API: Use with Transform streams for memory-efficient decompression
|
|
8
|
+
*/ // Streaming decoders (Transform streams)
|
|
9
|
+
"use strict";
|
|
10
|
+
Object.defineProperty(exports, "__esModule", {
|
|
11
|
+
value: true
|
|
12
|
+
});
|
|
13
|
+
function _export(target, all) {
|
|
14
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
_export(exports, {
|
|
20
|
+
get BitTreeDecoder () {
|
|
21
|
+
return _RangeDecoderts.BitTreeDecoder;
|
|
22
|
+
},
|
|
23
|
+
get Lzma2Decoder () {
|
|
24
|
+
return _Lzma2Decoderts.Lzma2Decoder;
|
|
25
|
+
},
|
|
26
|
+
get LzmaDecoder () {
|
|
27
|
+
return _LzmaDecoderts.LzmaDecoder;
|
|
28
|
+
},
|
|
29
|
+
get RangeDecoder () {
|
|
30
|
+
return _RangeDecoderts.RangeDecoder;
|
|
31
|
+
},
|
|
32
|
+
get createLzma2Decoder () {
|
|
33
|
+
return _transformsts.createLzma2Decoder;
|
|
34
|
+
},
|
|
35
|
+
get createLzmaDecoder () {
|
|
36
|
+
return _transformsts.createLzmaDecoder;
|
|
37
|
+
},
|
|
38
|
+
get decodeLzma () {
|
|
39
|
+
return _LzmaDecoderts.decodeLzma;
|
|
40
|
+
},
|
|
41
|
+
get decodeLzma2 () {
|
|
42
|
+
return _Lzma2Decoderts.decodeLzma2;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
var _transformsts = require("./stream/transforms.js");
|
|
46
|
+
var _Lzma2Decoderts = require("./sync/Lzma2Decoder.js");
|
|
47
|
+
var _LzmaDecoderts = require("./sync/LzmaDecoder.js");
|
|
48
|
+
var _RangeDecoderts = require("./sync/RangeDecoder.js");
|
|
49
|
+
_export_star(require("./types.js"), exports);
|
|
50
|
+
function _export_star(from, to) {
|
|
51
|
+
Object.keys(from).forEach(function(k) {
|
|
52
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
53
|
+
Object.defineProperty(to, k, {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function() {
|
|
56
|
+
return from[k];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return from;
|
|
62
|
+
}
|
|
63
|
+
/* 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/lzma/index.ts"],"sourcesContent":["/**\n * LZMA Decoder Module\n *\n * Provides both synchronous and streaming LZMA1/LZMA2 decoders.\n *\n * Synchronous API: Use when input is a complete Buffer\n * Streaming API: Use with Transform streams for memory-efficient decompression\n */\n\n// Streaming decoders (Transform streams)\nexport { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.ts';\nexport { decodeLzma2, Lzma2Decoder } from './sync/Lzma2Decoder.ts';\n// Synchronous decoders (for Buffer input)\nexport { decodeLzma, LzmaDecoder } from './sync/LzmaDecoder.ts';\nexport { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.ts';\n// Type exports\nexport * from './types.ts';\n"],"names":["BitTreeDecoder","Lzma2Decoder","LzmaDecoder","RangeDecoder","createLzma2Decoder","createLzmaDecoder","decodeLzma","decodeLzma2"],"mappings":"AAAA;;;;;;;CAOC,GAED,yCAAyC;;;;;;;;;;;;QAKhCA;eAAAA,8BAAc;;QAHDC;eAAAA,4BAAY;;QAEbC;eAAAA,0BAAW;;QACPC;eAAAA,4BAAY;;QAJ5BC;eAAAA,gCAAkB;;QAAEC;eAAAA,+BAAiB;;QAGrCC;eAAAA,yBAAU;;QAFVC;eAAAA,2BAAW;;;4BADkC;8BACZ;6BAEF;8BACK;qBAE/B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Transform Stream Wrappers
|
|
3
|
+
*
|
|
4
|
+
* Provides Transform streams for LZMA1 and LZMA2 decompression.
|
|
5
|
+
*
|
|
6
|
+
* LZMA2 streaming works by buffering until a complete chunk is available,
|
|
7
|
+
* then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max
|
|
8
|
+
* uncompressed), so memory usage is predictable and bounded.
|
|
9
|
+
*
|
|
10
|
+
* True byte-by-byte async LZMA streaming would require rewriting the entire
|
|
11
|
+
* decoder with continuation-passing style, which is complex and not worth
|
|
12
|
+
* the effort given LZMA2's chunked format.
|
|
13
|
+
*/
|
|
14
|
+
import { Transform } from 'extract-base-iterator';
|
|
15
|
+
/**
|
|
16
|
+
* Create an LZMA2 decoder Transform stream
|
|
17
|
+
*
|
|
18
|
+
* This is a streaming decoder that processes LZMA2 chunks incrementally.
|
|
19
|
+
* Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).
|
|
20
|
+
*
|
|
21
|
+
* @param properties - 1-byte LZMA2 properties (dictionary size)
|
|
22
|
+
* @returns Transform stream that decompresses LZMA2 data
|
|
23
|
+
*/
|
|
24
|
+
export declare function createLzma2Decoder(properties: Buffer | Uint8Array): InstanceType<typeof Transform>;
|
|
25
|
+
/**
|
|
26
|
+
* Create an LZMA1 decoder Transform stream
|
|
27
|
+
*
|
|
28
|
+
* Note: LZMA1 has no chunk boundaries, so this requires knowing the
|
|
29
|
+
* uncompressed size upfront. The stream buffers all input, then
|
|
30
|
+
* decompresses when complete.
|
|
31
|
+
*
|
|
32
|
+
* For true streaming, use LZMA2 which has built-in chunking.
|
|
33
|
+
*
|
|
34
|
+
* @param properties - 5-byte LZMA properties
|
|
35
|
+
* @param unpackSize - Expected uncompressed size
|
|
36
|
+
* @returns Transform stream that decompresses LZMA1 data
|
|
37
|
+
*/
|
|
38
|
+
export declare function createLzmaDecoder(properties: Buffer | Uint8Array, unpackSize: number): InstanceType<typeof Transform>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Transform Stream Wrappers
|
|
3
|
+
*
|
|
4
|
+
* Provides Transform streams for LZMA1 and LZMA2 decompression.
|
|
5
|
+
*
|
|
6
|
+
* LZMA2 streaming works by buffering until a complete chunk is available,
|
|
7
|
+
* then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max
|
|
8
|
+
* uncompressed), so memory usage is predictable and bounded.
|
|
9
|
+
*
|
|
10
|
+
* True byte-by-byte async LZMA streaming would require rewriting the entire
|
|
11
|
+
* decoder with continuation-passing style, which is complex and not worth
|
|
12
|
+
* the effort given LZMA2's chunked format.
|
|
13
|
+
*/
|
|
14
|
+
import { Transform } from 'extract-base-iterator';
|
|
15
|
+
/**
|
|
16
|
+
* Create an LZMA2 decoder Transform stream
|
|
17
|
+
*
|
|
18
|
+
* This is a streaming decoder that processes LZMA2 chunks incrementally.
|
|
19
|
+
* Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).
|
|
20
|
+
*
|
|
21
|
+
* @param properties - 1-byte LZMA2 properties (dictionary size)
|
|
22
|
+
* @returns Transform stream that decompresses LZMA2 data
|
|
23
|
+
*/
|
|
24
|
+
export declare function createLzma2Decoder(properties: Buffer | Uint8Array): InstanceType<typeof Transform>;
|
|
25
|
+
/**
|
|
26
|
+
* Create an LZMA1 decoder Transform stream
|
|
27
|
+
*
|
|
28
|
+
* Note: LZMA1 has no chunk boundaries, so this requires knowing the
|
|
29
|
+
* uncompressed size upfront. The stream buffers all input, then
|
|
30
|
+
* decompresses when complete.
|
|
31
|
+
*
|
|
32
|
+
* For true streaming, use LZMA2 which has built-in chunking.
|
|
33
|
+
*
|
|
34
|
+
* @param properties - 5-byte LZMA properties
|
|
35
|
+
* @param unpackSize - Expected uncompressed size
|
|
36
|
+
* @returns Transform stream that decompresses LZMA1 data
|
|
37
|
+
*/
|
|
38
|
+
export declare function createLzmaDecoder(properties: Buffer | Uint8Array, unpackSize: number): InstanceType<typeof Transform>;
|