7z-iterator 1.1.2 → 1.3.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 +1 -2
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +19 -3
- 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 +1 -2
- package/dist/esm/index.js +2 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/sync/RangeDecoder.ts"],"sourcesContent":["/**\n * Synchronous Range Decoder for LZMA\n *\n * Decodes arithmetic-coded bits from a buffer.\n * All operations are synchronous - for streaming use the async version.\n */\n\nimport { allocBuffer } from 'extract-base-iterator';\n\n/**\n * Range decoder for synchronous buffer-based LZMA decoding\n */\nexport class RangeDecoder {\n private input: Buffer;\n private pos: number;\n private code: number;\n private range: number;\n\n constructor() {\n this.input = allocBuffer(0); // Replaced by setInput() before use\n this.pos = 0;\n this.code = 0;\n this.range = 0;\n }\n\n /**\n * Set input buffer and initialize decoder state\n */\n setInput(input: Buffer, offset = 0): void {\n this.input = input;\n this.pos = offset;\n this.init();\n }\n\n /**\n * Initialize range decoder (reads first 5 bytes)\n */\n private init(): void {\n this.code = 0;\n this.range = -1; // 0xFFFFFFFF as signed int\n\n // First byte is ignored (should be 0)\n this.pos++;\n\n // Read 4 bytes into code\n for (let i = 0; i < 4; i++) {\n this.code = (this.code << 8) | this.input[this.pos++];\n }\n }\n\n /**\n * Get current position in input buffer\n */\n getPosition(): number {\n return this.pos;\n }\n\n /**\n * Normalize range if needed (read more bytes)\n */\n private normalize(): void {\n if ((this.range & 0xff000000) === 0) {\n this.code = (this.code << 8) | this.input[this.pos++];\n this.range <<= 8;\n }\n }\n\n /**\n * Decode a single bit using probability model\n * @param probs - Probability array\n * @param index - Index into probability array\n * @returns Decoded bit (0 or 1)\n */\n decodeBit(probs: Uint16Array, index: number): number {\n const prob = probs[index];\n const newBound = (this.range >>> 11) * prob;\n\n if ((this.code ^ 0x80000000) < (newBound ^ 0x80000000)) {\n this.range = newBound;\n probs[index] += (2048 - prob) >>> 5;\n this.normalize();\n return 0;\n }\n this.range -= newBound;\n this.code -= newBound;\n probs[index] -= prob >>> 5;\n this.normalize();\n return 1;\n }\n\n /**\n * Decode direct bits (not probability-based)\n * @param numTotalBits - Number of bits to decode\n * @returns Decoded value\n */\n decodeDirectBits(numTotalBits: number): number {\n let result = 0;\n for (let i = numTotalBits; i > 0; i--) {\n this.range >>>= 1;\n const t = (this.code - this.range) >>> 31;\n this.code -= this.range & (t - 1);\n result = (result << 1) | (1 - t);\n this.normalize();\n }\n return result;\n }\n}\n\n/**\n * Bit tree decoder for multi-bit symbols\n */\nexport class BitTreeDecoder {\n private numBitLevels: number;\n private models: Uint16Array;\n\n constructor(numBitLevels: number) {\n this.numBitLevels = numBitLevels;\n this.models = new Uint16Array(1 << numBitLevels);\n this.init();\n }\n\n /**\n * Initialize probability models\n */\n init(): void {\n for (let i = 0; i < this.models.length; i++) {\n this.models[i] = 1024; // kProbInitValue\n }\n }\n\n /**\n * Decode a symbol (forward bit order)\n */\n decode(rangeDecoder: RangeDecoder): number {\n let m = 1;\n for (let i = this.numBitLevels; i > 0; i--) {\n m = (m << 1) | rangeDecoder.decodeBit(this.models, m);\n }\n return m - (1 << this.numBitLevels);\n }\n\n /**\n * Decode a symbol (reverse bit order)\n */\n reverseDecode(rangeDecoder: RangeDecoder): number {\n let m = 1;\n let symbol = 0;\n for (let i = 0; i < this.numBitLevels; i++) {\n const bit = rangeDecoder.decodeBit(this.models, m);\n m = (m << 1) | bit;\n symbol |= bit << i;\n }\n return symbol;\n }\n}\n\n/**\n * Static reverse decode from external probability array\n */\nexport function reverseDecodeFromArray(models: Uint16Array, startIndex: number, rangeDecoder: RangeDecoder, numBitLevels: number): number {\n let m = 1;\n let symbol = 0;\n for (let i = 0; i < numBitLevels; i++) {\n const bit = rangeDecoder.decodeBit(models, startIndex + m);\n m = (m << 1) | bit;\n symbol |= bit << i;\n }\n return symbol;\n}\n"],"names":["allocBuffer","RangeDecoder","setInput","input","offset","pos","init","code","range","i","getPosition","normalize","decodeBit","probs","index","prob","newBound","decodeDirectBits","numTotalBits","result","t","BitTreeDecoder","models","length","decode","rangeDecoder","m","numBitLevels","reverseDecode","symbol","bit","Uint16Array","reverseDecodeFromArray","startIndex"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,WAAW,QAAQ,wBAAwB;AAEpD;;CAEC,GACD,OAAO,MAAMC;IAaX;;GAEC,GACDC,SAASC,KAAa,EAAEC,SAAS,CAAC,EAAQ;QACxC,IAAI,CAACD,KAAK,GAAGA;QACb,IAAI,CAACE,GAAG,GAAGD;QACX,IAAI,CAACE,IAAI;IACX;IAEA;;GAEC,GACD,AAAQA,OAAa;QACnB,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACC,KAAK,GAAG,CAAC,GAAG,2BAA2B;QAE5C,sCAAsC;QACtC,IAAI,CAACH,GAAG;QAER,yBAAyB;QACzB,IAAK,IAAII,IAAI,GAAGA,IAAI,GAAGA,IAAK;YAC1B,IAAI,CAACF,IAAI,GAAG,AAAC,IAAI,CAACA,IAAI,IAAI,IAAK,IAAI,CAACJ,KAAK,CAAC,IAAI,CAACE,GAAG,GAAG;QACvD;IACF;IAE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AK;QACrC,MAAMqB,MAAML,aAAab,SAAS,CAACU,QAAQW,aAAaP;QACxDA,IAAI,AAACA,KAAK,IAAKI;QACfD,UAAUC,OAAOrB;IACnB;IACA,OAAOoB;AACT"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Types and Constants
|
|
3
|
+
*
|
|
4
|
+
* Shared types, constants, and state transition functions for LZMA decoding.
|
|
5
|
+
* Based on the LZMA SDK specification.
|
|
6
|
+
*/
|
|
7
|
+
export declare const kNumRepDistances = 4;
|
|
8
|
+
export declare const kNumStates = 12;
|
|
9
|
+
export declare const kNumPosSlotBits = 6;
|
|
10
|
+
export declare const kDicLogSizeMin = 0;
|
|
11
|
+
export declare const kNumLenToPosStatesBits = 2;
|
|
12
|
+
export declare const kNumLenToPosStates: number;
|
|
13
|
+
export declare const kMatchMinLen = 2;
|
|
14
|
+
export declare const kNumLowLenBits = 3;
|
|
15
|
+
export declare const kNumMidLenBits = 3;
|
|
16
|
+
export declare const kNumHighLenBits = 8;
|
|
17
|
+
export declare const kNumLowLenSymbols: number;
|
|
18
|
+
export declare const kNumMidLenSymbols: number;
|
|
19
|
+
export declare const kNumLenSymbols: number;
|
|
20
|
+
export declare const kMatchMaxLen: number;
|
|
21
|
+
export declare const kNumAlignBits = 4;
|
|
22
|
+
export declare const kAlignTableSize: number;
|
|
23
|
+
export declare const kAlignMask: number;
|
|
24
|
+
export declare const kStartPosModelIndex = 4;
|
|
25
|
+
export declare const kEndPosModelIndex = 14;
|
|
26
|
+
export declare const kNumPosModels: number;
|
|
27
|
+
export declare const kNumFullDistances: number;
|
|
28
|
+
export declare const kNumLitPosStatesBitsEncodingMax = 4;
|
|
29
|
+
export declare const kNumLitContextBitsMax = 8;
|
|
30
|
+
export declare const kNumPosStatesBitsMax = 4;
|
|
31
|
+
export declare const kNumPosStatesMax: number;
|
|
32
|
+
export declare const kNumPosStatesBitsEncodingMax = 4;
|
|
33
|
+
export declare const kNumPosStatesEncodingMax: number;
|
|
34
|
+
export declare const kNumBitModelTotalBits = 11;
|
|
35
|
+
export declare const kBitModelTotal: number;
|
|
36
|
+
export declare const kNumMoveBits = 5;
|
|
37
|
+
export declare const kProbInitValue: number;
|
|
38
|
+
/**
|
|
39
|
+
* State transition: after literal byte
|
|
40
|
+
*/
|
|
41
|
+
export declare function stateUpdateChar(state: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* State transition: after match
|
|
44
|
+
*/
|
|
45
|
+
export declare function stateUpdateMatch(state: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* State transition: after rep (repeated match)
|
|
48
|
+
*/
|
|
49
|
+
export declare function stateUpdateRep(state: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* State transition: after short rep
|
|
52
|
+
*/
|
|
53
|
+
export declare function stateUpdateShortRep(state: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* Check if state indicates previous symbol was a character (literal)
|
|
56
|
+
*/
|
|
57
|
+
export declare function stateIsCharState(state: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get length-to-position state index
|
|
60
|
+
*/
|
|
61
|
+
export declare function getLenToPosState(len: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* Initialize probability array with default values
|
|
64
|
+
* @param probs - Array to initialize (or null to create new)
|
|
65
|
+
* @param count - Number of probabilities
|
|
66
|
+
* @returns Initialized probability array
|
|
67
|
+
*/
|
|
68
|
+
export declare function initBitModels(probs: Uint16Array | null, count?: number): Uint16Array;
|
|
69
|
+
/**
|
|
70
|
+
* LZMA properties parsed from the 5-byte header
|
|
71
|
+
*/
|
|
72
|
+
export interface LzmaProperties {
|
|
73
|
+
/** Literal context bits (0-8) */
|
|
74
|
+
lc: number;
|
|
75
|
+
/** Literal pos bits (0-4) */
|
|
76
|
+
lp: number;
|
|
77
|
+
/** Pos bits (0-4) */
|
|
78
|
+
pb: number;
|
|
79
|
+
/** Dictionary size in bytes */
|
|
80
|
+
dictionarySize: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parse LZMA properties from a 5-byte buffer
|
|
84
|
+
*/
|
|
85
|
+
export declare function parseProperties(properties: Buffer | Uint8Array): LzmaProperties;
|
|
86
|
+
/**
|
|
87
|
+
* LZMA2 control byte meanings
|
|
88
|
+
*/
|
|
89
|
+
export declare const LZMA2_CONTROL: {
|
|
90
|
+
readonly END: 0;
|
|
91
|
+
readonly UNCOMPRESSED_RESET_DIC: 1;
|
|
92
|
+
readonly UNCOMPRESSED: 2;
|
|
93
|
+
readonly LZMA_RESET_STATE_NEW_PROP: 224;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Check if LZMA2 control byte indicates reset state (new properties)
|
|
97
|
+
*/
|
|
98
|
+
export declare function lzma2NeedsNewProps(control: number): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Check if LZMA2 control byte indicates reset probabilities
|
|
101
|
+
*/
|
|
102
|
+
export declare function lzma2NeedsResetProbs(control: number): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Check if LZMA2 control byte indicates uncompressed chunk
|
|
105
|
+
*/
|
|
106
|
+
export declare function lzma2IsUncompressed(control: number): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Parse LZMA2 dictionary size from property byte
|
|
109
|
+
*/
|
|
110
|
+
export declare function parseLzma2DictionarySize(prop: number): number;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA Types and Constants
|
|
3
|
+
*
|
|
4
|
+
* Shared types, constants, and state transition functions for LZMA decoding.
|
|
5
|
+
* Based on the LZMA SDK specification.
|
|
6
|
+
*/ // LZMA State Machine Constants
|
|
7
|
+
export const kNumRepDistances = 4;
|
|
8
|
+
export const kNumStates = 12;
|
|
9
|
+
// Position slot constants
|
|
10
|
+
export const kNumPosSlotBits = 6;
|
|
11
|
+
export const kDicLogSizeMin = 0;
|
|
12
|
+
export const kNumLenToPosStatesBits = 2;
|
|
13
|
+
export const kNumLenToPosStates = 1 << kNumLenToPosStatesBits; // 4
|
|
14
|
+
// Match length constants
|
|
15
|
+
export const kMatchMinLen = 2;
|
|
16
|
+
export const kNumLowLenBits = 3;
|
|
17
|
+
export const kNumMidLenBits = 3;
|
|
18
|
+
export const kNumHighLenBits = 8;
|
|
19
|
+
export const kNumLowLenSymbols = 1 << kNumLowLenBits; // 8
|
|
20
|
+
export const kNumMidLenSymbols = 1 << kNumMidLenBits; // 8
|
|
21
|
+
export const kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + (1 << kNumHighLenBits); // 272
|
|
22
|
+
export const kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; // 273
|
|
23
|
+
// Alignment constants
|
|
24
|
+
export const kNumAlignBits = 4;
|
|
25
|
+
export const kAlignTableSize = 1 << kNumAlignBits; // 16
|
|
26
|
+
export const kAlignMask = kAlignTableSize - 1; // 15
|
|
27
|
+
// Position model constants
|
|
28
|
+
export const kStartPosModelIndex = 4;
|
|
29
|
+
export const kEndPosModelIndex = 14;
|
|
30
|
+
export const kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; // 10
|
|
31
|
+
export const kNumFullDistances = 1 << (kEndPosModelIndex >>> 1); // 128
|
|
32
|
+
// Literal/pos state constants
|
|
33
|
+
export const kNumLitPosStatesBitsEncodingMax = 4;
|
|
34
|
+
export const kNumLitContextBitsMax = 8;
|
|
35
|
+
export const kNumPosStatesBitsMax = 4;
|
|
36
|
+
export const kNumPosStatesMax = 1 << kNumPosStatesBitsMax; // 16
|
|
37
|
+
export const kNumPosStatesBitsEncodingMax = 4;
|
|
38
|
+
export const kNumPosStatesEncodingMax = 1 << kNumPosStatesBitsEncodingMax; // 16
|
|
39
|
+
// Range coder probability constants
|
|
40
|
+
export const kNumBitModelTotalBits = 11;
|
|
41
|
+
export const kBitModelTotal = 1 << kNumBitModelTotalBits; // 2048
|
|
42
|
+
export const kNumMoveBits = 5;
|
|
43
|
+
export const kProbInitValue = kBitModelTotal >>> 1; // 1024
|
|
44
|
+
/**
|
|
45
|
+
* State transition: after literal byte
|
|
46
|
+
*/ export function stateUpdateChar(state) {
|
|
47
|
+
if (state < 4) return 0;
|
|
48
|
+
if (state < 10) return state - 3;
|
|
49
|
+
return state - 6;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* State transition: after match
|
|
53
|
+
*/ export function stateUpdateMatch(state) {
|
|
54
|
+
return state < 7 ? 7 : 10;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* State transition: after rep (repeated match)
|
|
58
|
+
*/ export function stateUpdateRep(state) {
|
|
59
|
+
return state < 7 ? 8 : 11;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* State transition: after short rep
|
|
63
|
+
*/ export function stateUpdateShortRep(state) {
|
|
64
|
+
return state < 7 ? 9 : 11;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if state indicates previous symbol was a character (literal)
|
|
68
|
+
*/ export function stateIsCharState(state) {
|
|
69
|
+
return state < 7;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get length-to-position state index
|
|
73
|
+
*/ export function getLenToPosState(len) {
|
|
74
|
+
len -= kMatchMinLen;
|
|
75
|
+
return len < kNumLenToPosStates ? len : kNumLenToPosStates - 1;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Initialize probability array with default values
|
|
79
|
+
* @param probs - Array to initialize (or null to create new)
|
|
80
|
+
* @param count - Number of probabilities
|
|
81
|
+
* @returns Initialized probability array
|
|
82
|
+
*/ export function initBitModels(probs, count) {
|
|
83
|
+
if (probs === null) {
|
|
84
|
+
if (count === undefined) {
|
|
85
|
+
throw new Error('count required when probs is null');
|
|
86
|
+
}
|
|
87
|
+
probs = new Uint16Array(count);
|
|
88
|
+
}
|
|
89
|
+
for(let i = 0; i < probs.length; i++){
|
|
90
|
+
probs[i] = kProbInitValue;
|
|
91
|
+
}
|
|
92
|
+
return probs;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parse LZMA properties from a 5-byte buffer
|
|
96
|
+
*/ export function parseProperties(properties) {
|
|
97
|
+
if (properties.length < 5) {
|
|
98
|
+
throw new Error('LZMA properties must be at least 5 bytes');
|
|
99
|
+
}
|
|
100
|
+
const d = properties[0] & 0xff;
|
|
101
|
+
const lc = d % 9;
|
|
102
|
+
const remainder = ~~(d / 9);
|
|
103
|
+
const lp = remainder % 5;
|
|
104
|
+
const pb = ~~(remainder / 5);
|
|
105
|
+
if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {
|
|
106
|
+
throw new Error('Invalid LZMA properties');
|
|
107
|
+
}
|
|
108
|
+
let dictionarySize = 0;
|
|
109
|
+
for(let i = 0; i < 4; i++){
|
|
110
|
+
dictionarySize |= (properties[1 + i] & 0xff) << i * 8;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
lc,
|
|
114
|
+
lp,
|
|
115
|
+
pb,
|
|
116
|
+
dictionarySize
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* LZMA2 control byte meanings
|
|
121
|
+
*/ export const LZMA2_CONTROL = {
|
|
122
|
+
END: 0x00,
|
|
123
|
+
UNCOMPRESSED_RESET_DIC: 0x01,
|
|
124
|
+
UNCOMPRESSED: 0x02,
|
|
125
|
+
LZMA_RESET_STATE_NEW_PROP: 0xe0
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Check if LZMA2 control byte indicates reset state (new properties)
|
|
129
|
+
*/ export function lzma2NeedsNewProps(control) {
|
|
130
|
+
return control >= 0xe0;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if LZMA2 control byte indicates reset probabilities
|
|
134
|
+
*/ export function lzma2NeedsResetProbs(control) {
|
|
135
|
+
return control >= 0xa0;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Check if LZMA2 control byte indicates uncompressed chunk
|
|
139
|
+
*/ export function lzma2IsUncompressed(control) {
|
|
140
|
+
return control < 0x80;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Parse LZMA2 dictionary size from property byte
|
|
144
|
+
*/ export function parseLzma2DictionarySize(prop) {
|
|
145
|
+
if (prop > 40) {
|
|
146
|
+
throw new Error('Invalid LZMA2 dictionary size property');
|
|
147
|
+
}
|
|
148
|
+
if (prop === 40) {
|
|
149
|
+
return 0xffffffff;
|
|
150
|
+
}
|
|
151
|
+
const base = 2 | prop & 1;
|
|
152
|
+
const exp = (prop >>> 1) + 11;
|
|
153
|
+
return base << exp;
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/types.ts"],"sourcesContent":["/**\n * LZMA Types and Constants\n *\n * Shared types, constants, and state transition functions for LZMA decoding.\n * Based on the LZMA SDK specification.\n */\n\n// LZMA State Machine Constants\nexport const kNumRepDistances = 4;\nexport const kNumStates = 12;\n\n// Position slot constants\nexport const kNumPosSlotBits = 6;\nexport const kDicLogSizeMin = 0;\nexport const kNumLenToPosStatesBits = 2;\nexport const kNumLenToPosStates = 1 << kNumLenToPosStatesBits; // 4\n\n// Match length constants\nexport const kMatchMinLen = 2;\nexport const kNumLowLenBits = 3;\nexport const kNumMidLenBits = 3;\nexport const kNumHighLenBits = 8;\nexport const kNumLowLenSymbols = 1 << kNumLowLenBits; // 8\nexport const kNumMidLenSymbols = 1 << kNumMidLenBits; // 8\nexport const kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + (1 << kNumHighLenBits); // 272\nexport const kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; // 273\n\n// Alignment constants\nexport const kNumAlignBits = 4;\nexport const kAlignTableSize = 1 << kNumAlignBits; // 16\nexport const kAlignMask = kAlignTableSize - 1; // 15\n\n// Position model constants\nexport const kStartPosModelIndex = 4;\nexport const kEndPosModelIndex = 14;\nexport const kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; // 10\nexport const kNumFullDistances = 1 << (kEndPosModelIndex >>> 1); // 128\n\n// Literal/pos state constants\nexport const kNumLitPosStatesBitsEncodingMax = 4;\nexport const kNumLitContextBitsMax = 8;\nexport const kNumPosStatesBitsMax = 4;\nexport const kNumPosStatesMax = 1 << kNumPosStatesBitsMax; // 16\nexport const kNumPosStatesBitsEncodingMax = 4;\nexport const kNumPosStatesEncodingMax = 1 << kNumPosStatesBitsEncodingMax; // 16\n\n// Range coder probability constants\nexport const kNumBitModelTotalBits = 11;\nexport const kBitModelTotal = 1 << kNumBitModelTotalBits; // 2048\nexport const kNumMoveBits = 5;\nexport const kProbInitValue = kBitModelTotal >>> 1; // 1024\n\n/**\n * State transition: after literal byte\n */\nexport function stateUpdateChar(state: number): number {\n if (state < 4) return 0;\n if (state < 10) return state - 3;\n return state - 6;\n}\n\n/**\n * State transition: after match\n */\nexport function stateUpdateMatch(state: number): number {\n return state < 7 ? 7 : 10;\n}\n\n/**\n * State transition: after rep (repeated match)\n */\nexport function stateUpdateRep(state: number): number {\n return state < 7 ? 8 : 11;\n}\n\n/**\n * State transition: after short rep\n */\nexport function stateUpdateShortRep(state: number): number {\n return state < 7 ? 9 : 11;\n}\n\n/**\n * Check if state indicates previous symbol was a character (literal)\n */\nexport function stateIsCharState(state: number): boolean {\n return state < 7;\n}\n\n/**\n * Get length-to-position state index\n */\nexport function getLenToPosState(len: number): number {\n len -= kMatchMinLen;\n return len < kNumLenToPosStates ? len : kNumLenToPosStates - 1;\n}\n\n/**\n * Initialize probability array with default values\n * @param probs - Array to initialize (or null to create new)\n * @param count - Number of probabilities\n * @returns Initialized probability array\n */\nexport function initBitModels(probs: Uint16Array | null, count?: number): Uint16Array {\n if (probs === null) {\n if (count === undefined) {\n throw new Error('count required when probs is null');\n }\n probs = new Uint16Array(count);\n }\n for (let i = 0; i < probs.length; i++) {\n probs[i] = kProbInitValue;\n }\n return probs;\n}\n\n/**\n * LZMA properties parsed from the 5-byte header\n */\nexport interface LzmaProperties {\n /** Literal context bits (0-8) */\n lc: number;\n /** Literal pos bits (0-4) */\n lp: number;\n /** Pos bits (0-4) */\n pb: number;\n /** Dictionary size in bytes */\n dictionarySize: number;\n}\n\n/**\n * Parse LZMA properties from a 5-byte buffer\n */\nexport function parseProperties(properties: Buffer | Uint8Array): LzmaProperties {\n if (properties.length < 5) {\n throw new Error('LZMA properties must be at least 5 bytes');\n }\n\n const d = properties[0] & 0xff;\n const lc = d % 9;\n const remainder = ~~(d / 9);\n const lp = remainder % 5;\n const pb = ~~(remainder / 5);\n\n if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {\n throw new Error('Invalid LZMA properties');\n }\n\n let dictionarySize = 0;\n for (let i = 0; i < 4; i++) {\n dictionarySize |= (properties[1 + i] & 0xff) << (i * 8);\n }\n\n return { lc, lp, pb, dictionarySize };\n}\n\n/**\n * LZMA2 control byte meanings\n */\nexport const LZMA2_CONTROL = {\n END: 0x00,\n UNCOMPRESSED_RESET_DIC: 0x01,\n UNCOMPRESSED: 0x02,\n LZMA_RESET_STATE_NEW_PROP: 0xe0,\n} as const;\n\n/**\n * Check if LZMA2 control byte indicates reset state (new properties)\n */\nexport function lzma2NeedsNewProps(control: number): boolean {\n return control >= 0xe0;\n}\n\n/**\n * Check if LZMA2 control byte indicates reset probabilities\n */\nexport function lzma2NeedsResetProbs(control: number): boolean {\n return control >= 0xa0;\n}\n\n/**\n * Check if LZMA2 control byte indicates uncompressed chunk\n */\nexport function lzma2IsUncompressed(control: number): boolean {\n return control < 0x80;\n}\n\n/**\n * Parse LZMA2 dictionary size from property byte\n */\nexport function parseLzma2DictionarySize(prop: number): number {\n if (prop > 40) {\n throw new Error('Invalid LZMA2 dictionary size property');\n }\n if (prop === 40) {\n return 0xffffffff;\n }\n const base = 2 | (prop & 1);\n const exp = (prop >>> 1) + 11;\n return base << exp;\n}\n"],"names":["kNumRepDistances","kNumStates","kNumPosSlotBits","kDicLogSizeMin","kNumLenToPosStatesBits","kNumLenToPosStates","kMatchMinLen","kNumLowLenBits","kNumMidLenBits","kNumHighLenBits","kNumLowLenSymbols","kNumMidLenSymbols","kNumLenSymbols","kMatchMaxLen","kNumAlignBits","kAlignTableSize","kAlignMask","kStartPosModelIndex","kEndPosModelIndex","kNumPosModels","kNumFullDistances","kNumLitPosStatesBitsEncodingMax","kNumLitContextBitsMax","kNumPosStatesBitsMax","kNumPosStatesMax","kNumPosStatesBitsEncodingMax","kNumPosStatesEncodingMax","kNumBitModelTotalBits","kBitModelTotal","kNumMoveBits","kProbInitValue","stateUpdateChar","state","stateUpdateMatch","stateUpdateRep","stateUpdateShortRep","stateIsCharState","getLenToPosState","len","initBitModels","probs","count","undefined","Error","Uint16Array","i","length","parseProperties","properties","d","lc","remainder","lp","pb","dictionarySize","LZMA2_CONTROL","END","UNCOMPRESSED_RESET_DIC","UNCOMPRESSED","LZMA_RESET_STATE_NEW_PROP","lzma2NeedsNewProps","control","lzma2NeedsResetProbs","lzma2IsUncompressed","parseLzma2DictionarySize","prop","base","exp"],"mappings":"AAAA;;;;;CAKC,GAED,+BAA+B;AAC/B,OAAO,MAAMA,mBAAmB,EAAE;AAClC,OAAO,MAAMC,aAAa,GAAG;AAE7B,0BAA0B;AAC1B,OAAO,MAAMC,kBAAkB,EAAE;AACjC,OAAO,MAAMC,iBAAiB,EAAE;AAChC,OAAO,MAAMC,yBAAyB,EAAE;AACxC,OAAO,MAAMC,qBAAqB,KAAKD,uBAAuB,CAAC,IAAI;AAEnE,yBAAyB;AACzB,OAAO,MAAME,eAAe,EAAE;AAC9B,OAAO,MAAMC,iBAAiB,EAAE;AAChC,OAAO,MAAMC,iBAAiB,EAAE;AAChC,OAAO,MAAMC,kBAAkB,EAAE;AACjC,OAAO,MAAMC,oBAAoB,KAAKH,eAAe,CAAC,IAAI;AAC1D,OAAO,MAAMI,oBAAoB,KAAKH,eAAe,CAAC,IAAI;AAC1D,OAAO,MAAMI,iBAAiBF,oBAAoBC,oBAAqB,C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,gBAAgB;IAC3BC,KAAK;IACLC,wBAAwB;IACxBC,cAAc;IACdC,2BAA2B;AAC7B,EAAW;AAEX;;CAEC,GACD,OAAO,SAASC,mBAAmBC,OAAe;IAChD,OAAOA,WAAW;AACpB;AAEA;;CAEC,GACD,OAAO,SAASC,qBAAqBD,OAAe;IAClD,OAAOA,WAAW;AACpB;AAEA;;CAEC,GACD,OAAO,SAASE,oBAAoBF,OAAe;IACjD,OAAOA,UAAU;AACnB;AAEA;;CAEC,GACD,OAAO,SAASG,yBAAyBC,IAAY;IACnD,IAAIA,OAAO,IAAI;QACb,MAAM,IAAItB,MAAM;IAClB;IACA,IAAIsB,SAAS,IAAI;QACf,OAAO;IACT;IACA,MAAMC,OAAO,IAAKD,OAAO;IACzB,MAAME,MAAM,AAACF,CAAAA,SAAS,CAAA,IAAK;IAC3B,OAAOC,QAAQC;AACjB"}
|
package/dist/esm/nextEntry.js
CHANGED
|
@@ -4,12 +4,13 @@ import compact from 'lodash.compact';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import FileEntry from './FileEntry.js';
|
|
6
6
|
export default function nextEntry(iterator, callback) {
|
|
7
|
-
|
|
7
|
+
const internalIter = iterator._iterator;
|
|
8
|
+
if (!internalIter) {
|
|
8
9
|
callback(new Error('iterator missing'));
|
|
9
10
|
return;
|
|
10
11
|
}
|
|
11
12
|
let entry = null;
|
|
12
|
-
entry =
|
|
13
|
+
entry = internalIter.next();
|
|
13
14
|
const nextCallback = once((err, entry)=>{
|
|
14
15
|
// keep processing
|
|
15
16
|
if (entry) iterator.push(nextEntry);
|
|
@@ -53,28 +54,24 @@ export default function nextEntry(iterator, callback) {
|
|
|
53
54
|
{
|
|
54
55
|
// For symlinks, the file content IS the symlink target path
|
|
55
56
|
// Read the content to get the linkpath for SymbolicLinkEntry
|
|
56
|
-
const parser =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
stream.on('error', (streamErr)=>{
|
|
76
|
-
nextCallback(streamErr);
|
|
77
|
-
});
|
|
57
|
+
const parser = internalIter.getParser();
|
|
58
|
+
const stream = parser.getEntryStream(entry);
|
|
59
|
+
const chunks = [];
|
|
60
|
+
stream.on('data', (chunk)=>{
|
|
61
|
+
chunks.push(chunk);
|
|
62
|
+
});
|
|
63
|
+
stream.on('end', ()=>{
|
|
64
|
+
const linkpath = Buffer.concat(chunks).toString('utf8');
|
|
65
|
+
const linkAttributes = {
|
|
66
|
+
path: attributes.path,
|
|
67
|
+
mtime: attributes.mtime,
|
|
68
|
+
mode: attributes.mode,
|
|
69
|
+
linkpath: linkpath
|
|
70
|
+
};
|
|
71
|
+
nextCallback(null, new SymbolicLinkEntry(linkAttributes));
|
|
72
|
+
});
|
|
73
|
+
stream.on('error', (streamErr)=>{
|
|
74
|
+
nextCallback(streamErr);
|
|
78
75
|
});
|
|
79
76
|
return;
|
|
80
77
|
}
|
|
@@ -82,8 +79,9 @@ export default function nextEntry(iterator, callback) {
|
|
|
82
79
|
{
|
|
83
80
|
attributes.type = 'file';
|
|
84
81
|
attributes.size = entry.size;
|
|
85
|
-
const
|
|
86
|
-
|
|
82
|
+
const parser = internalIter.getParser();
|
|
83
|
+
const stream = parser.getEntryStream(entry);
|
|
84
|
+
return nextCallback(null, new FileEntry(attributes, stream, iterator.lock, entry._canStream));
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
return callback(new Error(`Unrecognized entry type: ${type}`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { type DirectoryAttributes, DirectoryEntry, type FileAttributes, type LinkAttributes, SymbolicLinkEntry } from 'extract-base-iterator';\nimport compact from 'lodash.compact';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type SevenZipIterator from './SevenZipIterator.ts';\nimport type { SevenZipEntry } from './sevenz/SevenZipParser.ts';\nimport type { Entry, EntryCallback } from './types.ts';\n\nexport type NextCallback = (error?: Error, entry?: Entry) => void;\n\n// Entry attributes object that gets mutated in switch - union of possible shapes\n// mtime is number for FileAttributes compatibility (timestamp in ms)\ntype EntryAttributesBuilder = {\n path: string;\n basename: string;\n mtime: number;\n mode: number;\n type?: 'file' | 'directory';\n size?: number;\n};\n\nexport default function nextEntry<_T>(iterator: SevenZipIterator, callback: EntryCallback): void {\n if (!
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { type DirectoryAttributes, DirectoryEntry, type FileAttributes, type LinkAttributes, SymbolicLinkEntry } from 'extract-base-iterator';\nimport compact from 'lodash.compact';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type SevenZipIterator from './SevenZipIterator.ts';\nimport type { SevenZipEntry, SevenZipParser } from './sevenz/SevenZipParser.ts';\nimport type { Entry, EntryCallback } from './types.ts';\n\nexport type NextCallback = (error?: Error, entry?: Entry) => void;\n\n/** @internal */\ninterface InternalIterator {\n next(): SevenZipEntry | null;\n getParser(): SevenZipParser;\n}\n\n// Entry attributes object that gets mutated in switch - union of possible shapes\n// mtime is number for FileAttributes compatibility (timestamp in ms)\ntype EntryAttributesBuilder = {\n path: string;\n basename: string;\n mtime: number;\n mode: number;\n type?: 'file' | 'directory';\n size?: number;\n};\n\nexport default function nextEntry<_T>(iterator: SevenZipIterator, callback: EntryCallback): void {\n const internalIter = iterator._iterator as InternalIterator | null;\n if (!internalIter) {\n callback(new Error('iterator missing'));\n return;\n }\n\n let entry: SevenZipEntry | null = null;\n entry = internalIter.next();\n\n const nextCallback = once((err?: Error, entry?: Entry) => {\n // keep processing\n if (entry) iterator.push(nextEntry);\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n }) as NextCallback;\n\n // done: signal iteration is complete (guard against stale lock)\n if (!iterator.lock || iterator.isDone() || !entry) return callback(null, { done: true, value: null });\n\n // Skip anti-files (these mark files to delete in delta archives)\n if (entry.isAntiFile) {\n iterator.push(nextEntry);\n return callback(null, null);\n }\n\n // Determine type from entry\n const type = entry.type;\n\n // Default modes (decimal values for Node 0.8 compatibility)\n // 0o755 = 493, 0o644 = 420\n const defaultMode = type === 'directory' ? 493 : 420;\n\n // Build attributes from 7z entry\n // mtime must be timestamp (number) for FileAttributes compatibility\n const mtimeDate = entry.mtime || new Date();\n const attributes: EntryAttributesBuilder = {\n path: compact(entry.path.split(path.sep)).join(path.sep),\n basename: entry.name,\n mtime: mtimeDate.getTime(),\n mode: entry.mode !== undefined ? entry.mode : defaultMode,\n };\n\n switch (type) {\n case 'directory':\n attributes.type = 'directory';\n return nextCallback(null, new DirectoryEntry(attributes as DirectoryAttributes));\n\n case 'link': {\n // For symlinks, the file content IS the symlink target path\n // Read the content to get the linkpath for SymbolicLinkEntry\n const parser = internalIter.getParser();\n const stream = parser.getEntryStream(entry);\n\n const chunks: Buffer[] = [];\n\n stream.on('data', (chunk: Buffer) => {\n chunks.push(chunk);\n });\n stream.on('end', () => {\n const linkpath = Buffer.concat(chunks).toString('utf8');\n\n const linkAttributes: LinkAttributes = {\n path: attributes.path,\n mtime: attributes.mtime,\n mode: attributes.mode,\n linkpath: linkpath,\n };\n\n nextCallback(null, new SymbolicLinkEntry(linkAttributes));\n });\n stream.on('error', (streamErr: Error) => {\n nextCallback(streamErr);\n });\n return;\n }\n\n case 'file': {\n attributes.type = 'file';\n attributes.size = entry.size;\n const parser = internalIter.getParser();\n\n const stream = parser.getEntryStream(entry);\n return nextCallback(null, new FileEntry(attributes as FileAttributes, stream, iterator.lock, entry._canStream));\n }\n }\n\n return callback(new Error(`Unrecognized entry type: ${type}`));\n}\n"],"names":["once","DirectoryEntry","SymbolicLinkEntry","compact","path","FileEntry","nextEntry","iterator","callback","internalIter","_iterator","Error","entry","next","nextCallback","err","push","done","value","lock","isDone","isAntiFile","type","defaultMode","mtimeDate","mtime","Date","attributes","split","sep","join","basename","name","getTime","mode","undefined","parser","getParser","stream","getEntryStream","chunks","on","chunk","linkpath","Buffer","concat","toString","linkAttributes","streamErr","size","_canStream"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAAmCC,cAAc,EAA4CC,iBAAiB,QAAQ,wBAAwB;AAC9I,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,UAAU,OAAO;AACxB,OAAOC,eAAe,iBAAiB;AAwBvC,eAAe,SAASC,UAAcC,QAA0B,EAAEC,QAAuB;IACvF,MAAMC,eAAeF,SAASG,SAAS;IACvC,IAAI,CAACD,cAAc;QACjBD,SAAS,IAAIG,MAAM;QACnB;IACF;IAEA,IAAIC,QAA8B;IAClCA,QAAQH,aAAaI,IAAI;IAEzB,MAAMC,eAAed,KAAK,CAACe,KAAaH;QACtC,kBAAkB;QAClB,IAAIA,OAAOL,SAASS,IAAI,CAACV;QACzBS,MAAMP,SAASO,OAAOP,SAAS,MAAMI,QAAQ;YAAEK,MAAM;YAAOC,OAAON;QAAM,IAAI;YAAEK,MAAM;YAAMC,OAAO;QAAK;IACzG;IAEA,gEAAgE;IAChE,IAAI,CAACX,SAASY,IAAI,IAAIZ,SAASa,MAAM,MAAM,CAACR,OAAO,OAAOJ,SAAS,MAAM;QAAES,MAAM;QAAMC,OAAO;IAAK;IAEnG,iEAAiE;IACjE,IAAIN,MAAMS,UAAU,EAAE;QACpBd,SAASS,IAAI,CAACV;QACd,OAAOE,SAAS,MAAM;IACxB;IAEA,4BAA4B;IAC5B,MAAMc,OAAOV,MAAMU,IAAI;IAEvB,4DAA4D;IAC5D,2BAA2B;IAC3B,MAAMC,cAAcD,SAAS,cAAc,MAAM;IAEjD,iCAAiC;IACjC,oEAAoE;IACp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AAEP,MAAMsC,UAAU;YAC/G;IACF;IAEA,OAAO1C,SAAS,IAAIG,MAAM,CAAC,yBAAyB,EAAEW,MAAM;AAC9D"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Provides a common interface for reading archive data from either
|
|
5
5
|
* a file descriptor or an in-memory buffer.
|
|
6
6
|
*/
|
|
7
|
+
import type Stream from 'stream';
|
|
7
8
|
/**
|
|
8
9
|
* Archive source abstraction - allows reading from file descriptor or buffer
|
|
9
10
|
*/
|
|
@@ -11,6 +12,11 @@ export interface ArchiveSource {
|
|
|
11
12
|
read(position: number, length: number): Buffer;
|
|
12
13
|
getSize(): number;
|
|
13
14
|
close(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Create a readable stream for a portion of the archive.
|
|
17
|
+
* Used for streaming decompression.
|
|
18
|
+
*/
|
|
19
|
+
createReadStream(offset: number, length: number): Stream.Readable;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Buffer-based archive source
|
|
@@ -23,6 +29,11 @@ export declare class BufferSource implements ArchiveSource {
|
|
|
23
29
|
read(position: number, length: number): Buffer;
|
|
24
30
|
getSize(): number;
|
|
25
31
|
close(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Create a readable stream for a portion of the buffer.
|
|
34
|
+
* Streams the data in chunks to avoid blocking.
|
|
35
|
+
*/
|
|
36
|
+
createReadStream(offset: number, length: number): Stream.Readable;
|
|
26
37
|
}
|
|
27
38
|
/**
|
|
28
39
|
* File descriptor based archive source
|
|
@@ -37,4 +48,9 @@ export declare class FileSource implements ArchiveSource {
|
|
|
37
48
|
read(position: number, length: number): Buffer;
|
|
38
49
|
getSize(): number;
|
|
39
50
|
close(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Create a readable stream for a portion of the file.
|
|
53
|
+
* Uses async fs.read() to avoid blocking the event loop.
|
|
54
|
+
*/
|
|
55
|
+
createReadStream(offset: number, length: number): Stream.Readable;
|
|
40
56
|
}
|
|
@@ -3,8 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides a common interface for reading archive data from either
|
|
5
5
|
* a file descriptor or an in-memory buffer.
|
|
6
|
-
*/ import { allocBuffer } from 'extract-base-iterator';
|
|
6
|
+
*/ import { allocBuffer, Readable } from 'extract-base-iterator';
|
|
7
7
|
import fs from 'fs';
|
|
8
|
+
// Helper to create a Readable stream compatible with Node 0.8
|
|
9
|
+
function createReadableStream(readFn) {
|
|
10
|
+
const stream = new Readable();
|
|
11
|
+
stream._read = function() {
|
|
12
|
+
readFn(this);
|
|
13
|
+
};
|
|
14
|
+
return stream;
|
|
15
|
+
}
|
|
8
16
|
/**
|
|
9
17
|
* Buffer-based archive source
|
|
10
18
|
*
|
|
@@ -19,6 +27,25 @@ import fs from 'fs';
|
|
|
19
27
|
close() {
|
|
20
28
|
// Nothing to close for buffer
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a readable stream for a portion of the buffer.
|
|
32
|
+
* Streams the data in chunks to avoid blocking.
|
|
33
|
+
*/ createReadStream(offset, length) {
|
|
34
|
+
const buffer = this.buffer;
|
|
35
|
+
const end = Math.min(offset + length, buffer.length);
|
|
36
|
+
let currentPos = offset;
|
|
37
|
+
const chunkSize = 65536; // 64KB chunks
|
|
38
|
+
return createReadableStream((stream)=>{
|
|
39
|
+
if (currentPos >= end) {
|
|
40
|
+
stream.push(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const toRead = Math.min(chunkSize, end - currentPos);
|
|
44
|
+
const chunk = buffer.slice(currentPos, currentPos + toRead);
|
|
45
|
+
currentPos += toRead;
|
|
46
|
+
stream.push(chunk);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
22
49
|
constructor(buffer){
|
|
23
50
|
this.buffer = buffer;
|
|
24
51
|
}
|
|
@@ -47,6 +74,48 @@ import fs from 'fs';
|
|
|
47
74
|
// Ignore close errors
|
|
48
75
|
}
|
|
49
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a readable stream for a portion of the file.
|
|
79
|
+
* Uses async fs.read() to avoid blocking the event loop.
|
|
80
|
+
*/ createReadStream(offset, length) {
|
|
81
|
+
const fd = this.fd;
|
|
82
|
+
let bytesRead = 0;
|
|
83
|
+
let reading = false;
|
|
84
|
+
let finished = false;
|
|
85
|
+
const chunkSize = 65536; // 64KB chunks
|
|
86
|
+
let _streamRef = null;
|
|
87
|
+
const stream = createReadableStream((s)=>{
|
|
88
|
+
_streamRef = s;
|
|
89
|
+
if (reading || finished) return; // Prevent re-entrant reads
|
|
90
|
+
const toRead = Math.min(chunkSize, length - bytesRead);
|
|
91
|
+
if (toRead <= 0) {
|
|
92
|
+
finished = true;
|
|
93
|
+
s.push(null);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
reading = true;
|
|
97
|
+
const buffer = allocBuffer(toRead);
|
|
98
|
+
const currentOffset = offset + bytesRead;
|
|
99
|
+
fs.read(fd, buffer, 0, toRead, currentOffset, (err, n)=>{
|
|
100
|
+
reading = false;
|
|
101
|
+
if (err) {
|
|
102
|
+
// Emit error for Node 0.8 compatibility (no destroy method)
|
|
103
|
+
s.emit('error', err);
|
|
104
|
+
finished = true;
|
|
105
|
+
s.push(null);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (n === 0) {
|
|
109
|
+
finished = true;
|
|
110
|
+
s.push(null);
|
|
111
|
+
} else {
|
|
112
|
+
bytesRead += n;
|
|
113
|
+
s.push(buffer.slice(0, n));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return stream;
|
|
118
|
+
}
|
|
50
119
|
constructor(fd, size){
|
|
51
120
|
this.fd = fd;
|
|
52
121
|
this.size = size;
|
|
@@ -1 +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;
|
|
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, Readable } from 'extract-base-iterator';\nimport fs from 'fs';\nimport type Stream from 'stream';\n\n// Helper to create a Readable stream compatible with Node 0.8\nfunction createReadableStream(readFn: (stream: Stream.Readable) => void): Stream.Readable {\n const stream = new Readable();\n stream._read = function () {\n readFn(this);\n };\n return stream;\n}\n\n/**\n * Archive source abstraction - allows reading from file descriptor or buffer\n */\nexport interface ArchiveSource {\n read(position: number, length: number): Buffer;\n getSize(): number;\n close(): void;\n /**\n * Create a readable stream for a portion of the archive.\n * Used for streaming decompression.\n */\n createReadStream(offset: number, length: number): Stream.Readable;\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 * Create a readable stream for a portion of the buffer.\n * Streams the data in chunks to avoid blocking.\n */\n createReadStream(offset: number, length: number): Stream.Readable {\n const buffer = this.buffer;\n const end = Math.min(offset + length, buffer.length);\n let currentPos = offset;\n const chunkSize = 65536; // 64KB chunks\n\n return createReadableStream((stream) => {\n if (currentPos >= end) {\n stream.push(null);\n return;\n }\n\n const toRead = Math.min(chunkSize, end - currentPos);\n const chunk = buffer.slice(currentPos, currentPos + toRead);\n currentPos += toRead;\n stream.push(chunk);\n });\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 /**\n * Create a readable stream for a portion of the file.\n * Uses async fs.read() to avoid blocking the event loop.\n */\n createReadStream(offset: number, length: number): Stream.Readable {\n const fd = this.fd;\n let bytesRead = 0;\n let reading = false;\n let finished = false;\n const chunkSize = 65536; // 64KB chunks\n let _streamRef: Stream.Readable | null = null;\n\n const stream = createReadableStream((s) => {\n _streamRef = s;\n if (reading || finished) return; // Prevent re-entrant reads\n\n const toRead = Math.min(chunkSize, length - bytesRead);\n if (toRead <= 0) {\n finished = true;\n s.push(null);\n return;\n }\n\n reading = true;\n const buffer = allocBuffer(toRead);\n const currentOffset = offset + bytesRead;\n\n fs.read(fd, buffer, 0, toRead, currentOffset, (err, n) => {\n reading = false;\n\n if (err) {\n // Emit error for Node 0.8 compatibility (no destroy method)\n s.emit('error', err);\n finished = true;\n s.push(null);\n return;\n }\n\n if (n === 0) {\n finished = true;\n s.push(null);\n } else {\n bytesRead += n;\n s.push(buffer.slice(0, n));\n }\n });\n });\n\n return stream;\n }\n}\n"],"names":["allocBuffer","Readable","fs","createReadableStream","readFn","stream","_read","BufferSource","read","position","length","buffer","slice","getSize","close","createReadStream","offset","end","Math","min","currentPos","chunkSize","push","toRead","chunk","FileSource","buf","bytesRead","readSync","fd","size","closeSync","_e","reading","finished","_streamRef","s","currentOffset","err","n","emit"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,WAAW,EAAEC,QAAQ,QAAQ,wBAAwB;AAC9D,OAAOC,QAAQ,KAAK;AAGpB,8DAA8D;AAC9D,SAASC,qBAAqBC,MAAyC;IACrE,MAAMC,SAAS,IAAIJ;IACnBI,OAAOC,KAAK,GAAG;QACbF,OAAO,IAAI;IACb;IACA,OAAOC;AACT;AAgBA;;;;CAIC,GACD,OAAO,MAAME;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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