xz-compat 0.2.0 → 0.2.1

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.
@@ -198,14 +198,15 @@ var Lzma2Decoder = /*#__PURE__*/ function() {
198
198
  }
199
199
  // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
200
200
  var useSolid = !chunk.stateReset || chunk.stateReset && !chunk.dictReset;
201
- // Decode LZMA chunk
202
- var chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
203
- var decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
204
- // Copy to output
201
+ // Decode LZMA chunk - use zero-copy when we have pre-allocated buffer
205
202
  if (outputBuffer) {
206
- decoded.copy(outputBuffer, outputPos);
207
- outputPos += decoded.length;
203
+ // Zero-copy: decode directly into caller's buffer
204
+ var bytesWritten = this.lzmaDecoder.decodeToBuffer(input, dataOffset, chunk.uncompSize, outputBuffer, outputPos, useSolid);
205
+ outputPos += bytesWritten;
208
206
  } else {
207
+ // No pre-allocation: decode to new buffer and collect chunks
208
+ var chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
209
+ var decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
209
210
  outputChunks.push(decoded);
210
211
  }
211
212
  offset = dataOffset + chunk.compSize;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink as 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":["Lzma2Decoder","decodeLzma2","properties","outputSink","length","Error","dictionarySize","parseLzma2DictionarySize","lzmaDecoder","LzmaDecoder","setDictionarySize","propsSet","resetDictionary","resetProbabilities","setLcLpPb","lc","lp","pb","feedUncompressed","data","decodeLzmaData","input","offset","outSize","solid","decode","decodeWithSink","totalBytes","result","parseLzma2ChunkHeader","success","chunk","type","dataSize","uncompSize","compSize","headerSize","dictReset","dataOffset","uncompData","slice","newProps","stateReset","useSolid","flushOutWindow","unpackSize","outputBuffer","outputPos","outputChunks","allocBufferUnsafe","copy","push","chunkData","decoded","Buffer","concat","decoder"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAUYA;eAAAA;;QA2PGC;eAAAA;;;mCAnQkB;kCACI;uBACoB;6BAC9B;;;;;;AAKrB,IAAA,AAAMD,6BAAN;;aAAMA,aAKCE,UAA+B,EAAEC,UAAuB;gCALzDH;QAMT,IAAI,CAACE,cAAcA,WAAWE,MAAM,GAAG,GAAG;YACxC,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAI,CAACC,cAAc,GAAGC,IAAAA,iCAAwB,EAACL,UAAU,CAAC,EAAE;QAC5D,IAAI,CAACM,WAAW,GAAG,IAAIC,0BAAW,CAACN;QACnC,I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P,MAAMI,QAAQ;YACtC;QACF;QAEA,qDAAqD;QACrD,IAAIW,cAAc;YAChB,OAAOC,YAAYD,aAAa1C,MAAM,GAAG0C,aAAaN,KAAK,CAAC,GAAGO,aAAaD;QAC9E;QACA,OAAOQ,OAAOC,MAAM,CAACP;IACvB;WAhPWhD;;AA2PN,SAASC,YAAYoB,KAAa,EAAEnB,UAA+B,EAAE2C,UAAmB,EAAE1C,UAA4C;IAC3I,IAAMqD,UAAU,IAAIxD,aAAaE,YAAYC;IAC7C,IAAIA,YAAY;QACd,8CAA8C;QAC9C,OAAOqD,QAAQ9B,cAAc,CAACL;IAChC;IACA,6CAA6C;IAC7C,OAAOmC,QAAQ/B,MAAM,CAACJ,OAAOwB;AAC/B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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 - use zero-copy when we have pre-allocated buffer\n if (outputBuffer) {\n // Zero-copy: decode directly into caller's buffer\n const bytesWritten = this.lzmaDecoder.decodeToBuffer(input, dataOffset, chunk.uncompSize, outputBuffer, outputPos, useSolid);\n outputPos += bytesWritten;\n } else {\n // No pre-allocation: decode to new buffer and collect chunks\n const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);\n const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink as 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":["Lzma2Decoder","decodeLzma2","properties","outputSink","length","Error","dictionarySize","parseLzma2DictionarySize","lzmaDecoder","LzmaDecoder","setDictionarySize","propsSet","resetDictionary","resetProbabilities","setLcLpPb","lc","lp","pb","feedUncompressed","data","decodeLzmaData","input","offset","outSize","solid","decode","decodeWithSink","totalBytes","result","parseLzma2ChunkHeader","success","chunk","type","dataSize","uncompSize","compSize","headerSize","dictReset","dataOffset","uncompData","slice","newProps","stateReset","useSolid","flushOutWindow","unpackSize","outputBuffer","outputPos","outputChunks","allocBufferUnsafe","copy","push","bytesWritten","decodeToBuffer","chunkData","decoded","Buffer","concat","decoder"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAUYA;eAAAA;;QA2PGC;eAAAA;;;mCAnQkB;kCACI;uBACoB;6BAC9B;;;;;;AAKrB,IAAA,AAAMD,6BAAN;;aAAMA,aAKCE,UAA+B,EAAEC,UAAuB;gCALzDH;QAMT,IAAI,CAACE,cAAcA,WAAWE,MAAM,GAAG,GAAG;YACxC,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAI,CAACC,cAAc,GAAGC,IAAAA,iCAAwB,EAACL,UAAU,CAAC,EAAE;QAC5D,IAAI,CAACM,WAAW,GAAG,IAAIC,0BAAW,CAACN;QACnC,IAAI,CAACK,WAAW,CAACE,iBAAiB,CAAC,IAAI,CAACJ,cAAc;QACtD,IAAI,CAACK,QAAQ,GAAG;;iBAbPX;IAgBX;;GAEC,GACDY,OAAAA,eAEC,GAFDA,SAAAA;QACE,IAAI,CAACJ,WAAW,CAACI,eAAe;IAClC;IAEA;;GAEC,GACDC,OAAAA,kBAEC,GAFDA,SAAAA;QACE,IAA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,CAACT;IACvB;WAhPWhD;;AA2PN,SAASC,YAAYoB,KAAa,EAAEnB,UAA+B,EAAE2C,UAAmB,EAAE1C,UAA4C;IAC3I,IAAMuD,UAAU,IAAI1D,aAAaE,YAAYC;IAC7C,IAAIA,YAAY;QACd,8CAA8C;QAC9C,OAAOuD,QAAQhC,cAAc,CAACL;IAChC;IACA,6CAA6C;IAC7C,OAAOqC,QAAQjC,MAAM,CAACJ,OAAOwB;AAC/B"}
@@ -76,6 +76,17 @@ export declare class LzmaDecoder {
76
76
  * @returns Number of bytes written to sink
77
77
  */
78
78
  decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
79
+ /**
80
+ * Decode LZMA data directly into caller's buffer (zero-copy)
81
+ * @param input - Compressed input buffer
82
+ * @param inputOffset - Offset into input buffer
83
+ * @param outSize - Expected output size
84
+ * @param output - Pre-allocated output buffer to write to
85
+ * @param outputOffset - Offset in output buffer to start writing
86
+ * @param solid - If true, preserve state from previous decode
87
+ * @returns Number of bytes written
88
+ */
89
+ decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: number, solid?: boolean): number;
79
90
  /**
80
91
  * Decode LZMA data
81
92
  * @param input - Compressed input buffer
@@ -76,6 +76,17 @@ export declare class LzmaDecoder {
76
76
  * @returns Number of bytes written to sink
77
77
  */
78
78
  decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
79
+ /**
80
+ * Decode LZMA data directly into caller's buffer (zero-copy)
81
+ * @param input - Compressed input buffer
82
+ * @param inputOffset - Offset into input buffer
83
+ * @param outSize - Expected output size
84
+ * @param output - Pre-allocated output buffer to write to
85
+ * @param outputOffset - Offset in output buffer to start writing
86
+ * @param solid - If true, preserve state from previous decode
87
+ * @returns Number of bytes written
88
+ */
89
+ decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: number, solid?: boolean): number;
79
90
  /**
80
91
  * Decode LZMA data
81
92
  * @param input - Compressed input buffer
@@ -453,14 +453,16 @@ var LzmaDecoder = /*#__PURE__*/ function() {
453
453
  return outPos;
454
454
  };
455
455
  /**
456
- * Decode LZMA data
456
+ * Decode LZMA data directly into caller's buffer (zero-copy)
457
457
  * @param input - Compressed input buffer
458
458
  * @param inputOffset - Offset into input buffer
459
459
  * @param outSize - Expected output size
460
+ * @param output - Pre-allocated output buffer to write to
461
+ * @param outputOffset - Offset in output buffer to start writing
460
462
  * @param solid - If true, preserve state from previous decode
461
- * @returns Decompressed data
462
- */ _proto.decode = function decode(input, inputOffset, outSize) {
463
- var solid = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
463
+ * @returns Number of bytes written
464
+ */ _proto.decodeToBuffer = function decodeToBuffer(input, inputOffset, outSize, output, outputOffset) {
465
+ var solid = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : false;
464
466
  this.rangeDecoder.setInput(input, inputOffset);
465
467
  if (!solid) {
466
468
  this.outWindow.init(false);
@@ -476,10 +478,10 @@ var LzmaDecoder = /*#__PURE__*/ function() {
476
478
  // Solid mode: preserve dictionary state but reinitialize range decoder
477
479
  this.outWindow.init(true);
478
480
  }
479
- var output = (0, _extractbaseiterator.allocBufferUnsafe)(outSize);
480
- var outPos = 0;
481
+ var outPos = outputOffset;
482
+ var outEnd = outputOffset + outSize;
481
483
  var cumPos = this.totalPos;
482
- while(outPos < outSize){
484
+ while(outPos < outEnd){
483
485
  var posState = cumPos & this.posStateMask;
484
486
  if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << _typests.kNumPosStatesBitsMax) + posState) === 0) {
485
487
  // Literal
@@ -563,6 +565,19 @@ var LzmaDecoder = /*#__PURE__*/ function() {
563
565
  }
564
566
  }
565
567
  this.totalPos = cumPos;
568
+ return outPos - outputOffset;
569
+ };
570
+ /**
571
+ * Decode LZMA data
572
+ * @param input - Compressed input buffer
573
+ * @param inputOffset - Offset into input buffer
574
+ * @param outSize - Expected output size
575
+ * @param solid - If true, preserve state from previous decode
576
+ * @returns Decompressed data
577
+ */ _proto.decode = function decode(input, inputOffset, outSize) {
578
+ var solid = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
579
+ var output = (0, _extractbaseiterator.allocBufferUnsafe)(outSize);
580
+ this.decodeToBuffer(input, inputOffset, outSize, output, 0, solid);
566
581
  return output;
567
582
  };
568
583
  return LzmaDecoder;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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, bufferFrom } 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 this.streamPos = 0; // Reset streamPos after wrap to track new data from 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 // Use bufferFrom to create a COPY, not a view - the buffer is reused after wrapping\n const chunk = bufferFrom(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 *\n * Note: LZMA1 is a low-level format. @napi-rs/lzma expects self-describing\n * data (like XZ), but here we accept raw LZMA with properties specified separately.\n * Pure JS implementation is used for LZMA1.\n *\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new LzmaDecoder(outputSink as 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":["LzmaDecoder","decodeLzma","LenDecoder","choice","initBitModels","lowCoder","midCoder","highCoder","BitTreeDecoder","numPosStates","create","init","i","decode","rangeDecoder","posState","decodeBit","LiteralDecoder2","decoders","decodeNormal","symbol","decodeWithMatchByte","matchByte","matchBit","bit","LiteralDecoder","numPosBits","numPrevBits","posMask","coders","length","getDecoder","pos","prevByte","index","decoder","OutWindow","sink","buffer","allocBufferUnsafe","windowSize","streamPos","solid","putByte","b","flush","size","chunk","bufferFrom","slice","write","getByte","distance","copyBlock","len","copyTo","output","outputOffset","count","srcPos","firstPart","copy","outputSink","outWindow","RangeDecoder","isMatchDecoders","kNumStates","kNumPosStatesBitsMax","isRepDecoders","isRepG0Decoders","isRepG1Decoders","isRepG2Decoders","isRep0LongDecoders","posSlotDecoder","posDecoders","kNumFullDistances","kEndPosModelIndex","posAlignDecoder","kNumAlignBits","lenDecoder","repLenDecoder","literalDecoder","kNumLenToPosStates","kNumPosSlotBits","dictionarySize","dictionarySizeCheck","posStateMask","state","rep0","rep1","rep2","rep3","totalPos","setDictionarySize","Math","max","setLcLpPb","lc","lp","pb","kNumLitContextBitsMax","setDecoderProperties","properties","props","parseProperties","initProbabilities","resetProbabilities","resetDictionary","feedUncompressed","data","flushOutWindow","decodeWithSink","input","inputOffset","outSize","setInput","outPos","cumPos","decoder2","stateIsCharState","stateUpdateChar","stateUpdateShortRep","kMatchMinLen","stateUpdateRep","stateUpdateMatch","posSlot","getLenToPosState","kStartPosModelIndex","numDirectBits","reverseDecodeFromArray","decodeDirectBits","reverseDecode","Error","bytesWritten"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QA+PYA;eAAAA;;QAsaGC;eAAAA;;;mCAnqB8B;uBAqBvC;8BAC8D;;;;;;AAErE;;CAEC,GACD,IAAA,AAAMC,2BAAN;;aAAMA;gCAAAA;QAQF,IAAI,CAACC,MAAM,GAAGC,IAAAA,sBAAa,EAAC,MAAM;QAClC,IAAI,CAACC,QAAQ,GAAG,EAAE;QAClB,IAAI,CAACC,QAAQ,GAAG,EAAE;QAClB,IAAI,CAACC,SAAS,GAAG,IAAIC,8BAAc,CAAC;QACpC,IAAI,CAACC,YAAY,GAAG;;iBAZlBP;IAeJQ,OAAAA,MAKC,GALDA,SAAAA,OAAOD,YAAoB;QACzB,MAAO,IAAI,CAACA,YAAY,GAAGA,cAAc,IAAI,CAACA,YAAY,GAAI;YAC5D,IAAI,CAACJ,QAAQ,CAAC,IAAI,CAACI,YAAY,CAAC,GAAG,IAAID,8BAAc,CAAC;YACtD,IAAI,CAACF,QAAQ,CAAC,IAAI,CAACG,YAAY,CAAC,GAAG,IAAID,8BAAc,CAAC;QACxD;IACF;IAEAG,OAAAA,IAOC,GAPDA,SAAAA;QACEP,IAAAA,sBAAa,EAAC,IAAI,CAACD,MAAM;QACzB,IAAK,IAAIS,IAAI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Q4E,cAAc,CAACC,OAAO,GAAGE,SAAS;QAC/D/E,QAAQ2E,cAAc;QACtB,OAAOuB;IACT;IACA,kEAAkE;IAClE,OAAOlG,QAAQtB,MAAM,CAACmG,OAAO,GAAGE,SAAS;AAC3C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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, bufferFrom } 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 this.streamPos = 0; // Reset streamPos after wrap to track new data from 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 // Use bufferFrom to create a COPY, not a view - the buffer is reused after wrapping\n const chunk = bufferFrom(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 directly into caller's buffer (zero-copy)\n * @param input - Compressed input buffer\n * @param inputOffset - Offset into input buffer\n * @param outSize - Expected output size\n * @param output - Pre-allocated output buffer to write to\n * @param outputOffset - Offset in output buffer to start writing\n * @param solid - If true, preserve state from previous decode\n * @returns Number of bytes written\n */\n decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: 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 // Solid mode: preserve dictionary state but reinitialize range decoder\n this.outWindow.init(true);\n }\n\n let outPos = outputOffset;\n const outEnd = outputOffset + outSize;\n let cumPos = this.totalPos;\n\n while (outPos < outEnd) {\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 outPos - outputOffset;\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 const output = allocBufferUnsafe(outSize);\n this.decodeToBuffer(input, inputOffset, outSize, output, 0, solid);\n return output;\n }\n}\n\n/**\n * Decode LZMA1 data synchronously\n *\n * Note: LZMA1 is a low-level format. @napi-rs/lzma expects self-describing\n * data (like XZ), but here we accept raw LZMA with properties specified separately.\n * Pure JS implementation is used for LZMA1.\n *\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new LzmaDecoder(outputSink as 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":["LzmaDecoder","decodeLzma","LenDecoder","choice","initBitModels","lowCoder","midCoder","highCoder","BitTreeDecoder","numPosStates","create","init","i","decode","rangeDecoder","posState","decodeBit","LiteralDecoder2","decoders","decodeNormal","symbol","decodeWithMatchByte","matchByte","matchBit","bit","LiteralDecoder","numPosBits","numPrevBits","posMask","coders","length","getDecoder","pos","prevByte","index","decoder","OutWindow","sink","buffer","allocBufferUnsafe","windowSize","streamPos","solid","putByte","b","flush","size","chunk","bufferFrom","slice","write","getByte","distance","copyBlock","len","copyTo","output","outputOffset","count","srcPos","firstPart","copy","outputSink","outWindow","RangeDecoder","isMatchDecoders","kNumStates","kNumPosStatesBitsMax","isRepDecoders","isRepG0Decoders","isRepG1Decoders","isRepG2Decoders","isRep0LongDecoders","posSlotDecoder","posDecoders","kNumFullDistances","kEndPosModelIndex","posAlignDecoder","kNumAlignBits","lenDecoder","repLenDecoder","literalDecoder","kNumLenToPosStates","kNumPosSlotBits","dictionarySize","dictionarySizeCheck","posStateMask","state","rep0","rep1","rep2","rep3","totalPos","setDictionarySize","Math","max","setLcLpPb","lc","lp","pb","kNumLitContextBitsMax","setDecoderProperties","properties","props","parseProperties","initProbabilities","resetProbabilities","resetDictionary","feedUncompressed","data","flushOutWindow","decodeWithSink","input","inputOffset","outSize","setInput","outPos","cumPos","decoder2","stateIsCharState","stateUpdateChar","stateUpdateShortRep","kMatchMinLen","stateUpdateRep","stateUpdateMatch","posSlot","getLenToPosState","kStartPosModelIndex","numDirectBits","reverseDecodeFromArray","decodeDirectBits","reverseDecode","Error","decodeToBuffer","outEnd","bytesWritten"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QA+PYA;eAAAA;;QAsbGC;eAAAA;;;mCAnrB8B;uBAqBvC;8BAC8D;;;;;;AAErE;;CAEC,GACD,IAAA,AAAMC,2BAAN;;aAAMA;gCAAAA;QAQF,IAAI,CAACC,MAAM,GAAGC,IAAAA,sBAAa,EAAC,MAAM;QAClC,IAAI,CAACC,QAAQ,GAAG,EAAE;QAClB,IAAI,CAACC,QAAQ,GAAG,EAAE;QAClB,IAAI,CAACC,SAAS,GAAG,IAAIC,8BAAc,CAAC;QACpC,IAAI,CAACC,YAAY,GAAG;;iBAZlBP;IAeJQ,OAAAA,MAKC,GALDA,SAAAA,OAAOD,YAAoB;QACzB,MAAO,IAAI,CAACA,YAAY,GAAGA,cAAc,IAAI,CAACA,YAAY,GAAI;Y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AS,CAACZ,OAAO,CAAC;YACzC;QACF;QAEA,IAAI,CAACyC,QAAQ,GAAGyB;QAChB,OAAOD,SAAS3D;IAClB;IAEA;;;;;;;GAOC,GACD5C,OAAAA,MAIC,GAJDA,SAAAA,OAAOmG,KAAa,EAAEC,WAAmB,EAAEC,OAAe;YAAExE,QAAAA,iEAAQ;QAClE,IAAMc,SAASjB,IAAAA,sCAAiB,EAAC2E;QACjC,IAAI,CAACmB,cAAc,CAACrB,OAAOC,aAAaC,SAAS1D,QAAQ,GAAGd;QAC5D,OAAOc;IACT;WAtaWxD;;AAsbN,SAASC,WAAW+G,KAAa,EAAEV,UAA+B,EAAEY,OAAe,EAAEpD,UAA4C;IACtI,IAAM3B,UAAU,IAAInC,YAAY8D;IAChC3B,QAAQkE,oBAAoB,CAACC;IAC7B,IAAIxC,YAAY;QACd,8CAA8C;QAC9C,IAAMyE,eAAepG,QAAQ4E,cAAc,CAACC,OAAO,GAAGE,SAAS;QAC/D/E,QAAQ2E,cAAc;QACtB,OAAOyB;IACT;IACA,kEAAkE;IAClE,OAAOpG,QAAQtB,MAAM,CAACmG,OAAO,GAAGE,SAAS;AAC3C"}
@@ -164,14 +164,15 @@ import { LzmaDecoder } from './LzmaDecoder.js';
164
164
  }
165
165
  // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
166
166
  const useSolid = !chunk.stateReset || chunk.stateReset && !chunk.dictReset;
167
- // Decode LZMA chunk
168
- const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
169
- const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
170
- // Copy to output
167
+ // Decode LZMA chunk - use zero-copy when we have pre-allocated buffer
171
168
  if (outputBuffer) {
172
- decoded.copy(outputBuffer, outputPos);
173
- outputPos += decoded.length;
169
+ // Zero-copy: decode directly into caller's buffer
170
+ const bytesWritten = this.lzmaDecoder.decodeToBuffer(input, dataOffset, chunk.uncompSize, outputBuffer, outputPos, useSolid);
171
+ outputPos += bytesWritten;
174
172
  } else {
173
+ // No pre-allocation: decode to new buffer and collect chunks
174
+ const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
175
+ const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
175
176
  outputChunks.push(decoded);
176
177
  }
177
178
  offset = dataOffset + chunk.compSize;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink as 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"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAA0BC,wBAAwB,QAAQ,cAAc;AACxE,SAASC,WAAW,QAAQ,mBAAmB;AAE/C;;CAEC,GACD,OAAO,MAAMC;IAgBX;;GAEC,GACDC,kBAAwB;QACtB,IAAI,CAACC,WAAW,CAACD,eAAe;IAClC;IAEA;;GAEC,GACDE,qBAA2B;QACzB,IAAI,CAACD,WAAW,CAACC,kBAAkB;IACrC;IAEA;;GAEC,GACDC,UAAUC,EAAU,EAAEC,EAAU,EAAEC,EAAU,EAAW;QACrD,OAAO,IAAI,CAACL,WAAW,CAACE,SAAS,CAACC,IAAIC,IAAIC;IAC5C;IAEA;;GAEC,GACDC,iBAAiBC,IAAY,EAAQ;QACnC,IAAI,CAACP,WAAW,CAACM,gBAAgB,CAACC;IACpC;IAEA;;;;;;;GAOC,GACDC,eAAeC,KAAa,EAAEC,MAAc,EAAEC,OAAe,EAAEC,QAAQ,KAAK,EAAU;QACpF,OAAO,IAAI,CAACZ,WAAW,CAACa,MAAM,CAACJ,OAAOC,QAAQC,SAASC;IACzD;IAEA;;;;GAIC,GACDE,eAAeL,KAAa,EAAU;QACpC,IAAIM,aAAa;QACjB,IAAIL,SAAS;QAEb,MAAOA,SAASD,MAAMO,MAAM,CAAE;YAC5B,MAAMC,SAAStB,sBAAsBc,OAAOC;YAE5C,IAAI,CAACO,OAAOC,OAAO,EAAE;gBACnB,MAAM,IAAIC,MAAM;YAClB;YAEA,MAAMC,QAAQH,OAAOG,KAAK;YAE1B,IAAIA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aK,QAAQ1B,MAAM;gBAC7B,OAAO;oBACLsB,aAAaE,IAAI,CAACE;gBACpB;gBAEAhC,SAASiB,aAAaP,MAAMI,QAAQ;YACtC;QACF;QAEA,qDAAqD;QACrD,IAAIY,cAAc;YAChB,OAAOC,YAAYD,aAAapB,MAAM,GAAGoB,aAAaP,KAAK,CAAC,GAAGQ,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,UAA4C;IAC3I,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"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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 - use zero-copy when we have pre-allocated buffer\n if (outputBuffer) {\n // Zero-copy: decode directly into caller's buffer\n const bytesWritten = this.lzmaDecoder.decodeToBuffer(input, dataOffset, chunk.uncompSize, outputBuffer, outputPos, useSolid);\n outputPos += bytesWritten;\n } else {\n // No pre-allocation: decode to new buffer and collect chunks\n const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);\n const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink as 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","bytesWritten","decodeToBuffer","chunkData","decoded","Buffer","concat","properties","outputSink","dictionarySize","setDictionarySize","decodeLzma2","decoder"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAA0BC,wBAAwB,QAAQ,cAAc;AACxE,SAASC,WAAW,QAAQ,mBAAmB;AAE/C;;CAEC,GACD,OAA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AcA,WAAW/B,MAAM,GAAG,GAAG;YACxC,MAAM,IAAIG,MAAM;QAClB;QAEA,IAAI,CAAC8B,cAAc,GAAGrD,yBAAyBmD,UAAU,CAAC,EAAE;QAC5D,IAAI,CAAC/C,WAAW,GAAG,IAAIH,YAAYmD;QACnC,IAAI,CAAChD,WAAW,CAACkD,iBAAiB,CAAC,IAAI,CAACD,cAAc;QACtD,IAAI,CAAClB,QAAQ,GAAG;IAClB;AAmOF;AAEA;;;;;;;CAOC,GACD,OAAO,SAASoB,YAAY1C,KAAa,EAAEsC,UAA+B,EAAEZ,UAAmB,EAAEa,UAA4C;IAC3I,MAAMI,UAAU,IAAItD,aAAaiD,YAAYC;IAC7C,IAAIA,YAAY;QACd,8CAA8C;QAC9C,OAAOI,QAAQtC,cAAc,CAACL;IAChC;IACA,6CAA6C;IAC7C,OAAO2C,QAAQvC,MAAM,CAACJ,OAAO0B;AAC/B"}
@@ -76,6 +76,17 @@ export declare class LzmaDecoder {
76
76
  * @returns Number of bytes written to sink
77
77
  */
78
78
  decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
79
+ /**
80
+ * Decode LZMA data directly into caller's buffer (zero-copy)
81
+ * @param input - Compressed input buffer
82
+ * @param inputOffset - Offset into input buffer
83
+ * @param outSize - Expected output size
84
+ * @param output - Pre-allocated output buffer to write to
85
+ * @param outputOffset - Offset in output buffer to start writing
86
+ * @param solid - If true, preserve state from previous decode
87
+ * @returns Number of bytes written
88
+ */
89
+ decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: number, solid?: boolean): number;
79
90
  /**
80
91
  * Decode LZMA data
81
92
  * @param input - Compressed input buffer
@@ -383,13 +383,15 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
383
383
  return outPos;
384
384
  }
385
385
  /**
386
- * Decode LZMA data
386
+ * Decode LZMA data directly into caller's buffer (zero-copy)
387
387
  * @param input - Compressed input buffer
388
388
  * @param inputOffset - Offset into input buffer
389
389
  * @param outSize - Expected output size
390
+ * @param output - Pre-allocated output buffer to write to
391
+ * @param outputOffset - Offset in output buffer to start writing
390
392
  * @param solid - If true, preserve state from previous decode
391
- * @returns Decompressed data
392
- */ decode(input, inputOffset, outSize, solid = false) {
393
+ * @returns Number of bytes written
394
+ */ decodeToBuffer(input, inputOffset, outSize, output, outputOffset, solid = false) {
393
395
  this.rangeDecoder.setInput(input, inputOffset);
394
396
  if (!solid) {
395
397
  this.outWindow.init(false);
@@ -405,10 +407,10 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
405
407
  // Solid mode: preserve dictionary state but reinitialize range decoder
406
408
  this.outWindow.init(true);
407
409
  }
408
- const output = allocBufferUnsafe(outSize);
409
- let outPos = 0;
410
+ let outPos = outputOffset;
411
+ const outEnd = outputOffset + outSize;
410
412
  let cumPos = this.totalPos;
411
- while(outPos < outSize){
413
+ while(outPos < outEnd){
412
414
  const posState = cumPos & this.posStateMask;
413
415
  if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {
414
416
  // Literal
@@ -492,6 +494,18 @@ import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDec
492
494
  }
493
495
  }
494
496
  this.totalPos = cumPos;
497
+ return outPos - outputOffset;
498
+ }
499
+ /**
500
+ * Decode LZMA data
501
+ * @param input - Compressed input buffer
502
+ * @param inputOffset - Offset into input buffer
503
+ * @param outSize - Expected output size
504
+ * @param solid - If true, preserve state from previous decode
505
+ * @returns Decompressed data
506
+ */ decode(input, inputOffset, outSize, solid = false) {
507
+ const output = allocBufferUnsafe(outSize);
508
+ this.decodeToBuffer(input, inputOffset, outSize, output, 0, solid);
495
509
  return output;
496
510
  }
497
511
  constructor(outputSink){
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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, bufferFrom } 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 this.streamPos = 0; // Reset streamPos after wrap to track new data from 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 // Use bufferFrom to create a COPY, not a view - the buffer is reused after wrapping\n const chunk = bufferFrom(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 *\n * Note: LZMA1 is a low-level format. @napi-rs/lzma expects self-describing\n * data (like XZ), but here we accept raw LZMA with properties specified separately.\n * Pure JS implementation is used for LZMA1.\n *\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new LzmaDecoder(outputSink as 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","bufferFrom","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,EAAEC,UAAU,QAAQ,wBAAwB;AACtE,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,QAAQ,CAAC,IAAI,CAACF,YAAY,CAAC,GAAG,IAAIL,eAAe;QACxD;IACF;IAEAQ,OAAa;QACXzB,cAAc,IAAI,CAAC0B,MAAM;QACzB,IAAK,IAAIC,IAAI,IAAI,CAACL,YAAY,GAAG,GAAGK,KAAK,GAAGA,IAAK;YAC/C,IAAI,CAACJ,QAAQ,CAACI,EAAE,CAACF,IAAI;YACrB,IAAI,CAACD,QAAQ,CAACG,EAAE,CAACF,IAAI;QACvB;QACA,IAAI,CAACG,SAAS,CAACH,IAAI;IACrB;IAEAI,OAAOC,YAA0B,EAAEC,QAAgB,EAAU;QAC3D,IAAID,aAAaE,SAAS,CAAC,IAAI,CAACN,MAAM,EAAE,OAAO,GAAG;YAChD,OAAO,IAAI,CAACH,QAAQ,CA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AAGE,SAAS;AAC3C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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, bufferFrom } 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 this.streamPos = 0; // Reset streamPos after wrap to track new data from 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 // Use bufferFrom to create a COPY, not a view - the buffer is reused after wrapping\n const chunk = bufferFrom(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 directly into caller's buffer (zero-copy)\n * @param input - Compressed input buffer\n * @param inputOffset - Offset into input buffer\n * @param outSize - Expected output size\n * @param output - Pre-allocated output buffer to write to\n * @param outputOffset - Offset in output buffer to start writing\n * @param solid - If true, preserve state from previous decode\n * @returns Number of bytes written\n */\n decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: 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 // Solid mode: preserve dictionary state but reinitialize range decoder\n this.outWindow.init(true);\n }\n\n let outPos = outputOffset;\n const outEnd = outputOffset + outSize;\n let cumPos = this.totalPos;\n\n while (outPos < outEnd) {\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 outPos - outputOffset;\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 const output = allocBufferUnsafe(outSize);\n this.decodeToBuffer(input, inputOffset, outSize, output, 0, solid);\n return output;\n }\n}\n\n/**\n * Decode LZMA1 data synchronously\n *\n * Note: LZMA1 is a low-level format. @napi-rs/lzma expects self-describing\n * data (like XZ), but here we accept raw LZMA with properties specified separately.\n * Pure JS implementation is used for LZMA1.\n *\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new LzmaDecoder(outputSink as 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","bufferFrom","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","decodeToBuffer","outEnd","outputSink","decodeLzma","bytesWritten"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,iBAAiB,EAAEC,UAAU,QAAQ,wBAAwB;AACtE,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,Q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AAE,GAAG,IAAIV,eAAeV;QAC9C;QAEA,IAAI,CAACuE,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,CAAC5D,QAAQ,GAAG;QAChB,IAAI,CAAC8D,QAAQ,GAAG;IAClB;AAuWF;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASoB,WAAWf,KAAa,EAAExB,UAA+B,EAAE0B,OAAe,EAAEY,UAA4C;IACtI,MAAM/E,UAAU,IAAIyB,YAAYsD;IAChC/E,QAAQwC,oBAAoB,CAACC;IAC7B,IAAIsC,YAAY;QACd,8CAA8C;QAC9C,MAAME,eAAejF,QAAQgE,cAAc,CAACC,OAAO,GAAGE,SAAS;QAC/DnE,QAAQ+D,cAAc;QACtB,OAAOkB;IACT;IACA,kEAAkE;IAClE,OAAOjF,QAAQtB,MAAM,CAACuF,OAAO,GAAGE,SAAS;AAC3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xz-compat",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "XZ Decompression Library",
5
5
  "keywords": [
6
6
  "extract",