7z-iterator 1.3.1 → 1.4.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.
Files changed (52) hide show
  1. package/dist/cjs/index.d.cts +3 -1
  2. package/dist/cjs/index.d.ts +3 -1
  3. package/dist/cjs/index.js +10 -0
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/lzma/index.d.cts +18 -0
  6. package/dist/cjs/lzma/index.d.ts +18 -0
  7. package/dist/cjs/lzma/index.js +20 -0
  8. package/dist/cjs/lzma/index.js.map +1 -1
  9. package/dist/cjs/lzma/stream/transforms.d.cts +8 -0
  10. package/dist/cjs/lzma/stream/transforms.d.ts +8 -0
  11. package/dist/cjs/lzma/stream/transforms.js +66 -6
  12. package/dist/cjs/lzma/stream/transforms.js.map +1 -1
  13. package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +37 -4
  14. package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +37 -4
  15. package/dist/cjs/lzma/sync/Lzma2Decoder.js +100 -4
  16. package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -1
  17. package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +18 -3
  18. package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +18 -3
  19. package/dist/cjs/lzma/sync/LzmaDecoder.js +146 -6
  20. package/dist/cjs/lzma/sync/LzmaDecoder.js.map +1 -1
  21. package/dist/cjs/lzma/types.d.cts +7 -0
  22. package/dist/cjs/lzma/types.d.ts +7 -0
  23. package/dist/cjs/lzma/types.js.map +1 -1
  24. package/dist/cjs/sevenz/codecs/Lzma.js.map +1 -1
  25. package/dist/cjs/sevenz/codecs/Lzma2.js.map +1 -1
  26. package/dist/cjs/xz/Decoder.d.cts +25 -0
  27. package/dist/cjs/xz/Decoder.d.ts +25 -0
  28. package/dist/cjs/xz/Decoder.js +194 -0
  29. package/dist/cjs/xz/Decoder.js.map +1 -0
  30. package/dist/esm/index.d.ts +3 -1
  31. package/dist/esm/index.js +2 -1
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/lzma/index.d.ts +18 -0
  34. package/dist/esm/lzma/index.js +29 -0
  35. package/dist/esm/lzma/index.js.map +1 -1
  36. package/dist/esm/lzma/stream/transforms.d.ts +8 -0
  37. package/dist/esm/lzma/stream/transforms.js +46 -7
  38. package/dist/esm/lzma/stream/transforms.js.map +1 -1
  39. package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +37 -4
  40. package/dist/esm/lzma/sync/Lzma2Decoder.js +102 -6
  41. package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -1
  42. package/dist/esm/lzma/sync/LzmaDecoder.d.ts +18 -3
  43. package/dist/esm/lzma/sync/LzmaDecoder.js +147 -7
  44. package/dist/esm/lzma/sync/LzmaDecoder.js.map +1 -1
  45. package/dist/esm/lzma/types.d.ts +7 -0
  46. package/dist/esm/lzma/types.js.map +1 -1
  47. package/dist/esm/sevenz/codecs/Lzma.js.map +1 -1
  48. package/dist/esm/sevenz/codecs/Lzma2.js.map +1 -1
  49. package/dist/esm/xz/Decoder.d.ts +25 -0
  50. package/dist/esm/xz/Decoder.js +185 -0
  51. package/dist/esm/xz/Decoder.js.map +1 -0
  52. package/package.json +8 -2
@@ -11,6 +11,96 @@ import { LzmaDecoder } from './LzmaDecoder.js';
11
11
  * Synchronous LZMA2 decoder
12
12
  */ export class Lzma2Decoder {
13
13
  /**
14
+ * Reset the dictionary (for stream boundaries)
15
+ */ resetDictionary() {
16
+ this.lzmaDecoder.resetDictionary();
17
+ }
18
+ /**
19
+ * Reset all probability models (for stream boundaries)
20
+ */ resetProbabilities() {
21
+ this.lzmaDecoder.resetProbabilities();
22
+ }
23
+ /**
24
+ * Set LZMA properties
25
+ */ setLcLpPb(lc, lp, pb) {
26
+ return this.lzmaDecoder.setLcLpPb(lc, lp, pb);
27
+ }
28
+ /**
29
+ * Feed uncompressed data to the dictionary (for subsequent LZMA chunks)
30
+ */ feedUncompressed(data) {
31
+ this.lzmaDecoder.feedUncompressed(data);
32
+ }
33
+ /**
34
+ * Decode raw LZMA data (used internally for LZMA2 chunks)
35
+ * @param input - LZMA compressed data
36
+ * @param offset - Input offset
37
+ * @param outSize - Expected output size
38
+ * @param solid - Use solid mode
39
+ * @returns Decompressed data
40
+ */ decodeLzmaData(input, offset, outSize, solid = false) {
41
+ return this.lzmaDecoder.decode(input, offset, outSize, solid);
42
+ }
43
+ /**
44
+ * Decode LZMA2 data with streaming output
45
+ * @param input - LZMA2 compressed data
46
+ * @returns Total number of bytes written to sink
47
+ */ decodeWithSink(input) {
48
+ let totalBytes = 0;
49
+ let offset = 0;
50
+ while(offset < input.length){
51
+ const result = parseLzma2ChunkHeader(input, offset);
52
+ if (!result.success) {
53
+ throw new Error('Truncated LZMA2 chunk header');
54
+ }
55
+ const chunk = result.chunk;
56
+ if (chunk.type === 'end') {
57
+ break;
58
+ }
59
+ // Validate we have enough data for the chunk
60
+ const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
61
+ if (offset + chunk.headerSize + dataSize > input.length) {
62
+ throw new Error(`Truncated LZMA2 ${chunk.type} data`);
63
+ }
64
+ // Handle dictionary reset
65
+ if (chunk.dictReset) {
66
+ this.lzmaDecoder.resetDictionary();
67
+ }
68
+ const dataOffset = offset + chunk.headerSize;
69
+ if (chunk.type === 'uncompressed') {
70
+ const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);
71
+ // Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it
72
+ this.lzmaDecoder.feedUncompressed(uncompData);
73
+ totalBytes += uncompData.length;
74
+ offset = dataOffset + chunk.uncompSize;
75
+ } else {
76
+ // LZMA compressed chunk
77
+ // Apply new properties if present
78
+ if (chunk.newProps) {
79
+ const { lc, lp, pb } = chunk.newProps;
80
+ if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {
81
+ throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);
82
+ }
83
+ this.propsSet = true;
84
+ }
85
+ if (!this.propsSet) {
86
+ throw new Error('LZMA chunk without properties');
87
+ }
88
+ // Reset probabilities if state reset
89
+ if (chunk.stateReset) {
90
+ this.lzmaDecoder.resetProbabilities();
91
+ }
92
+ // Determine solid mode
93
+ const useSolid = !chunk.stateReset || chunk.stateReset && !chunk.dictReset;
94
+ // Decode LZMA chunk directly to sink
95
+ totalBytes += this.lzmaDecoder.decodeWithSink(input, dataOffset, chunk.uncompSize, useSolid);
96
+ offset = dataOffset + chunk.compSize;
97
+ }
98
+ }
99
+ // Flush any remaining data in the OutWindow
100
+ this.lzmaDecoder.flushOutWindow();
101
+ return totalBytes;
102
+ }
103
+ /**
14
104
  * Decode LZMA2 data
15
105
  * @param input - LZMA2 compressed data
16
106
  * @param unpackSize - Expected output size (optional, for pre-allocation)
@@ -93,12 +183,12 @@ import { LzmaDecoder } from './LzmaDecoder.js';
93
183
  }
94
184
  return Buffer.concat(outputChunks);
95
185
  }
96
- constructor(properties){
186
+ constructor(properties, outputSink){
97
187
  if (!properties || properties.length < 1) {
98
188
  throw new Error('LZMA2 requires properties byte');
99
189
  }
100
190
  this.dictionarySize = parseLzma2DictionarySize(properties[0]);
101
- this.lzmaDecoder = new LzmaDecoder();
191
+ this.lzmaDecoder = new LzmaDecoder(outputSink);
102
192
  this.lzmaDecoder.setDictionarySize(this.dictionarySize);
103
193
  this.propsSet = false;
104
194
  }
@@ -107,9 +197,15 @@ import { LzmaDecoder } from './LzmaDecoder.js';
107
197
  * Decode LZMA2 data synchronously
108
198
  * @param input - LZMA2 compressed data
109
199
  * @param properties - 1-byte properties (dictionary size)
110
- * @param unpackSize - Expected output size (optional)
111
- * @returns Decompressed data
112
- */ export function decodeLzma2(input, properties, unpackSize) {
113
- const decoder = new Lzma2Decoder(properties);
200
+ * @param unpackSize - Expected output size (optional, autodetects if not provided)
201
+ * @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
202
+ * @returns Decompressed data (or bytes written if outputSink provided)
203
+ */ export function decodeLzma2(input, properties, unpackSize, outputSink) {
204
+ const decoder = new Lzma2Decoder(properties, outputSink);
205
+ if (outputSink) {
206
+ // Zero-copy mode: write to sink during decode
207
+ return decoder.decodeWithSink(input);
208
+ }
209
+ // Buffering mode: returns Buffer (zero-copy)
114
210
  return decoder.decode(input, unpackSize);
115
211
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/sync/Lzma2Decoder.ts"],"sourcesContent":["/**\n * Synchronous LZMA2 Decoder\n *\n * LZMA2 is a container format that wraps LZMA chunks with framing.\n * Decodes LZMA2 data from a buffer.\n */\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport { parseLzma2ChunkHeader } from '../Lzma2ChunkParser.ts';\nimport { parseLzma2DictionarySize } from '../types.ts';\nimport { LzmaDecoder } from './LzmaDecoder.ts';\n\n/**\n * Synchronous LZMA2 decoder\n */\nexport class Lzma2Decoder {\n private lzmaDecoder: LzmaDecoder;\n private dictionarySize: number;\n private propsSet: boolean;\n\n constructor(properties: Buffer | Uint8Array) {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n this.dictionarySize = parseLzma2DictionarySize(properties[0]);\n this.lzmaDecoder = new LzmaDecoder();\n this.lzmaDecoder.setDictionarySize(this.dictionarySize);\n this.propsSet = false;\n }\n\n /**\n * Decode LZMA2 data\n * @param input - LZMA2 compressed data\n * @param unpackSize - Expected output size (optional, for pre-allocation)\n * @returns Decompressed data\n */\n decode(input: Buffer, unpackSize?: number): Buffer {\n // Pre-allocate output buffer if size is known\n let outputBuffer: Buffer | null = null;\n let outputPos = 0;\n const outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n let offset = 0;\n\n while (offset < input.length) {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (!result.success) {\n throw new Error('Truncated LZMA2 chunk header');\n }\n\n const chunk = result.chunk;\n\n if (chunk.type === 'end') {\n break;\n }\n\n // Validate we have enough data for the chunk\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n if (offset + chunk.headerSize + dataSize > input.length) {\n throw new Error(`Truncated LZMA2 ${chunk.type} data`);\n }\n\n // Handle dictionary reset\n if (chunk.dictReset) {\n this.lzmaDecoder.resetDictionary();\n }\n\n const dataOffset = offset + chunk.headerSize;\n\n if (chunk.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);\n\n // Copy to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks.push(uncompData);\n }\n\n // Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it\n this.lzmaDecoder.feedUncompressed(uncompData);\n\n offset = dataOffset + chunk.uncompSize;\n } else {\n // LZMA compressed chunk\n\n // Apply new properties if present\n if (chunk.newProps) {\n const { lc, lp, pb } = chunk.newProps;\n if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n this.propsSet = true;\n }\n\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n // Reset probabilities if state reset\n if (chunk.stateReset) {\n this.lzmaDecoder.resetProbabilities();\n }\n\n // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)\n const useSolid = !chunk.stateReset || (chunk.stateReset && !chunk.dictReset);\n\n // Decode LZMA chunk\n const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);\n const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);\n\n // Copy to output\n if (outputBuffer) {\n decoded.copy(outputBuffer, outputPos);\n outputPos += decoded.length;\n } else {\n outputChunks.push(decoded);\n }\n\n offset = dataOffset + chunk.compSize;\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n }\n}\n\n/**\n * Decode LZMA2 data synchronously\n * @param input - LZMA2 compressed data\n * @param properties - 1-byte properties (dictionary size)\n * @param unpackSize - Expected output size (optional)\n * @returns Decompressed data\n */\nexport function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number): Buffer {\n const decoder = new Lzma2Decoder(properties);\n return decoder.decode(input, unpackSize);\n}\n"],"names":["allocBufferUnsafe","parseLzma2ChunkHeader","parseLzma2DictionarySize","LzmaDecoder","Lzma2Decoder","decode","input","unpackSize","outputBuffer","outputPos","outputChunks","offset","length","result","success","Error","chunk","type","dataSize","uncompSize","compSize","headerSize","dictReset","lzmaDecoder","resetDictionary","dataOffset","uncompData","slice","copy","push","feedUncompressed","newProps","lc","lp","pb","setLcLpPb","propsSet","stateReset","resetProbabilities","useSolid","chunkData","decoded","Buffer","concat","properties","dictionarySize","setDictionarySize","decodeLzma2","decoder"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,wBAAwB,QAAQ,cAAc;AACvD,SAASC,WAAW,QAAQ,mBAAmB;AAE/C;;CAEC,GACD,OAAO,MAAMC;IAgBX;;;;;GAKC,GACDC,OAAOC,KAAa,EAAEC,UAAmB,EAAU;QACjD,8CAA8C;QAC9C,IAAIC,eAA8B;QAClC,IAAIC,YAAY;QAChB,MAAMC,eAAyB,EAAE;QAEjC,IAAIH,cAAcA,aAAa,GAAG;YAChCC,eAAeR,kBAAkBO;QACnC;QAEA,IAAII,SAAS;QAEb,MAAOA,SAASL,MAAMM,MAAM,CAAE;YAC5B,MAAMC,SAASZ,sBAAsBK,OAAOK;YAE5C,IAAI,CAACE,OAAOC,OAAO,EAAE;gBACnB,MAAM,IAAIC,MAAM;YAClB;YAEA,MAAMC,QAAQH,OAAOG,KAAK;YAE1B,IAAIA,MA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C,OAAOC;AAC/B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/sync/Lzma2Decoder.ts"],"sourcesContent":["/**\n * Synchronous LZMA2 Decoder\n *\n * LZMA2 is a container format that wraps LZMA chunks with framing.\n * Decodes LZMA2 data from a buffer.\n */\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport { parseLzma2ChunkHeader } from '../Lzma2ChunkParser.ts';\nimport { type OutputSink, parseLzma2DictionarySize } from '../types.ts';\nimport { LzmaDecoder } from './LzmaDecoder.ts';\n\n/**\n * Synchronous LZMA2 decoder\n */\nexport class Lzma2Decoder {\n private lzmaDecoder: LzmaDecoder;\n private dictionarySize: number;\n private propsSet: boolean;\n\n constructor(properties: Buffer | Uint8Array, outputSink?: OutputSink) {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n this.dictionarySize = parseLzma2DictionarySize(properties[0]);\n this.lzmaDecoder = new LzmaDecoder(outputSink);\n this.lzmaDecoder.setDictionarySize(this.dictionarySize);\n this.propsSet = false;\n }\n\n /**\n * Reset the dictionary (for stream boundaries)\n */\n resetDictionary(): void {\n this.lzmaDecoder.resetDictionary();\n }\n\n /**\n * Reset all probability models (for stream boundaries)\n */\n resetProbabilities(): void {\n this.lzmaDecoder.resetProbabilities();\n }\n\n /**\n * Set LZMA properties\n */\n setLcLpPb(lc: number, lp: number, pb: number): boolean {\n return this.lzmaDecoder.setLcLpPb(lc, lp, pb);\n }\n\n /**\n * Feed uncompressed data to the dictionary (for subsequent LZMA chunks)\n */\n feedUncompressed(data: Buffer): void {\n this.lzmaDecoder.feedUncompressed(data);\n }\n\n /**\n * Decode raw LZMA data (used internally for LZMA2 chunks)\n * @param input - LZMA compressed data\n * @param offset - Input offset\n * @param outSize - Expected output size\n * @param solid - Use solid mode\n * @returns Decompressed data\n */\n decodeLzmaData(input: Buffer, offset: number, outSize: number, solid = false): Buffer {\n return this.lzmaDecoder.decode(input, offset, outSize, solid);\n }\n\n /**\n * Decode LZMA2 data with streaming output\n * @param input - LZMA2 compressed data\n * @returns Total number of bytes written to sink\n */\n decodeWithSink(input: Buffer): number {\n let totalBytes = 0;\n let offset = 0;\n\n while (offset < input.length) {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (!result.success) {\n throw new Error('Truncated LZMA2 chunk header');\n }\n\n const chunk = result.chunk;\n\n if (chunk.type === 'end') {\n break;\n }\n\n // Validate we have enough data for the chunk\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n if (offset + chunk.headerSize + dataSize > input.length) {\n throw new Error(`Truncated LZMA2 ${chunk.type} data`);\n }\n\n // Handle dictionary reset\n if (chunk.dictReset) {\n this.lzmaDecoder.resetDictionary();\n }\n\n const dataOffset = offset + chunk.headerSize;\n\n if (chunk.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);\n\n // Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it\n this.lzmaDecoder.feedUncompressed(uncompData);\n\n totalBytes += uncompData.length;\n offset = dataOffset + chunk.uncompSize;\n } else {\n // LZMA compressed chunk\n\n // Apply new properties if present\n if (chunk.newProps) {\n const { lc, lp, pb } = chunk.newProps;\n if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n this.propsSet = true;\n }\n\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n // Reset probabilities if state reset\n if (chunk.stateReset) {\n this.lzmaDecoder.resetProbabilities();\n }\n\n // Determine solid mode\n const useSolid = !chunk.stateReset || (chunk.stateReset && !chunk.dictReset);\n\n // Decode LZMA chunk directly to sink\n totalBytes += this.lzmaDecoder.decodeWithSink(input, dataOffset, chunk.uncompSize, useSolid);\n\n offset = dataOffset + chunk.compSize;\n }\n }\n\n // Flush any remaining data in the OutWindow\n this.lzmaDecoder.flushOutWindow();\n\n return totalBytes;\n }\n\n /**\n * Decode LZMA2 data\n * @param input - LZMA2 compressed data\n * @param unpackSize - Expected output size (optional, for pre-allocation)\n * @returns Decompressed data\n */\n decode(input: Buffer, unpackSize?: number): Buffer {\n // Pre-allocate output buffer if size is known\n let outputBuffer: Buffer | null = null;\n let outputPos = 0;\n const outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n let offset = 0;\n\n while (offset < input.length) {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (!result.success) {\n throw new Error('Truncated LZMA2 chunk header');\n }\n\n const chunk = result.chunk;\n\n if (chunk.type === 'end') {\n break;\n }\n\n // Validate we have enough data for the chunk\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n if (offset + chunk.headerSize + dataSize > input.length) {\n throw new Error(`Truncated LZMA2 ${chunk.type} data`);\n }\n\n // Handle dictionary reset\n if (chunk.dictReset) {\n this.lzmaDecoder.resetDictionary();\n }\n\n const dataOffset = offset + chunk.headerSize;\n\n if (chunk.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);\n\n // Copy to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks.push(uncompData);\n }\n\n // Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it\n this.lzmaDecoder.feedUncompressed(uncompData);\n\n offset = dataOffset + chunk.uncompSize;\n } else {\n // LZMA compressed chunk\n\n // Apply new properties if present\n if (chunk.newProps) {\n const { lc, lp, pb } = chunk.newProps;\n if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n this.propsSet = true;\n }\n\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n // Reset probabilities if state reset\n if (chunk.stateReset) {\n this.lzmaDecoder.resetProbabilities();\n }\n\n // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)\n const useSolid = !chunk.stateReset || (chunk.stateReset && !chunk.dictReset);\n\n // Decode LZMA chunk\n const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);\n const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);\n\n // Copy to output\n if (outputBuffer) {\n decoded.copy(outputBuffer, outputPos);\n outputPos += decoded.length;\n } else {\n outputChunks.push(decoded);\n }\n\n offset = dataOffset + chunk.compSize;\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n }\n}\n\n/**\n * Decode LZMA2 data synchronously\n * @param input - LZMA2 compressed data\n * @param properties - 1-byte properties (dictionary size)\n * @param unpackSize - Expected output size (optional, autodetects if not provided)\n * @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)\n * @returns Decompressed data (or bytes written if outputSink provided)\n */\nexport function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?: OutputSink): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink);\n if (outputSink) {\n // Zero-copy mode: write to sink during decode\n return decoder.decodeWithSink(input);\n }\n // Buffering mode: returns Buffer (zero-copy)\n return decoder.decode(input, unpackSize);\n}\n"],"names":["allocBufferUnsafe","parseLzma2ChunkHeader","parseLzma2DictionarySize","LzmaDecoder","Lzma2Decoder","resetDictionary","lzmaDecoder","resetProbabilities","setLcLpPb","lc","lp","pb","feedUncompressed","data","decodeLzmaData","input","offset","outSize","solid","decode","decodeWithSink","totalBytes","length","result","success","Error","chunk","type","dataSize","uncompSize","compSize","headerSize","dictReset","dataOffset","uncompData","slice","newProps","propsSet","stateReset","useSolid","flushOutWindow","unpackSize","outputBuffer","outputPos","outputChunks","copy","push","chunkData","decoded","Buffer","concat","properties","outputSink","dictionarySize","setDictionarySize","decodeLzma2","decoder"],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,aAAaD;QAC9E;QACA,OAAOO,OAAOC,MAAM,CAACN;IACvB;IA3OA,YAAYO,UAA+B,EAAEC,UAAuB,CAAE;QACpE,IAAI,CAACD,cAAcA,WAAW7B,MAAM,GAAG,GAAG;YACxC,MAAM,IAAIG,MAAM;QAClB;QAEA,IAAI,CAAC4B,cAAc,GAAGnD,yBAAyBiD,UAAU,CAAC,EAAE;QAC5D,IAAI,CAAC7C,WAAW,GAAG,IAAIH,YAAYiD;QACnC,IAAI,CAAC9C,WAAW,CAACgD,iBAAiB,CAAC,IAAI,CAACD,cAAc;QACtD,IAAI,CAAChB,QAAQ,GAAG;IAClB;AAmOF;AAEA;;;;;;;CAOC,GACD,OAAO,SAASkB,YAAYxC,KAAa,EAAEoC,UAA+B,EAAEV,UAAmB,EAAEW,UAAuB;IACtH,MAAMI,UAAU,IAAIpD,aAAa+C,YAAYC;IAC7C,IAAIA,YAAY;QACd,8CAA8C;QAC9C,OAAOI,QAAQpC,cAAc,CAACL;IAChC;IACA,6CAA6C;IAC7C,OAAOyC,QAAQrC,MAAM,CAACJ,OAAO0B;AAC/B"}
@@ -4,6 +4,7 @@
4
4
  * Decodes LZMA1 compressed data from a buffer.
5
5
  * All operations are synchronous.
6
6
  */
7
+ import { type OutputSink } from '../types.js';
7
8
  /**
8
9
  * Synchronous LZMA1 decoder
9
10
  */
@@ -32,7 +33,7 @@ export declare class LzmaDecoder {
32
33
  private rep3;
33
34
  private prevByte;
34
35
  private totalPos;
35
- constructor();
36
+ constructor(outputSink?: OutputSink);
36
37
  /**
37
38
  * Set dictionary size
38
39
  */
@@ -62,6 +63,19 @@ export declare class LzmaDecoder {
62
63
  * This updates the sliding window so subsequent LZMA chunks can reference this data.
63
64
  */
64
65
  feedUncompressed(data: Buffer): void;
66
+ /**
67
+ * Flush any remaining data in the OutWindow to the sink
68
+ */
69
+ flushOutWindow(): void;
70
+ /**
71
+ * Decode LZMA data with streaming output (no buffer accumulation)
72
+ * @param input - Compressed input buffer
73
+ * @param inputOffset - Offset into input buffer
74
+ * @param outSize - Expected output size
75
+ * @param solid - If true, preserve state from previous decode
76
+ * @returns Number of bytes written to sink
77
+ */
78
+ decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
65
79
  /**
66
80
  * Decode LZMA data
67
81
  * @param input - Compressed input buffer
@@ -77,6 +91,7 @@ export declare class LzmaDecoder {
77
91
  * @param input - Compressed data (without 5-byte properties header)
78
92
  * @param properties - 5-byte LZMA properties
79
93
  * @param outSize - Expected output size
80
- * @returns Decompressed data
94
+ * @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
95
+ * @returns Decompressed data (or bytes written if outputSink provided)
81
96
  */
82
- export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number): Buffer;
97
+ export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?: OutputSink): Buffer | number;
@@ -118,16 +118,31 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
118
118
  }
119
119
  this.windowSize = windowSize;
120
120
  this.pos = 0;
121
+ this.streamPos = 0;
121
122
  }
122
123
  init(solid) {
123
124
  if (!solid) {
124
125
  this.pos = 0;
126
+ this.streamPos = 0;
125
127
  }
126
128
  }
127
129
  putByte(b) {
128
130
  this.buffer[this.pos++] = b;
129
131
  if (this.pos >= this.windowSize) {
130
- this.pos = 0;
132
+ if (this.sink) {
133
+ this.flush();
134
+ this.pos = 0;
135
+ } else {
136
+ this.pos = 0;
137
+ }
138
+ }
139
+ }
140
+ flush() {
141
+ const size = this.pos - this.streamPos;
142
+ if (size > 0 && this.sink) {
143
+ const chunk = this.buffer.slice(this.streamPos, this.streamPos + size);
144
+ this.sink.write(chunk);
145
+ this.streamPos = this.pos;
131
146
  }
132
147
  }
133
148
  getByte(distance) {
@@ -162,10 +177,12 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
162
177
  this.buffer.copy(output, outputOffset, srcPos, srcPos + count);
163
178
  }
164
179
  }
165
- constructor(){
180
+ constructor(sink){
166
181
  this.buffer = allocBufferUnsafe(0); // Replaced by create() before use
167
182
  this.windowSize = 0;
168
183
  this.pos = 0;
184
+ this.sink = sink;
185
+ this.streamPos = 0;
169
186
  }
170
187
  };
171
188
  /**
@@ -249,6 +266,121 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
249
266
  }
250
267
  }
251
268
  /**
269
+ * Flush any remaining data in the OutWindow to the sink
270
+ */ flushOutWindow() {
271
+ this.outWindow.flush();
272
+ }
273
+ /**
274
+ * Decode LZMA data with streaming output (no buffer accumulation)
275
+ * @param input - Compressed input buffer
276
+ * @param inputOffset - Offset into input buffer
277
+ * @param outSize - Expected output size
278
+ * @param solid - If true, preserve state from previous decode
279
+ * @returns Number of bytes written to sink
280
+ */ decodeWithSink(input, inputOffset, outSize, solid = false) {
281
+ this.rangeDecoder.setInput(input, inputOffset);
282
+ if (!solid) {
283
+ this.outWindow.init(false);
284
+ this.initProbabilities();
285
+ this.state = 0;
286
+ this.rep0 = 0;
287
+ this.rep1 = 0;
288
+ this.rep2 = 0;
289
+ this.rep3 = 0;
290
+ this.prevByte = 0;
291
+ this.totalPos = 0;
292
+ } else {
293
+ this.outWindow.init(true);
294
+ }
295
+ let outPos = 0;
296
+ let cumPos = this.totalPos;
297
+ while(outPos < outSize){
298
+ const posState = cumPos & this.posStateMask;
299
+ if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {
300
+ // Literal
301
+ const decoder2 = this.literalDecoder.getDecoder(cumPos, this.prevByte);
302
+ if (!stateIsCharState(this.state)) {
303
+ this.prevByte = decoder2.decodeWithMatchByte(this.rangeDecoder, this.outWindow.getByte(this.rep0));
304
+ } else {
305
+ this.prevByte = decoder2.decodeNormal(this.rangeDecoder);
306
+ }
307
+ this.outWindow.putByte(this.prevByte);
308
+ outPos++;
309
+ this.state = stateUpdateChar(this.state);
310
+ cumPos++;
311
+ } else {
312
+ // Match or rep
313
+ let len;
314
+ if (this.rangeDecoder.decodeBit(this.isRepDecoders, this.state) === 1) {
315
+ // Rep match
316
+ len = 0;
317
+ if (this.rangeDecoder.decodeBit(this.isRepG0Decoders, this.state) === 0) {
318
+ if (this.rangeDecoder.decodeBit(this.isRep0LongDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {
319
+ this.state = stateUpdateShortRep(this.state);
320
+ len = 1;
321
+ }
322
+ } else {
323
+ let distance;
324
+ if (this.rangeDecoder.decodeBit(this.isRepG1Decoders, this.state) === 0) {
325
+ distance = this.rep1;
326
+ } else {
327
+ if (this.rangeDecoder.decodeBit(this.isRepG2Decoders, this.state) === 0) {
328
+ distance = this.rep2;
329
+ } else {
330
+ distance = this.rep3;
331
+ this.rep3 = this.rep2;
332
+ }
333
+ this.rep2 = this.rep1;
334
+ }
335
+ this.rep1 = this.rep0;
336
+ this.rep0 = distance;
337
+ }
338
+ if (len === 0) {
339
+ len = kMatchMinLen + this.repLenDecoder.decode(this.rangeDecoder, posState);
340
+ this.state = stateUpdateRep(this.state);
341
+ }
342
+ } else {
343
+ // Normal match
344
+ this.rep3 = this.rep2;
345
+ this.rep2 = this.rep1;
346
+ this.rep1 = this.rep0;
347
+ len = kMatchMinLen + this.lenDecoder.decode(this.rangeDecoder, posState);
348
+ this.state = stateUpdateMatch(this.state);
349
+ const posSlot = this.posSlotDecoder[getLenToPosState(len)].decode(this.rangeDecoder);
350
+ if (posSlot >= kStartPosModelIndex) {
351
+ const numDirectBits = (posSlot >> 1) - 1;
352
+ this.rep0 = (2 | posSlot & 1) << numDirectBits;
353
+ if (posSlot < kEndPosModelIndex) {
354
+ this.rep0 += reverseDecodeFromArray(this.posDecoders, this.rep0 - posSlot - 1, this.rangeDecoder, numDirectBits);
355
+ } else {
356
+ this.rep0 += this.rangeDecoder.decodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;
357
+ this.rep0 += this.posAlignDecoder.reverseDecode(this.rangeDecoder);
358
+ if (this.rep0 < 0) {
359
+ if (this.rep0 === -1) break;
360
+ throw new Error('LZMA: Invalid distance');
361
+ }
362
+ }
363
+ } else {
364
+ this.rep0 = posSlot;
365
+ }
366
+ }
367
+ if (this.rep0 >= cumPos || this.rep0 >= this.dictionarySizeCheck) {
368
+ throw new Error('LZMA: Invalid distance');
369
+ }
370
+ // Copy match bytes
371
+ for(let i = 0; i < len; i++){
372
+ const b = this.outWindow.getByte(this.rep0);
373
+ this.outWindow.putByte(b);
374
+ outPos++;
375
+ }
376
+ cumPos += len;
377
+ this.prevByte = this.outWindow.getByte(0);
378
+ }
379
+ }
380
+ this.totalPos = cumPos;
381
+ return outPos;
382
+ }
383
+ /**
252
384
  * Decode LZMA data
253
385
  * @param input - Compressed input buffer
254
386
  * @param inputOffset - Offset into input buffer
@@ -360,8 +492,8 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
360
492
  this.totalPos = cumPos;
361
493
  return output;
362
494
  }
363
- constructor(){
364
- this.outWindow = new OutWindow();
495
+ constructor(outputSink){
496
+ this.outWindow = new OutWindow(outputSink);
365
497
  this.rangeDecoder = new RangeDecoder();
366
498
  this.isMatchDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);
367
499
  this.isRepDecoders = initBitModels(null, kNumStates);
@@ -395,9 +527,17 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
395
527
  * @param input - Compressed data (without 5-byte properties header)
396
528
  * @param properties - 5-byte LZMA properties
397
529
  * @param outSize - Expected output size
398
- * @returns Decompressed data
399
- */ export function decodeLzma(input, properties, outSize) {
400
- const decoder = new LzmaDecoder();
530
+ * @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
531
+ * @returns Decompressed data (or bytes written if outputSink provided)
532
+ */ export function decodeLzma(input, properties, outSize, outputSink) {
533
+ const decoder = new LzmaDecoder(outputSink);
401
534
  decoder.setDecoderProperties(properties);
535
+ if (outputSink) {
536
+ // Zero-copy mode: write to sink during decode
537
+ const bytesWritten = decoder.decodeWithSink(input, 0, outSize, false);
538
+ decoder.flushOutWindow();
539
+ return bytesWritten;
540
+ }
541
+ // Buffering mode: pre-allocated buffer, direct writes (zero-copy)
402
542
  return decoder.decode(input, 0, outSize, false);
403
543
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/sync/LzmaDecoder.ts"],"sourcesContent":["/**\n * Synchronous LZMA1 Decoder\n *\n * Decodes LZMA1 compressed data from a buffer.\n * All operations are synchronous.\n */\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport {\n getLenToPosState,\n initBitModels,\n kEndPosModelIndex,\n kMatchMinLen,\n kNumAlignBits,\n kNumFullDistances,\n kNumLenToPosStates,\n kNumLitContextBitsMax,\n kNumPosSlotBits,\n kNumPosStatesBitsMax,\n kNumStates,\n kStartPosModelIndex,\n parseProperties,\n stateIsCharState,\n stateUpdateChar,\n stateUpdateMatch,\n stateUpdateRep,\n stateUpdateShortRep,\n} from '../types.ts';\nimport { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDecoder.ts';\n\n/**\n * Length decoder for match/rep lengths\n */\nclass LenDecoder {\n private choice: Uint16Array;\n private lowCoder: BitTreeDecoder[];\n private midCoder: BitTreeDecoder[];\n private highCoder: BitTreeDecoder;\n private numPosStates: number;\n\n constructor() {\n this.choice = initBitModels(null, 2);\n this.lowCoder = [];\n this.midCoder = [];\n this.highCoder = new BitTreeDecoder(8);\n this.numPosStates = 0;\n }\n\n create(numPosStates: number): void {\n for (; this.numPosStates < numPosStates; this.numPosStates++) {\n this.lowCoder[this.numPosStates] = new BitTreeDecoder(3);\n this.midCoder[this.numPosStates] = new BitTreeDecoder(3);\n }\n }\n\n init(): void {\n initBitModels(this.choice);\n for (let i = this.numPosStates - 1; i >= 0; i--) {\n this.lowCoder[i].init();\n this.midCoder[i].init();\n }\n this.highCoder.init();\n }\n\n decode(rangeDecoder: RangeDecoder, posState: number): number {\n if (rangeDecoder.decodeBit(this.choice, 0) === 0) {\n return this.lowCoder[posState].decode(rangeDecoder);\n }\n if (rangeDecoder.decodeBit(this.choice, 1) === 0) {\n return 8 + this.midCoder[posState].decode(rangeDecoder);\n }\n return 16 + this.highCoder.decode(rangeDecoder);\n }\n}\n\n/**\n * Single literal decoder (decodes one byte)\n */\nclass LiteralDecoder2 {\n private decoders: Uint16Array;\n\n constructor() {\n this.decoders = initBitModels(null, 0x300);\n }\n\n init(): void {\n initBitModels(this.decoders);\n }\n\n decodeNormal(rangeDecoder: RangeDecoder): number {\n let symbol = 1;\n do {\n symbol = (symbol << 1) | rangeDecoder.decodeBit(this.decoders, symbol);\n } while (symbol < 0x100);\n return symbol & 0xff;\n }\n\n decodeWithMatchByte(rangeDecoder: RangeDecoder, matchByte: number): number {\n let symbol = 1;\n do {\n const matchBit = (matchByte >> 7) & 1;\n matchByte <<= 1;\n const bit = rangeDecoder.decodeBit(this.decoders, ((1 + matchBit) << 8) + symbol);\n symbol = (symbol << 1) | bit;\n if (matchBit !== bit) {\n while (symbol < 0x100) {\n symbol = (symbol << 1) | rangeDecoder.decodeBit(this.decoders, symbol);\n }\n break;\n }\n } while (symbol < 0x100);\n return symbol & 0xff;\n }\n}\n\n/**\n * Literal decoder (array of single decoders)\n */\nclass LiteralDecoder {\n private numPosBits: number;\n private numPrevBits: number;\n private posMask: number;\n private coders: (LiteralDecoder2 | undefined)[];\n\n constructor() {\n this.numPosBits = 0;\n this.numPrevBits = 0;\n this.posMask = 0;\n this.coders = [];\n }\n\n create(numPosBits: number, numPrevBits: number): void {\n if (this.coders.length > 0 && this.numPrevBits === numPrevBits && this.numPosBits === numPosBits) {\n return;\n }\n this.numPosBits = numPosBits;\n this.posMask = (1 << numPosBits) - 1;\n this.numPrevBits = numPrevBits;\n this.coders = [];\n }\n\n init(): void {\n for (let i = 0; i < this.coders.length; i++) {\n if (this.coders[i]) {\n this.coders[i]?.init();\n }\n }\n }\n\n getDecoder(pos: number, prevByte: number): LiteralDecoder2 {\n const index = ((pos & this.posMask) << this.numPrevBits) + ((prevByte & 0xff) >>> (8 - this.numPrevBits));\n let decoder = this.coders[index];\n if (!decoder) {\n decoder = new LiteralDecoder2();\n this.coders[index] = decoder;\n }\n return decoder;\n }\n}\n\n/**\n * Output window (sliding dictionary)\n */\nclass OutWindow {\n private buffer: Buffer;\n private windowSize: number;\n private pos: number;\n\n constructor() {\n this.buffer = allocBufferUnsafe(0); // Replaced by create() before use\n this.windowSize = 0;\n this.pos = 0;\n }\n\n create(windowSize: number): void {\n if (!this.buffer || this.windowSize !== windowSize) {\n this.buffer = allocBufferUnsafe(windowSize);\n }\n this.windowSize = windowSize;\n this.pos = 0;\n }\n\n init(solid: boolean): void {\n if (!solid) {\n this.pos = 0;\n }\n }\n\n putByte(b: number): void {\n this.buffer[this.pos++] = b;\n if (this.pos >= this.windowSize) {\n this.pos = 0;\n }\n }\n\n getByte(distance: number): number {\n let pos = this.pos - distance - 1;\n if (pos < 0) {\n pos += this.windowSize;\n }\n return this.buffer[pos];\n }\n\n copyBlock(distance: number, len: number): void {\n let pos = this.pos - distance - 1;\n if (pos < 0) {\n pos += this.windowSize;\n }\n for (let i = 0; i < len; i++) {\n if (pos >= this.windowSize) {\n pos = 0;\n }\n this.putByte(this.buffer[pos++]);\n }\n }\n\n /**\n * Copy decoded data to output buffer\n */\n copyTo(output: Buffer, outputOffset: number, count: number): void {\n const srcPos = this.pos - count;\n if (srcPos < 0) {\n // Wrap around case - data spans end and beginning of buffer\n const firstPart = -srcPos;\n this.buffer.copy(output, outputOffset, this.windowSize + srcPos, this.windowSize);\n this.buffer.copy(output, outputOffset + firstPart, 0, count - firstPart);\n } else {\n this.buffer.copy(output, outputOffset, srcPos, srcPos + count);\n }\n }\n}\n\n/**\n * Synchronous LZMA1 decoder\n */\nexport class LzmaDecoder {\n private outWindow: OutWindow;\n private rangeDecoder: RangeDecoder;\n\n // Probability models\n private isMatchDecoders: Uint16Array;\n private isRepDecoders: Uint16Array;\n private isRepG0Decoders: Uint16Array;\n private isRepG1Decoders: Uint16Array;\n private isRepG2Decoders: Uint16Array;\n private isRep0LongDecoders: Uint16Array;\n private posSlotDecoder: BitTreeDecoder[];\n private posDecoders: Uint16Array;\n private posAlignDecoder: BitTreeDecoder;\n private lenDecoder: LenDecoder;\n private repLenDecoder: LenDecoder;\n private literalDecoder: LiteralDecoder;\n\n // Properties\n private dictionarySize: number;\n private dictionarySizeCheck: number;\n private posStateMask: number;\n\n // State (preserved across solid calls)\n private state: number;\n private rep0: number;\n private rep1: number;\n private rep2: number;\n private rep3: number;\n private prevByte: number;\n private totalPos: number;\n\n constructor() {\n this.outWindow = new OutWindow();\n this.rangeDecoder = new RangeDecoder();\n\n this.isMatchDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);\n this.isRepDecoders = initBitModels(null, kNumStates);\n this.isRepG0Decoders = initBitModels(null, kNumStates);\n this.isRepG1Decoders = initBitModels(null, kNumStates);\n this.isRepG2Decoders = initBitModels(null, kNumStates);\n this.isRep0LongDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);\n this.posSlotDecoder = [];\n this.posDecoders = initBitModels(null, kNumFullDistances - kEndPosModelIndex);\n this.posAlignDecoder = new BitTreeDecoder(kNumAlignBits);\n this.lenDecoder = new LenDecoder();\n this.repLenDecoder = new LenDecoder();\n this.literalDecoder = new LiteralDecoder();\n\n for (let i = 0; i < kNumLenToPosStates; i++) {\n this.posSlotDecoder[i] = new BitTreeDecoder(kNumPosSlotBits);\n }\n\n this.dictionarySize = -1;\n this.dictionarySizeCheck = -1;\n this.posStateMask = 0;\n\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n this.prevByte = 0;\n this.totalPos = 0;\n }\n\n /**\n * Set dictionary size\n */\n setDictionarySize(dictionarySize: number): boolean {\n if (dictionarySize < 0) return false;\n if (this.dictionarySize !== dictionarySize) {\n this.dictionarySize = dictionarySize;\n this.dictionarySizeCheck = Math.max(dictionarySize, 1);\n this.outWindow.create(Math.max(this.dictionarySizeCheck, 1 << 12));\n }\n return true;\n }\n\n /**\n * Set lc, lp, pb properties\n */\n setLcLpPb(lc: number, lp: number, pb: number): boolean {\n if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {\n return false;\n }\n const numPosStates = 1 << pb;\n this.literalDecoder.create(lp, lc);\n this.lenDecoder.create(numPosStates);\n this.repLenDecoder.create(numPosStates);\n this.posStateMask = numPosStates - 1;\n return true;\n }\n\n /**\n * Set decoder properties from 5-byte buffer\n */\n setDecoderProperties(properties: Buffer | Uint8Array): boolean {\n const props = parseProperties(properties);\n if (!this.setLcLpPb(props.lc, props.lp, props.pb)) return false;\n return this.setDictionarySize(props.dictionarySize);\n }\n\n /**\n * Initialize probability tables\n */\n private initProbabilities(): void {\n initBitModels(this.isMatchDecoders);\n initBitModels(this.isRepDecoders);\n initBitModels(this.isRepG0Decoders);\n initBitModels(this.isRepG1Decoders);\n initBitModels(this.isRepG2Decoders);\n initBitModels(this.isRep0LongDecoders);\n initBitModels(this.posDecoders);\n this.literalDecoder.init();\n for (let i = kNumLenToPosStates - 1; i >= 0; i--) {\n this.posSlotDecoder[i].init();\n }\n this.lenDecoder.init();\n this.repLenDecoder.init();\n this.posAlignDecoder.init();\n }\n\n /**\n * Reset probabilities only (for LZMA2 state reset)\n */\n resetProbabilities(): void {\n this.initProbabilities();\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n }\n\n /**\n * Reset dictionary position (for LZMA2 dictionary reset)\n */\n resetDictionary(): void {\n this.outWindow.init(false);\n this.totalPos = 0;\n }\n\n /**\n * Feed uncompressed data into the dictionary (for LZMA2 uncompressed chunks)\n * This updates the sliding window so subsequent LZMA chunks can reference this data.\n */\n feedUncompressed(data: Buffer): void {\n for (let i = 0; i < data.length; i++) {\n this.outWindow.putByte(data[i]);\n }\n this.totalPos += data.length;\n if (data.length > 0) {\n this.prevByte = data[data.length - 1];\n }\n }\n\n /**\n * Decode LZMA data\n * @param input - Compressed input buffer\n * @param inputOffset - Offset into input buffer\n * @param outSize - Expected output size\n * @param solid - If true, preserve state from previous decode\n * @returns Decompressed data\n */\n decode(input: Buffer, inputOffset: number, outSize: number, solid = false): Buffer {\n this.rangeDecoder.setInput(input, inputOffset);\n\n if (!solid) {\n this.outWindow.init(false);\n this.initProbabilities();\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n this.prevByte = 0;\n this.totalPos = 0;\n } else {\n // Solid mode: preserve dictionary state but reinitialize range decoder\n this.outWindow.init(true);\n }\n\n const output = allocBufferUnsafe(outSize);\n let outPos = 0;\n let cumPos = this.totalPos;\n\n while (outPos < outSize) {\n const posState = cumPos & this.posStateMask;\n\n if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {\n // Literal\n const decoder2 = this.literalDecoder.getDecoder(cumPos, this.prevByte);\n if (!stateIsCharState(this.state)) {\n this.prevByte = decoder2.decodeWithMatchByte(this.rangeDecoder, this.outWindow.getByte(this.rep0));\n } else {\n this.prevByte = decoder2.decodeNormal(this.rangeDecoder);\n }\n this.outWindow.putByte(this.prevByte);\n output[outPos++] = this.prevByte;\n this.state = stateUpdateChar(this.state);\n cumPos++;\n } else {\n // Match or rep\n let len: number;\n\n if (this.rangeDecoder.decodeBit(this.isRepDecoders, this.state) === 1) {\n // Rep match\n len = 0;\n if (this.rangeDecoder.decodeBit(this.isRepG0Decoders, this.state) === 0) {\n if (this.rangeDecoder.decodeBit(this.isRep0LongDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {\n this.state = stateUpdateShortRep(this.state);\n len = 1;\n }\n } else {\n let distance: number;\n if (this.rangeDecoder.decodeBit(this.isRepG1Decoders, this.state) === 0) {\n distance = this.rep1;\n } else {\n if (this.rangeDecoder.decodeBit(this.isRepG2Decoders, this.state) === 0) {\n distance = this.rep2;\n } else {\n distance = this.rep3;\n this.rep3 = this.rep2;\n }\n this.rep2 = this.rep1;\n }\n this.rep1 = this.rep0;\n this.rep0 = distance;\n }\n if (len === 0) {\n len = kMatchMinLen + this.repLenDecoder.decode(this.rangeDecoder, posState);\n this.state = stateUpdateRep(this.state);\n }\n } else {\n // Normal match\n this.rep3 = this.rep2;\n this.rep2 = this.rep1;\n this.rep1 = this.rep0;\n len = kMatchMinLen + this.lenDecoder.decode(this.rangeDecoder, posState);\n this.state = stateUpdateMatch(this.state);\n\n const posSlot = this.posSlotDecoder[getLenToPosState(len)].decode(this.rangeDecoder);\n if (posSlot >= kStartPosModelIndex) {\n const numDirectBits = (posSlot >> 1) - 1;\n this.rep0 = (2 | (posSlot & 1)) << numDirectBits;\n if (posSlot < kEndPosModelIndex) {\n this.rep0 += reverseDecodeFromArray(this.posDecoders, this.rep0 - posSlot - 1, this.rangeDecoder, numDirectBits);\n } else {\n this.rep0 += this.rangeDecoder.decodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;\n this.rep0 += this.posAlignDecoder.reverseDecode(this.rangeDecoder);\n if (this.rep0 < 0) {\n if (this.rep0 === -1) break; // End marker\n throw new Error('LZMA: Invalid distance');\n }\n }\n } else {\n this.rep0 = posSlot;\n }\n }\n\n if (this.rep0 >= cumPos || this.rep0 >= this.dictionarySizeCheck) {\n throw new Error('LZMA: Invalid distance');\n }\n\n // Copy match bytes\n for (let i = 0; i < len; i++) {\n const b = this.outWindow.getByte(this.rep0);\n this.outWindow.putByte(b);\n output[outPos++] = b;\n }\n cumPos += len;\n this.prevByte = this.outWindow.getByte(0);\n }\n }\n\n this.totalPos = cumPos;\n return output;\n }\n}\n\n/**\n * Decode LZMA1 data synchronously\n * @param input - Compressed data (without 5-byte properties header)\n * @param properties - 5-byte LZMA properties\n * @param outSize - Expected output size\n * @returns Decompressed data\n */\nexport function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number): Buffer {\n const decoder = new LzmaDecoder();\n decoder.setDecoderProperties(properties);\n return decoder.decode(input, 0, outSize, false);\n}\n"],"names":["allocBufferUnsafe","getLenToPosState","initBitModels","kEndPosModelIndex","kMatchMinLen","kNumAlignBits","kNumFullDistances","kNumLenToPosStates","kNumLitContextBitsMax","kNumPosSlotBits","kNumPosStatesBitsMax","kNumStates","kStartPosModelIndex","parseProperties","stateIsCharState","stateUpdateChar","stateUpdateMatch","stateUpdateRep","stateUpdateShortRep","BitTreeDecoder","RangeDecoder","reverseDecodeFromArray","LenDecoder","create","numPosStates","lowCoder","midCoder","init","choice","i","highCoder","decode","rangeDecoder","posState","decodeBit","LiteralDecoder2","decoders","decodeNormal","symbol","decodeWithMatchByte","matchByte","matchBit","bit","LiteralDecoder","numPosBits","numPrevBits","coders","length","posMask","getDecoder","pos","prevByte","index","decoder","OutWindow","windowSize","buffer","solid","putByte","b","getByte","distance","copyBlock","len","copyTo","output","outputOffset","count","srcPos","firstPart","copy","LzmaDecoder","setDictionarySize","dictionarySize","dictionarySizeCheck","Math","max","outWindow","setLcLpPb","lc","lp","pb","literalDecoder","lenDecoder","repLenDecoder","posStateMask","setDecoderProperties","properties","props","initProbabilities","isMatchDecoders","isRepDecoders","isRepG0Decoders","isRepG1Decoders","isRepG2Decoders","isRep0LongDecoders","posDecoders","posSlotDecoder","posAlignDecoder","resetProbabilities","state","rep0","rep1","rep2","rep3","resetDictionary","totalPos","feedUncompressed","data","input","inputOffset","outSize","setInput","outPos","cumPos","decoder2","posSlot","numDirectBits","decodeDirectBits","reverseDecode","Error","decodeLzma"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SACEC,gBAAgB,EAChBC,aAAa,EACbC,iBAAiB,EACjBC,YAAY,EACZC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,qBAAqB,EACrBC,eAAe,EACfC,oBAAoB,EACpBC,UAAU,EACVC,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oBsB,IAAK;YAC3C,IAAI,CAACoE,cAAc,CAACpE,EAAE,GAAG,IAAIV,eAAeV;QAC9C;QAEA,IAAI,CAACgE,cAAc,GAAG,CAAC;QACvB,IAAI,CAACC,mBAAmB,GAAG,CAAC;QAC5B,IAAI,CAACW,YAAY,GAAG;QAEpB,IAAI,CAACe,KAAK,GAAG;QACb,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACrD,QAAQ,GAAG;QAChB,IAAI,CAACuD,QAAQ,GAAG;IAClB;AAuNF;AAEA;;;;;;CAMC,GACD,OAAO,SAASe,WAAWZ,KAAa,EAAEtB,UAA+B,EAAEwB,OAAe;IACxF,MAAM1D,UAAU,IAAIkB;IACpBlB,QAAQiC,oBAAoB,CAACC;IAC7B,OAAOlC,QAAQtB,MAAM,CAAC8E,OAAO,GAAGE,SAAS;AAC3C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/sync/LzmaDecoder.ts"],"sourcesContent":["/**\n * Synchronous LZMA1 Decoder\n *\n * Decodes LZMA1 compressed data from a buffer.\n * All operations are synchronous.\n */\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport {\n getLenToPosState,\n initBitModels,\n kEndPosModelIndex,\n kMatchMinLen,\n kNumAlignBits,\n kNumFullDistances,\n kNumLenToPosStates,\n kNumLitContextBitsMax,\n kNumPosSlotBits,\n kNumPosStatesBitsMax,\n kNumStates,\n kStartPosModelIndex,\n type OutputSink,\n parseProperties,\n stateIsCharState,\n stateUpdateChar,\n stateUpdateMatch,\n stateUpdateRep,\n stateUpdateShortRep,\n} from '../types.ts';\nimport { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDecoder.ts';\n\n/**\n * Length decoder for match/rep lengths\n */\nclass LenDecoder {\n private choice: Uint16Array;\n private lowCoder: BitTreeDecoder[];\n private midCoder: BitTreeDecoder[];\n private highCoder: BitTreeDecoder;\n private numPosStates: number;\n\n constructor() {\n this.choice = initBitModels(null, 2);\n this.lowCoder = [];\n this.midCoder = [];\n this.highCoder = new BitTreeDecoder(8);\n this.numPosStates = 0;\n }\n\n create(numPosStates: number): void {\n for (; this.numPosStates < numPosStates; this.numPosStates++) {\n this.lowCoder[this.numPosStates] = new BitTreeDecoder(3);\n this.midCoder[this.numPosStates] = new BitTreeDecoder(3);\n }\n }\n\n init(): void {\n initBitModels(this.choice);\n for (let i = this.numPosStates - 1; i >= 0; i--) {\n this.lowCoder[i].init();\n this.midCoder[i].init();\n }\n this.highCoder.init();\n }\n\n decode(rangeDecoder: RangeDecoder, posState: number): number {\n if (rangeDecoder.decodeBit(this.choice, 0) === 0) {\n return this.lowCoder[posState].decode(rangeDecoder);\n }\n if (rangeDecoder.decodeBit(this.choice, 1) === 0) {\n return 8 + this.midCoder[posState].decode(rangeDecoder);\n }\n return 16 + this.highCoder.decode(rangeDecoder);\n }\n}\n\n/**\n * Single literal decoder (decodes one byte)\n */\nclass LiteralDecoder2 {\n private decoders: Uint16Array;\n\n constructor() {\n this.decoders = initBitModels(null, 0x300);\n }\n\n init(): void {\n initBitModels(this.decoders);\n }\n\n decodeNormal(rangeDecoder: RangeDecoder): number {\n let symbol = 1;\n do {\n symbol = (symbol << 1) | rangeDecoder.decodeBit(this.decoders, symbol);\n } while (symbol < 0x100);\n return symbol & 0xff;\n }\n\n decodeWithMatchByte(rangeDecoder: RangeDecoder, matchByte: number): number {\n let symbol = 1;\n do {\n const matchBit = (matchByte >> 7) & 1;\n matchByte <<= 1;\n const bit = rangeDecoder.decodeBit(this.decoders, ((1 + matchBit) << 8) + symbol);\n symbol = (symbol << 1) | bit;\n if (matchBit !== bit) {\n while (symbol < 0x100) {\n symbol = (symbol << 1) | rangeDecoder.decodeBit(this.decoders, symbol);\n }\n break;\n }\n } while (symbol < 0x100);\n return symbol & 0xff;\n }\n}\n\n/**\n * Literal decoder (array of single decoders)\n */\nclass LiteralDecoder {\n private numPosBits: number;\n private numPrevBits: number;\n private posMask: number;\n private coders: (LiteralDecoder2 | undefined)[];\n\n constructor() {\n this.numPosBits = 0;\n this.numPrevBits = 0;\n this.posMask = 0;\n this.coders = [];\n }\n\n create(numPosBits: number, numPrevBits: number): void {\n if (this.coders.length > 0 && this.numPrevBits === numPrevBits && this.numPosBits === numPosBits) {\n return;\n }\n this.numPosBits = numPosBits;\n this.posMask = (1 << numPosBits) - 1;\n this.numPrevBits = numPrevBits;\n this.coders = [];\n }\n\n init(): void {\n for (let i = 0; i < this.coders.length; i++) {\n if (this.coders[i]) {\n this.coders[i]?.init();\n }\n }\n }\n\n getDecoder(pos: number, prevByte: number): LiteralDecoder2 {\n const index = ((pos & this.posMask) << this.numPrevBits) + ((prevByte & 0xff) >>> (8 - this.numPrevBits));\n let decoder = this.coders[index];\n if (!decoder) {\n decoder = new LiteralDecoder2();\n this.coders[index] = decoder;\n }\n return decoder;\n }\n}\n\n/**\n * Output window (sliding dictionary)\n */\nclass OutWindow {\n private buffer: Buffer;\n private windowSize: number;\n private pos: number;\n private sink?: {\n write(buffer: Buffer): void;\n };\n private streamPos: number;\n\n constructor(sink?: OutputSink) {\n this.buffer = allocBufferUnsafe(0); // Replaced by create() before use\n this.windowSize = 0;\n this.pos = 0;\n this.sink = sink;\n this.streamPos = 0;\n }\n\n create(windowSize: number): void {\n if (!this.buffer || this.windowSize !== windowSize) {\n this.buffer = allocBufferUnsafe(windowSize);\n }\n this.windowSize = windowSize;\n this.pos = 0;\n this.streamPos = 0;\n }\n\n init(solid: boolean): void {\n if (!solid) {\n this.pos = 0;\n this.streamPos = 0;\n }\n }\n\n putByte(b: number): void {\n this.buffer[this.pos++] = b;\n if (this.pos >= this.windowSize) {\n if (this.sink) {\n this.flush();\n this.pos = 0;\n } else {\n this.pos = 0;\n }\n }\n }\n\n flush(): void {\n const size = this.pos - this.streamPos;\n if (size > 0 && this.sink) {\n const chunk = this.buffer.slice(this.streamPos, this.streamPos + size);\n this.sink.write(chunk);\n this.streamPos = this.pos;\n }\n }\n\n getByte(distance: number): number {\n let pos = this.pos - distance - 1;\n if (pos < 0) {\n pos += this.windowSize;\n }\n return this.buffer[pos];\n }\n\n copyBlock(distance: number, len: number): void {\n let pos = this.pos - distance - 1;\n if (pos < 0) {\n pos += this.windowSize;\n }\n for (let i = 0; i < len; i++) {\n if (pos >= this.windowSize) {\n pos = 0;\n }\n this.putByte(this.buffer[pos++]);\n }\n }\n\n /**\n * Copy decoded data to output buffer\n */\n copyTo(output: Buffer, outputOffset: number, count: number): void {\n const srcPos = this.pos - count;\n if (srcPos < 0) {\n // Wrap around case - data spans end and beginning of buffer\n const firstPart = -srcPos;\n this.buffer.copy(output, outputOffset, this.windowSize + srcPos, this.windowSize);\n this.buffer.copy(output, outputOffset + firstPart, 0, count - firstPart);\n } else {\n this.buffer.copy(output, outputOffset, srcPos, srcPos + count);\n }\n }\n}\n\n/**\n * Synchronous LZMA1 decoder\n */\nexport class LzmaDecoder {\n private outWindow: OutWindow;\n private rangeDecoder: RangeDecoder;\n\n // Probability models\n private isMatchDecoders: Uint16Array;\n private isRepDecoders: Uint16Array;\n private isRepG0Decoders: Uint16Array;\n private isRepG1Decoders: Uint16Array;\n private isRepG2Decoders: Uint16Array;\n private isRep0LongDecoders: Uint16Array;\n private posSlotDecoder: BitTreeDecoder[];\n private posDecoders: Uint16Array;\n private posAlignDecoder: BitTreeDecoder;\n private lenDecoder: LenDecoder;\n private repLenDecoder: LenDecoder;\n private literalDecoder: LiteralDecoder;\n\n // Properties\n private dictionarySize: number;\n private dictionarySizeCheck: number;\n private posStateMask: number;\n\n // State (preserved across solid calls)\n private state: number;\n private rep0: number;\n private rep1: number;\n private rep2: number;\n private rep3: number;\n private prevByte: number;\n private totalPos: number;\n\n constructor(outputSink?: OutputSink) {\n this.outWindow = new OutWindow(outputSink);\n this.rangeDecoder = new RangeDecoder();\n\n this.isMatchDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);\n this.isRepDecoders = initBitModels(null, kNumStates);\n this.isRepG0Decoders = initBitModels(null, kNumStates);\n this.isRepG1Decoders = initBitModels(null, kNumStates);\n this.isRepG2Decoders = initBitModels(null, kNumStates);\n this.isRep0LongDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);\n this.posSlotDecoder = [];\n this.posDecoders = initBitModels(null, kNumFullDistances - kEndPosModelIndex);\n this.posAlignDecoder = new BitTreeDecoder(kNumAlignBits);\n this.lenDecoder = new LenDecoder();\n this.repLenDecoder = new LenDecoder();\n this.literalDecoder = new LiteralDecoder();\n\n for (let i = 0; i < kNumLenToPosStates; i++) {\n this.posSlotDecoder[i] = new BitTreeDecoder(kNumPosSlotBits);\n }\n\n this.dictionarySize = -1;\n this.dictionarySizeCheck = -1;\n this.posStateMask = 0;\n\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n this.prevByte = 0;\n this.totalPos = 0;\n }\n\n /**\n * Set dictionary size\n */\n setDictionarySize(dictionarySize: number): boolean {\n if (dictionarySize < 0) return false;\n if (this.dictionarySize !== dictionarySize) {\n this.dictionarySize = dictionarySize;\n this.dictionarySizeCheck = Math.max(dictionarySize, 1);\n this.outWindow.create(Math.max(this.dictionarySizeCheck, 1 << 12));\n }\n return true;\n }\n\n /**\n * Set lc, lp, pb properties\n */\n setLcLpPb(lc: number, lp: number, pb: number): boolean {\n if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {\n return false;\n }\n const numPosStates = 1 << pb;\n this.literalDecoder.create(lp, lc);\n this.lenDecoder.create(numPosStates);\n this.repLenDecoder.create(numPosStates);\n this.posStateMask = numPosStates - 1;\n return true;\n }\n\n /**\n * Set decoder properties from 5-byte buffer\n */\n setDecoderProperties(properties: Buffer | Uint8Array): boolean {\n const props = parseProperties(properties);\n if (!this.setLcLpPb(props.lc, props.lp, props.pb)) return false;\n return this.setDictionarySize(props.dictionarySize);\n }\n\n /**\n * Initialize probability tables\n */\n private initProbabilities(): void {\n initBitModels(this.isMatchDecoders);\n initBitModels(this.isRepDecoders);\n initBitModels(this.isRepG0Decoders);\n initBitModels(this.isRepG1Decoders);\n initBitModels(this.isRepG2Decoders);\n initBitModels(this.isRep0LongDecoders);\n initBitModels(this.posDecoders);\n this.literalDecoder.init();\n for (let i = kNumLenToPosStates - 1; i >= 0; i--) {\n this.posSlotDecoder[i].init();\n }\n this.lenDecoder.init();\n this.repLenDecoder.init();\n this.posAlignDecoder.init();\n }\n\n /**\n * Reset probabilities only (for LZMA2 state reset)\n */\n resetProbabilities(): void {\n this.initProbabilities();\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n }\n\n /**\n * Reset dictionary position (for LZMA2 dictionary reset)\n */\n resetDictionary(): void {\n this.outWindow.init(false);\n this.totalPos = 0;\n }\n\n /**\n * Feed uncompressed data into the dictionary (for LZMA2 uncompressed chunks)\n * This updates the sliding window so subsequent LZMA chunks can reference this data.\n */\n feedUncompressed(data: Buffer): void {\n for (let i = 0; i < data.length; i++) {\n this.outWindow.putByte(data[i]);\n }\n this.totalPos += data.length;\n if (data.length > 0) {\n this.prevByte = data[data.length - 1];\n }\n }\n\n /**\n * Flush any remaining data in the OutWindow to the sink\n */\n flushOutWindow(): void {\n this.outWindow.flush();\n }\n\n /**\n * Decode LZMA data with streaming output (no buffer accumulation)\n * @param input - Compressed input buffer\n * @param inputOffset - Offset into input buffer\n * @param outSize - Expected output size\n * @param solid - If true, preserve state from previous decode\n * @returns Number of bytes written to sink\n */\n decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid = false): number {\n this.rangeDecoder.setInput(input, inputOffset);\n\n if (!solid) {\n this.outWindow.init(false);\n this.initProbabilities();\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n this.prevByte = 0;\n this.totalPos = 0;\n } else {\n this.outWindow.init(true);\n }\n\n let outPos = 0;\n let cumPos = this.totalPos;\n\n while (outPos < outSize) {\n const posState = cumPos & this.posStateMask;\n\n if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {\n // Literal\n const decoder2 = this.literalDecoder.getDecoder(cumPos, this.prevByte);\n if (!stateIsCharState(this.state)) {\n this.prevByte = decoder2.decodeWithMatchByte(this.rangeDecoder, this.outWindow.getByte(this.rep0));\n } else {\n this.prevByte = decoder2.decodeNormal(this.rangeDecoder);\n }\n this.outWindow.putByte(this.prevByte);\n outPos++;\n this.state = stateUpdateChar(this.state);\n cumPos++;\n } else {\n // Match or rep\n let len: number;\n\n if (this.rangeDecoder.decodeBit(this.isRepDecoders, this.state) === 1) {\n // Rep match\n len = 0;\n if (this.rangeDecoder.decodeBit(this.isRepG0Decoders, this.state) === 0) {\n if (this.rangeDecoder.decodeBit(this.isRep0LongDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {\n this.state = stateUpdateShortRep(this.state);\n len = 1;\n }\n } else {\n let distance: number;\n if (this.rangeDecoder.decodeBit(this.isRepG1Decoders, this.state) === 0) {\n distance = this.rep1;\n } else {\n if (this.rangeDecoder.decodeBit(this.isRepG2Decoders, this.state) === 0) {\n distance = this.rep2;\n } else {\n distance = this.rep3;\n this.rep3 = this.rep2;\n }\n this.rep2 = this.rep1;\n }\n this.rep1 = this.rep0;\n this.rep0 = distance;\n }\n if (len === 0) {\n len = kMatchMinLen + this.repLenDecoder.decode(this.rangeDecoder, posState);\n this.state = stateUpdateRep(this.state);\n }\n } else {\n // Normal match\n this.rep3 = this.rep2;\n this.rep2 = this.rep1;\n this.rep1 = this.rep0;\n len = kMatchMinLen + this.lenDecoder.decode(this.rangeDecoder, posState);\n this.state = stateUpdateMatch(this.state);\n\n const posSlot = this.posSlotDecoder[getLenToPosState(len)].decode(this.rangeDecoder);\n if (posSlot >= kStartPosModelIndex) {\n const numDirectBits = (posSlot >> 1) - 1;\n this.rep0 = (2 | (posSlot & 1)) << numDirectBits;\n if (posSlot < kEndPosModelIndex) {\n this.rep0 += reverseDecodeFromArray(this.posDecoders, this.rep0 - posSlot - 1, this.rangeDecoder, numDirectBits);\n } else {\n this.rep0 += this.rangeDecoder.decodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;\n this.rep0 += this.posAlignDecoder.reverseDecode(this.rangeDecoder);\n if (this.rep0 < 0) {\n if (this.rep0 === -1) break;\n throw new Error('LZMA: Invalid distance');\n }\n }\n } else {\n this.rep0 = posSlot;\n }\n }\n\n if (this.rep0 >= cumPos || this.rep0 >= this.dictionarySizeCheck) {\n throw new Error('LZMA: Invalid distance');\n }\n\n // Copy match bytes\n for (let i = 0; i < len; i++) {\n const b = this.outWindow.getByte(this.rep0);\n this.outWindow.putByte(b);\n outPos++;\n }\n cumPos += len;\n this.prevByte = this.outWindow.getByte(0);\n }\n }\n\n this.totalPos = cumPos;\n return outPos;\n }\n\n /**\n * Decode LZMA data\n * @param input - Compressed input buffer\n * @param inputOffset - Offset into input buffer\n * @param outSize - Expected output size\n * @param solid - If true, preserve state from previous decode\n * @returns Decompressed data\n */\n decode(input: Buffer, inputOffset: number, outSize: number, solid = false): Buffer {\n this.rangeDecoder.setInput(input, inputOffset);\n\n if (!solid) {\n this.outWindow.init(false);\n this.initProbabilities();\n this.state = 0;\n this.rep0 = 0;\n this.rep1 = 0;\n this.rep2 = 0;\n this.rep3 = 0;\n this.prevByte = 0;\n this.totalPos = 0;\n } else {\n // Solid mode: preserve dictionary state but reinitialize range decoder\n this.outWindow.init(true);\n }\n\n const output = allocBufferUnsafe(outSize);\n let outPos = 0;\n let cumPos = this.totalPos;\n\n while (outPos < outSize) {\n const posState = cumPos & this.posStateMask;\n\n if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {\n // Literal\n const decoder2 = this.literalDecoder.getDecoder(cumPos, this.prevByte);\n if (!stateIsCharState(this.state)) {\n this.prevByte = decoder2.decodeWithMatchByte(this.rangeDecoder, this.outWindow.getByte(this.rep0));\n } else {\n this.prevByte = decoder2.decodeNormal(this.rangeDecoder);\n }\n this.outWindow.putByte(this.prevByte);\n output[outPos++] = this.prevByte;\n this.state = stateUpdateChar(this.state);\n cumPos++;\n } else {\n // Match or rep\n let len: number;\n\n if (this.rangeDecoder.decodeBit(this.isRepDecoders, this.state) === 1) {\n // Rep match\n len = 0;\n if (this.rangeDecoder.decodeBit(this.isRepG0Decoders, this.state) === 0) {\n if (this.rangeDecoder.decodeBit(this.isRep0LongDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {\n this.state = stateUpdateShortRep(this.state);\n len = 1;\n }\n } else {\n let distance: number;\n if (this.rangeDecoder.decodeBit(this.isRepG1Decoders, this.state) === 0) {\n distance = this.rep1;\n } else {\n if (this.rangeDecoder.decodeBit(this.isRepG2Decoders, this.state) === 0) {\n distance = this.rep2;\n } else {\n distance = this.rep3;\n this.rep3 = this.rep2;\n }\n this.rep2 = this.rep1;\n }\n this.rep1 = this.rep0;\n this.rep0 = distance;\n }\n if (len === 0) {\n len = kMatchMinLen + this.repLenDecoder.decode(this.rangeDecoder, posState);\n this.state = stateUpdateRep(this.state);\n }\n } else {\n // Normal match\n this.rep3 = this.rep2;\n this.rep2 = this.rep1;\n this.rep1 = this.rep0;\n len = kMatchMinLen + this.lenDecoder.decode(this.rangeDecoder, posState);\n this.state = stateUpdateMatch(this.state);\n\n const posSlot = this.posSlotDecoder[getLenToPosState(len)].decode(this.rangeDecoder);\n if (posSlot >= kStartPosModelIndex) {\n const numDirectBits = (posSlot >> 1) - 1;\n this.rep0 = (2 | (posSlot & 1)) << numDirectBits;\n if (posSlot < kEndPosModelIndex) {\n this.rep0 += reverseDecodeFromArray(this.posDecoders, this.rep0 - posSlot - 1, this.rangeDecoder, numDirectBits);\n } else {\n this.rep0 += this.rangeDecoder.decodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;\n this.rep0 += this.posAlignDecoder.reverseDecode(this.rangeDecoder);\n if (this.rep0 < 0) {\n if (this.rep0 === -1) break; // End marker\n throw new Error('LZMA: Invalid distance');\n }\n }\n } else {\n this.rep0 = posSlot;\n }\n }\n\n if (this.rep0 >= cumPos || this.rep0 >= this.dictionarySizeCheck) {\n throw new Error('LZMA: Invalid distance');\n }\n\n // Copy match bytes\n for (let i = 0; i < len; i++) {\n const b = this.outWindow.getByte(this.rep0);\n this.outWindow.putByte(b);\n output[outPos++] = b;\n }\n cumPos += len;\n this.prevByte = this.outWindow.getByte(0);\n }\n }\n\n this.totalPos = cumPos;\n return output;\n }\n}\n\n/**\n * Decode LZMA1 data synchronously\n * @param input - Compressed data (without 5-byte properties header)\n * @param properties - 5-byte LZMA properties\n * @param outSize - Expected output size\n * @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)\n * @returns Decompressed data (or bytes written if outputSink provided)\n */\nexport function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?: OutputSink): Buffer | number {\n const decoder = new LzmaDecoder(outputSink);\n decoder.setDecoderProperties(properties);\n if (outputSink) {\n // Zero-copy mode: write to sink during decode\n const bytesWritten = decoder.decodeWithSink(input, 0, outSize, false);\n decoder.flushOutWindow();\n return bytesWritten;\n }\n // Buffering mode: pre-allocated buffer, direct writes (zero-copy)\n return decoder.decode(input, 0, outSize, false);\n}\n"],"names":["allocBufferUnsafe","getLenToPosState","initBitModels","kEndPosModelIndex","kMatchMinLen","kNumAlignBits","kNumFullDistances","kNumLenToPosStates","kNumLitContextBitsMax","kNumPosSlotBits","kNumPosStatesBitsMax","kNumStates","kStartPosModelIndex","parseProperties","stateIsCharState","stateUpdateChar","stateUpdateMatch","stateUpdateRep","stateUpdateShortRep","BitTreeDecoder","RangeDecoder","reverseDecodeFromArray","LenDecoder","create","numPosStates","lowCoder","midCoder","init","choice","i","highCoder","decode","rangeDecoder","posState","decodeBit","LiteralDecoder2","decoders","decodeNormal","symbol","decodeWithMatchByte","matchByte","matchBit","bit","LiteralDecoder","numPosBits","numPrevBits","coders","length","posMask","getDecoder","pos","prevByte","index","decoder","OutWindow","windowSize","buffer","streamPos","solid","putByte","b","sink","flush","size","chunk","slice","write","getByte","distance","copyBlock","len","copyTo","output","outputOffset","count","srcPos","firstPart","copy","LzmaDecoder","setDictionarySize","dictionarySize","dictionarySizeCheck","Math","max","outWindow","setLcLpPb","lc","lp","pb","literalDecoder","lenDecoder","repLenDecoder","posStateMask","setDecoderProperties","properties","props","initProbabilities","isMatchDecoders","isRepDecoders","isRepG0Decoders","isRepG1Decoders","isRepG2Decoders","isRep0LongDecoders","posDecoders","posSlotDecoder","posAlignDecoder","resetProbabilities","state","rep0","rep1","rep2","rep3","resetDictionary","totalPos","feedUncompressed","data","flushOutWindow","decodeWithSink","input","inputOffset","outSize","setInput","outPos","cumPos","decoder2","posSlot","numDirectBits","decodeDirectBits","reverseDecode","Error","outputSink","decodeLzma","bytesWritten"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SACEC,gBAAgB,EAChBC,aAAa,EACbC,iBAAiB,EACjBC,YAAY,EACZC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,qBAAqB,EACrBC,eAAe,EACfC,oBAAoB,EACpBC,UAAU,EACVC,mBAAmB,EAEnBC,eAAe,EACfC,gBAAgB,EAChBC,eAAe,EACfC,gBAAgB,EAChBC,cAAc,EACdC,mBAAmB,QACd,cAAc;AACrB,SAASC,cAAc,EAAEC,YAAY,EAAEC,sBAAsB,QAAQ,oBAAoB;AAEzF;;CAEC,GACD,IAAA,AAAMC,aAAN,MAAMA;IAeJC,OAAOC,YAAoB,EAAQ;QACjC,MAAO,IAAI,CAACA,YAAY,GAAGA,cAAc,IAAI,CAACA,YAAY,GAAI;YAC5D,IAAI,CAACC,QAAQ,CAAC,IAAI,CAACD,YAAY,CAAC,GAAG,IAAIL,eAAe;YACtD,IAAI,CAACO,QAA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AChB,IAAI,CAAC8D,QAAQ,GAAG;IAClB;AAuVF;AAEA;;;;;;;CAOC,GACD,OAAO,SAASkB,WAAWb,KAAa,EAAExB,UAA+B,EAAE0B,OAAe,EAAEU,UAAuB;IACjH,MAAM7E,UAAU,IAAIyB,YAAYoD;IAChC7E,QAAQwC,oBAAoB,CAACC;IAC7B,IAAIoC,YAAY;QACd,8CAA8C;QAC9C,MAAME,eAAe/E,QAAQgE,cAAc,CAACC,OAAO,GAAGE,SAAS;QAC/DnE,QAAQ+D,cAAc;QACtB,OAAOgB;IACT;IACA,kEAAkE;IAClE,OAAO/E,QAAQtB,MAAM,CAACuF,OAAO,GAAGE,SAAS;AAC3C"}
@@ -108,3 +108,10 @@ export declare function lzma2IsUncompressed(control: number): boolean;
108
108
  * Parse LZMA2 dictionary size from property byte
109
109
  */
110
110
  export declare function parseLzma2DictionarySize(prop: number): number;
111
+ /**
112
+ * Output sink interface for fast streaming decode
113
+ * Can be a Buffer (with write method) or a stream with write() method
114
+ */
115
+ export interface OutputSink {
116
+ write(buffer: Buffer): void;
117
+ }