xz-compat 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/cjs/lzma/lib/Lzma2ChunkParser.js.map +1 -0
  2. package/dist/cjs/lzma/stream/transforms.js +18 -6
  3. package/dist/cjs/lzma/stream/transforms.js.map +1 -1
  4. package/dist/cjs/lzma/sync/Lzma2Decoder.js +11 -7
  5. package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -1
  6. package/dist/cjs/native.d.cts +0 -3
  7. package/dist/cjs/native.d.ts +0 -3
  8. package/dist/cjs/native.js +13 -66
  9. package/dist/cjs/native.js.map +1 -1
  10. package/dist/cjs/sevenz.js +11 -8
  11. package/dist/cjs/sevenz.js.map +1 -1
  12. package/dist/cjs/xz/Decoder.js +5 -11
  13. package/dist/cjs/xz/Decoder.js.map +1 -1
  14. package/dist/esm/lzma/lib/Lzma2ChunkParser.js.map +1 -0
  15. package/dist/esm/lzma/stream/transforms.js +18 -6
  16. package/dist/esm/lzma/stream/transforms.js.map +1 -1
  17. package/dist/esm/lzma/sync/Lzma2Decoder.js +11 -7
  18. package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -1
  19. package/dist/esm/native.d.ts +0 -3
  20. package/dist/esm/native.js +15 -70
  21. package/dist/esm/native.js.map +1 -1
  22. package/dist/esm/sevenz.js +11 -8
  23. package/dist/esm/sevenz.js.map +1 -1
  24. package/dist/esm/xz/Decoder.js +5 -11
  25. package/dist/esm/xz/Decoder.js.map +1 -1
  26. package/package.json +1 -1
  27. package/dist/cjs/lzma/Lzma2ChunkParser.js.map +0 -1
  28. package/dist/esm/lzma/Lzma2ChunkParser.js.map +0 -1
  29. /package/dist/cjs/lzma/{Lzma2ChunkParser.d.cts → lib/Lzma2ChunkParser.d.cts} +0 -0
  30. /package/dist/cjs/lzma/{Lzma2ChunkParser.d.ts → lib/Lzma2ChunkParser.d.ts} +0 -0
  31. /package/dist/cjs/lzma/{Lzma2ChunkParser.js → lib/Lzma2ChunkParser.js} +0 -0
  32. /package/dist/esm/lzma/{Lzma2ChunkParser.d.ts → lib/Lzma2ChunkParser.d.ts} +0 -0
  33. /package/dist/esm/lzma/{Lzma2ChunkParser.js → lib/Lzma2ChunkParser.js} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/lzma/lib/Lzma2ChunkParser.ts"],"sourcesContent":["/**\n * LZMA2 Chunk Parser\n *\n * Shared parsing logic for LZMA2 chunk headers.\n * Used by both synchronous and streaming decoders.\n *\n * LZMA2 control byte ranges:\n * 0x00 = End of stream\n * 0x01 = Uncompressed chunk, dictionary reset\n * 0x02 = Uncompressed chunk, no dictionary reset\n * 0x80-0x9F = LZMA chunk, no reset (solid mode)\n * 0xA0-0xBF = LZMA chunk, reset state (probabilities)\n * 0xC0-0xDF = LZMA chunk, reset state + new properties\n * 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties\n */\n\n/**\n * LZMA properties extracted from chunk header\n */\nexport interface LzmaChunkProps {\n lc: number;\n lp: number;\n pb: number;\n}\n\n/**\n * Parsed LZMA2 chunk information\n */\nexport interface Lzma2Chunk {\n /** Chunk type */\n type: 'end' | 'uncompressed' | 'lzma';\n /** Total bytes consumed by header (including control byte) */\n headerSize: number;\n /** Whether to reset dictionary */\n dictReset: boolean;\n /** Whether to reset state/probabilities */\n stateReset: boolean;\n /** New LZMA properties (only for control >= 0xC0) */\n newProps: LzmaChunkProps | null;\n /** Uncompressed data size */\n uncompSize: number;\n /** Compressed data size (0 for uncompressed chunks) */\n compSize: number;\n}\n\n/**\n * Result of parsing attempt\n */\nexport type ParseResult = { success: true; chunk: Lzma2Chunk } | { success: false; needBytes: number };\n\n/**\n * Parse an LZMA2 chunk header\n *\n * @param input - Input buffer\n * @param offset - Offset to start parsing\n * @returns Parsed chunk info or number of bytes needed\n */\nexport function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult {\n if (offset >= input.length) {\n return { success: false, needBytes: 1 };\n }\n\n const control = input[offset];\n\n // End of stream\n if (control === 0x00) {\n return {\n success: true,\n chunk: {\n type: 'end',\n headerSize: 1,\n dictReset: false,\n stateReset: false,\n newProps: null,\n uncompSize: 0,\n compSize: 0,\n },\n };\n }\n\n // Uncompressed chunk\n if (control === 0x01 || control === 0x02) {\n // Need 3 bytes: control + 2 size bytes\n if (offset + 3 > input.length) {\n return { success: false, needBytes: 3 - (input.length - offset) };\n }\n\n const uncompSize = ((input[offset + 1] << 8) | input[offset + 2]) + 1;\n\n return {\n success: true,\n chunk: {\n type: 'uncompressed',\n headerSize: 3,\n dictReset: control === 0x01,\n stateReset: false,\n newProps: null,\n uncompSize,\n compSize: 0,\n },\n };\n }\n\n // LZMA compressed chunk\n if (control >= 0x80) {\n const hasNewProps = control >= 0xc0;\n const minHeaderSize = hasNewProps ? 6 : 5; // control + 2 uncomp + 2 comp + (1 props)\n\n if (offset + minHeaderSize > input.length) {\n return { success: false, needBytes: minHeaderSize - (input.length - offset) };\n }\n\n // Parse sizes\n const uncompHigh = control & 0x1f;\n const uncompSize = ((uncompHigh << 16) | (input[offset + 1] << 8) | input[offset + 2]) + 1;\n const compSize = ((input[offset + 3] << 8) | input[offset + 4]) + 1;\n\n // Parse properties if present\n let newProps: LzmaChunkProps | null = null;\n if (hasNewProps) {\n const propsByte = input[offset + 5];\n const lc = propsByte % 9;\n const remainder = ~~(propsByte / 9);\n const lp = remainder % 5;\n const pb = ~~(remainder / 5);\n newProps = { lc, lp, pb };\n }\n\n return {\n success: true,\n chunk: {\n type: 'lzma',\n headerSize: minHeaderSize,\n dictReset: control >= 0xe0,\n stateReset: control >= 0xa0,\n newProps,\n uncompSize,\n compSize,\n },\n };\n }\n\n // Invalid control byte\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n}\n\n/** Result type for hasCompleteChunk with totalSize included on success */\nexport type CompleteChunkResult = { success: true; chunk: Lzma2Chunk; totalSize: number } | { success: false; needBytes: number };\n\n/**\n * Check if we have enough data for the complete chunk (header + data)\n */\nexport function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (result.success === false) {\n return { success: false, needBytes: result.needBytes };\n }\n\n const { chunk } = result;\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n const totalSize = chunk.headerSize + dataSize;\n\n if (offset + totalSize > input.length) {\n return { success: false, needBytes: totalSize - (input.length - offset) };\n }\n\n return { success: true, chunk, totalSize };\n}\n"],"names":["hasCompleteChunk","parseLzma2ChunkHeader","input","offset","length","success","needBytes","control","chunk","type","headerSize","dictReset","stateReset","newProps","uncompSize","compSize","hasNewProps","minHeaderSize","uncompHigh","propsByte","lc","remainder","lp","pb","Error","toString","result","dataSize","totalSize"],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GAED;;CAEC;;;;;;;;;;;QAsIeA;eAAAA;;QA/FAC;eAAAA;;;AAAT,SAASA,sBAAsBC,KAAa,EAAEC,MAAc;IACjE,IAAIA,UAAUD,MAAME,MAAM,EAAE;QAC1B,OAAO;YAAEC,SAAS;YAAOC,WAAW;QAAE;IACxC;IAEA,IAAMC,UAAUL,KAAK,CAACC,OAAO;IAE7B,gBAAgB;IAChB,IAAII,YAAY,MAAM;QACpB,OAAO;YACLF,SAAS;YACTG,OAAO;gBACLC,MAAM;gBACNC,YAAY;gBACZC,WAAW;gBACXC,YAAY;gBACZC,UAAU;gBACVC,YAAY;gBACZC,UAAU;YACZ;QACF;IACF;IAEA,qBAAqB;IACrB,IAAIR,YAAY,QAAQA,YAAY,MAAM;QACxC,uCAAuC;QACvC,IAAIJ,SAAS,IAAID,MAAME,MAAM,EAAE;YAC7B,OAAO;gBAAEC,SAAS;gBAAOC,WAAW,IAAKJ,CAAAA,MAAME,MAAM,GAAGD,MAAK;YAAG;QAClE;QAEA,IAAMW,aAAa,AAAC,CAAA,AAACZ,KA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BACAC,UAAAA;YACF;QACF;IACF;IAEA,uBAAuB;IACvB,MAAM,IAAIS,MAAM,AAAC,iCAAqD,OAArBjB,QAAQkB,QAAQ,CAAC;AACpE;AAQO,SAASzB,iBAAiBE,KAAa,EAAEC,MAAc;IAC5D,IAAMuB,SAASzB,sBAAsBC,OAAOC;IAE5C,IAAIuB,OAAOrB,OAAO,KAAK,OAAO;QAC5B,OAAO;YAAEA,SAAS;YAAOC,WAAWoB,OAAOpB,SAAS;QAAC;IACvD;IAEA,IAAM,AAAEE,QAAUkB,OAAVlB;IACR,IAAMmB,WAAWnB,MAAMC,IAAI,KAAK,iBAAiBD,MAAMM,UAAU,GAAGN,MAAMO,QAAQ;IAClF,IAAMa,YAAYpB,MAAME,UAAU,GAAGiB;IAErC,IAAIxB,SAASyB,YAAY1B,MAAME,MAAM,EAAE;QACrC,OAAO;YAAEC,SAAS;YAAOC,WAAWsB,YAAa1B,CAAAA,MAAME,MAAM,GAAGD,MAAK;QAAG;IAC1E;IAEA,OAAO;QAAEE,SAAS;QAAMG,OAAAA;QAAOoB,WAAAA;IAAU;AAC3C"}
@@ -34,7 +34,7 @@ _export(exports, {
34
34
  }
35
35
  });
36
36
  var _extractbaseiterator = require("extract-base-iterator");
37
- var _Lzma2ChunkParserts = require("../Lzma2ChunkParser.js");
37
+ var _Lzma2ChunkParserts = require("../lib/Lzma2ChunkParser.js");
38
38
  var _LzmaDecoderts = require("../sync/LzmaDecoder.js");
39
39
  var _typests = require("../types.js");
40
40
  function createLzma2Decoder(properties) {
@@ -47,6 +47,10 @@ function createLzma2Decoder(properties) {
47
47
  decoder.setDictionarySize(dictSize);
48
48
  // Track current LZMA properties
49
49
  var propsSet = false;
50
+ // Store lc/lp/pb for reuse in stream decoder
51
+ var currentLc;
52
+ var currentLp;
53
+ var currentPb;
50
54
  // Buffer for incomplete chunk data
51
55
  var pending = null;
52
56
  var finished = false;
@@ -102,13 +106,19 @@ function createLzma2Decoder(properties) {
102
106
  if (chunkInfo.newProps) {
103
107
  var ref;
104
108
  ref = chunkInfo.newProps, lc = ref.lc, lp = ref.lp, pb = ref.pb, ref;
109
+ // Store properties for reuse in stream decoder
110
+ currentLc = lc;
111
+ currentLp = lp;
112
+ currentPb = pb;
105
113
  if (!decoder.setLcLpPb(lc, lp, pb)) {
106
114
  throw new Error("Invalid LZMA properties: lc=".concat(lc, " lp=").concat(lp, " pb=").concat(pb));
107
115
  }
108
116
  propsSet = true;
109
- }
110
- if (!propsSet) {
111
- throw new Error('LZMA chunk without properties');
117
+ } else {
118
+ // No new properties, check if we already have them
119
+ if (!propsSet) {
120
+ throw new Error('LZMA chunk without properties');
121
+ }
112
122
  }
113
123
  // Reset probabilities if state reset
114
124
  if (chunkInfo.stateReset) {
@@ -125,8 +135,10 @@ function createLzma2Decoder(properties) {
125
135
  }
126
136
  });
127
137
  streamDecoder.setDictionarySize(dictSize);
128
- // Preserve properties from main decoder
129
- streamDecoder.setLcLpPb(lc, lp, pb);
138
+ // Set properties from current values (from first chunk or newProps)
139
+ if (currentLc !== undefined && currentLp !== undefined && currentPb !== undefined) {
140
+ streamDecoder.setLcLpPb(currentLc, currentLp, currentPb);
141
+ }
130
142
  // Use solid mode based on chunk properties
131
143
  streamDecoder.decodeWithSink(compData, 0, chunkInfo.uncompSize, useSolid);
132
144
  // Flush any remaining data in the OutWindow
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/lzma/stream/transforms.ts"],"sourcesContent":["/**\n * LZMA Transform Stream Wrappers\n *\n * Provides Transform streams for LZMA1 and LZMA2 decompression.\n *\n * LZMA2 streaming works by buffering until a complete chunk is available,\n * then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max\n * uncompressed), so memory usage is predictable and bounded.\n *\n * Performance Optimization:\n * - Uses OutputSink pattern for zero-copy output during decode\n * - Each decoded byte written directly to stream (not buffered then copied)\n * - ~4x faster than previous buffering approach\n *\n * True byte-by-byte async LZMA streaming would require rewriting the entire\n * decoder with continuation-passing style, which is complex and not worth\n * the effort given LZMA2's chunked format.\n */\n\nimport { allocBufferUnsafe, Transform } from 'extract-base-iterator';\nimport { hasCompleteChunk } from '../Lzma2ChunkParser.ts';\nimport { LzmaDecoder } from '../sync/LzmaDecoder.ts';\nimport { parseLzma2DictionarySize } from '../types.ts';\n\n/**\n * Create an LZMA2 decoder Transform stream\n *\n * This is a streaming decoder that processes LZMA2 chunks incrementally.\n * Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).\n *\n * @param properties - 1-byte LZMA2 properties (dictionary size)\n * @returns Transform stream that decompresses LZMA2 data\n */\nexport function createLzma2Decoder(properties: Buffer | Uint8Array): InstanceType<typeof Transform> {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = parseLzma2DictionarySize(properties[0]);\n\n // LZMA decoder instance - reused across chunks for solid mode\n const decoder = new LzmaDecoder();\n decoder.setDictionarySize(dictSize);\n\n // Track current LZMA properties\n let propsSet = false;\n\n // Buffer for incomplete chunk data\n let pending: Buffer | null = null;\n let finished = false;\n\n return new Transform({\n transform: function (this: InstanceType<typeof Transform>, chunk: Buffer, _encoding: string, callback: (err?: Error | null) => void) {\n if (finished) {\n callback(null);\n return;\n }\n\n // Combine with pending data\n let input: Buffer;\n if (pending && pending.length > 0) {\n input = Buffer.concat([pending, chunk]);\n pending = null;\n } else {\n input = chunk;\n }\n\n let offset = 0;\n\n try {\n while (offset < input.length && !finished) {\n const result = hasCompleteChunk(input, offset);\n\n if (!result.success) {\n // Need more data\n pending = input.slice(offset);\n break;\n }\n\n const { chunk: chunkInfo, totalSize } = result;\n\n if (chunkInfo.type === 'end') {\n finished = true;\n break;\n }\n\n // Handle dictionary reset\n if (chunkInfo.dictReset) {\n decoder.resetDictionary();\n }\n\n const dataOffset = offset + chunkInfo.headerSize;\n\n if (chunkInfo.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunkInfo.uncompSize);\n this.push(uncompData);\n\n // Feed uncompressed data to dictionary for subsequent LZMA chunks\n decoder.feedUncompressed(uncompData);\n } else {\n // LZMA compressed chunk\n\n // Variables to store properties (used for both decoders)\n let lc: number;\n let lp: number;\n let pb: number;\n\n // Apply new properties if present\n if (chunkInfo.newProps) {\n ({ lc, lp, pb } = chunkInfo.newProps);\n if (!decoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n propsSet = true;\n }\n\n if (!propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n // Reset probabilities if state reset\n if (chunkInfo.stateReset) {\n decoder.resetProbabilities();\n }\n\n // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)\n const useSolid = !chunkInfo.stateReset || (chunkInfo.stateReset && !chunkInfo.dictReset);\n\n const compData = input.slice(dataOffset, dataOffset + chunkInfo.compSize);\n\n // Enhanced: Use OutputSink for direct emission (zero-copy)\n // Create a decoder with direct stream emission\n const streamDecoder = new LzmaDecoder({\n write: (chunk: Buffer) => this.push(chunk),\n });\n streamDecoder.setDictionarySize(dictSize);\n // Preserve properties from main decoder\n streamDecoder.setLcLpPb(lc, lp, pb);\n\n // Use solid mode based on chunk properties\n streamDecoder.decodeWithSink(compData, 0, chunkInfo.uncompSize, useSolid);\n\n // Flush any remaining data in the OutWindow\n streamDecoder.flushOutWindow();\n }\n\n offset += totalSize;\n }\n\n callback(null);\n } catch (err) {\n callback(err as Error);\n }\n },\n\n flush: function (this: InstanceType<typeof Transform>, callback: (err?: Error | null) => void) {\n if (pending && pending.length > 0 && !finished) {\n callback(new Error('Truncated LZMA2 stream'));\n } else {\n callback(null);\n }\n },\n });\n}\n\n/**\n * Create an LZMA1 decoder Transform stream\n *\n * Note: LZMA1 has no chunk boundaries, so this requires knowing the\n * uncompressed size upfront. The stream buffers all input, then\n * decompresses when complete.\n *\n * For true streaming, use LZMA2 which has built-in chunking.\n *\n * Optimization: Pre-allocates input buffer and copies chunks once,\n * avoiding the double-buffering of Buffer.concat().\n *\n * @param properties - 5-byte LZMA properties\n * @param unpackSize - Expected uncompressed size\n * @returns Transform stream that decompresses LZMA1 data\n */\nexport function createLzmaDecoder(properties: Buffer | Uint8Array, unpackSize: number): InstanceType<typeof Transform> {\n const decoder = new LzmaDecoder();\n decoder.setDecoderProperties(properties);\n\n const chunks: Buffer[] = [];\n let totalSize = 0;\n\n return new Transform({\n transform: function (this: InstanceType<typeof Transform>, chunk: Buffer, _encoding: string, callback: (err?: Error | null) => void) {\n chunks.push(chunk);\n totalSize += chunk.length;\n callback(null);\n },\n\n flush: function (this: InstanceType<typeof Transform>, callback: (err?: Error | null) => void) {\n try {\n // Optimization: Pre-allocate single buffer instead of Buffer.concat()\n // This reduces peak memory usage by ~50% during concatenation\n const input = allocBufferUnsafe(totalSize);\n let offset = 0;\n\n // Copy each chunk into the pre-allocated buffer\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n chunk.copy(input, offset);\n offset += chunk.length;\n }\n\n // Enhanced: Use OutputSink for direct emission (zero-copy)\n // Create a decoder with direct stream emission\n const streamDecoder = new LzmaDecoder({\n write: (chunk: Buffer) => this.push(chunk),\n });\n streamDecoder.setDecoderProperties(properties);\n streamDecoder.decodeWithSink(input, 0, unpackSize, false);\n\n // Flush any remaining data in the OutWindow\n streamDecoder.flushOutWindow();\n\n callback(null);\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["createLzma2Decoder","createLzmaDecoder","properties","length","Error","dictSize","parseLzma2DictionarySize","decoder","LzmaDecoder","setDictionarySize","propsSet","pending","finished","Transform","transform","chunk","_encoding","callback","input","Buffer","concat","offset","result","hasCompleteChunk","success","slice","chunkInfo","totalSize","type","dictReset","resetDictionary","dataOffset","headerSize","uncompData","uncompSize","push","feedUncompressed","lc","lp","pb","newProps","setLcLpPb","stateReset","resetProbabilities","useSolid","compData","compSize","streamDecoder","write","decodeWithSink","flushOutWindow","err","flush","unpackSize","setDecoderProperties","chunks","all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ACAgC,cAAcO,oBAAoB,CAACpD;gBACnC6C,cAAcE,cAAc,CAAC/B,OAAO,GAAGmC,YAAY;gBAEnD,4CAA4C;gBAC5CN,cAAcG,cAAc;gBAE5BjC,SAAS;YACX,EAAE,OAAOkC,KAAK;gBACZlC,SAASkC;YACX;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/lzma/stream/transforms.ts"],"sourcesContent":["/**\n * LZMA Transform Stream Wrappers\n *\n * Provides Transform streams for LZMA1 and LZMA2 decompression.\n *\n * LZMA2 streaming works by buffering until a complete chunk is available,\n * then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max\n * uncompressed), so memory usage is predictable and bounded.\n *\n * Performance Optimization:\n * - Uses OutputSink pattern for zero-copy output during decode\n * - Each decoded byte written directly to stream (not buffered then copied)\n * - ~4x faster than previous buffering approach\n *\n * True byte-by-byte async LZMA streaming would require rewriting the entire\n * decoder with continuation-passing style, which is complex and not worth\n * the effort given LZMA2's chunked format.\n */\n\nimport { allocBufferUnsafe, Transform } from 'extract-base-iterator';\nimport { hasCompleteChunk } from '../lib/Lzma2ChunkParser.ts';\nimport { LzmaDecoder } from '../sync/LzmaDecoder.ts';\nimport { parseLzma2DictionarySize } from '../types.ts';\n\n/**\n * Create an LZMA2 decoder Transform stream\n *\n * This is a streaming decoder that processes LZMA2 chunks incrementally.\n * Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).\n *\n * @param properties - 1-byte LZMA2 properties (dictionary size)\n * @returns Transform stream that decompresses LZMA2 data\n */\nexport function createLzma2Decoder(properties: Buffer | Uint8Array): InstanceType<typeof Transform> {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = parseLzma2DictionarySize(properties[0]);\n\n // LZMA decoder instance - reused across chunks for solid mode\n const decoder = new LzmaDecoder();\n decoder.setDictionarySize(dictSize);\n\n // Track current LZMA properties\n let propsSet = false;\n\n // Store lc/lp/pb for reuse in stream decoder\n let currentLc: number | undefined;\n let currentLp: number | undefined;\n let currentPb: number | undefined;\n\n // Buffer for incomplete chunk data\n let pending: Buffer | null = null;\n let finished = false;\n\n return new Transform({\n transform: function (this: InstanceType<typeof Transform>, chunk: Buffer, _encoding: string, callback: (err?: Error | null) => void) {\n if (finished) {\n callback(null);\n return;\n }\n\n // Combine with pending data\n let input: Buffer;\n if (pending && pending.length > 0) {\n input = Buffer.concat([pending, chunk]);\n pending = null;\n } else {\n input = chunk;\n }\n\n let offset = 0;\n\n try {\n while (offset < input.length && !finished) {\n const result = hasCompleteChunk(input, offset);\n\n if (!result.success) {\n // Need more data\n pending = input.slice(offset);\n break;\n }\n\n const { chunk: chunkInfo, totalSize } = result;\n\n if (chunkInfo.type === 'end') {\n finished = true;\n break;\n }\n\n // Handle dictionary reset\n if (chunkInfo.dictReset) {\n decoder.resetDictionary();\n }\n\n const dataOffset = offset + chunkInfo.headerSize;\n\n if (chunkInfo.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunkInfo.uncompSize);\n this.push(uncompData);\n\n // Feed uncompressed data to dictionary for subsequent LZMA chunks\n decoder.feedUncompressed(uncompData);\n } else {\n // LZMA compressed chunk\n\n // Variables to store properties (used for both decoders)\n let lc: number;\n let lp: number;\n let pb: number;\n\n // Apply new properties if present\n if (chunkInfo.newProps) {\n ({ lc, lp, pb } = chunkInfo.newProps);\n // Store properties for reuse in stream decoder\n currentLc = lc;\n currentLp = lp;\n currentPb = pb;\n if (!decoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n propsSet = true;\n } else {\n // No new properties, check if we already have them\n if (!propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n }\n\n // Reset probabilities if state reset\n if (chunkInfo.stateReset) {\n decoder.resetProbabilities();\n }\n\n // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)\n const useSolid = !chunkInfo.stateReset || (chunkInfo.stateReset && !chunkInfo.dictReset);\n\n const compData = input.slice(dataOffset, dataOffset + chunkInfo.compSize);\n\n // Enhanced: Use OutputSink for direct emission (zero-copy)\n // Create a decoder with direct stream emission\n const streamDecoder = new LzmaDecoder({\n write: (chunk: Buffer) => this.push(chunk),\n });\n streamDecoder.setDictionarySize(dictSize);\n // Set properties from current values (from first chunk or newProps)\n if (currentLc !== undefined && currentLp !== undefined && currentPb !== undefined) {\n streamDecoder.setLcLpPb(currentLc, currentLp, currentPb);\n }\n\n // Use solid mode based on chunk properties\n streamDecoder.decodeWithSink(compData, 0, chunkInfo.uncompSize, useSolid);\n\n // Flush any remaining data in the OutWindow\n streamDecoder.flushOutWindow();\n }\n\n offset += totalSize;\n }\n\n callback(null);\n } catch (err) {\n callback(err as Error);\n }\n },\n\n flush: function (this: InstanceType<typeof Transform>, callback: (err?: Error | null) => void) {\n if (pending && pending.length > 0 && !finished) {\n callback(new Error('Truncated LZMA2 stream'));\n } else {\n callback(null);\n }\n },\n });\n}\n\n/**\n * Create an LZMA1 decoder Transform stream\n *\n * Note: LZMA1 has no chunk boundaries, so this requires knowing the\n * uncompressed size upfront. The stream buffers all input, then\n * decompresses when complete.\n *\n * For true streaming, use LZMA2 which has built-in chunking.\n *\n * Optimization: Pre-allocates input buffer and copies chunks once,\n * avoiding the double-buffering of Buffer.concat().\n *\n * @param properties - 5-byte LZMA properties\n * @param unpackSize - Expected uncompressed size\n * @returns Transform stream that decompresses LZMA1 data\n */\nexport function createLzmaDecoder(properties: Buffer | Uint8Array, unpackSize: number): InstanceType<typeof Transform> {\n const decoder = new LzmaDecoder();\n decoder.setDecoderProperties(properties);\n\n const chunks: Buffer[] = [];\n let totalSize = 0;\n\n return new Transform({\n transform: function (this: InstanceType<typeof Transform>, chunk: Buffer, _encoding: string, callback: (err?: Error | null) => void) {\n chunks.push(chunk);\n totalSize += chunk.length;\n callback(null);\n },\n\n flush: function (this: InstanceType<typeof Transform>, callback: (err?: Error | null) => void) {\n try {\n // Optimization: Pre-allocate single buffer instead of Buffer.concat()\n // This reduces peak memory usage by ~50% during concatenation\n const input = allocBufferUnsafe(totalSize);\n let offset = 0;\n\n // Copy each chunk into the pre-allocated buffer\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n chunk.copy(input, offset);\n offset += chunk.length;\n }\n\n // Enhanced: Use OutputSink for direct emission (zero-copy)\n // Create a decoder with direct stream emission\n const streamDecoder = new LzmaDecoder({\n write: (chunk: Buffer) => this.push(chunk),\n });\n streamDecoder.setDecoderProperties(properties);\n streamDecoder.decodeWithSink(input, 0, unpackSize, false);\n\n // Flush any remaining data in the OutWindow\n streamDecoder.flushOutWindow();\n\n callback(null);\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["createLzma2Decoder","createLzmaDecoder","properties","length","Error","dictSize","parseLzma2DictionarySize","decoder","LzmaDecoder","setDictionarySize","propsSet","currentLc","currentLp","currentPb","pending","finished","Transform","transform","chunk","_encoding","callback","input","Buffer","concat","offset","result","hasCompleteChunk","success","slice","chunkInfo","totalSize","type","dictReset","resetDictionary","dataOffset","headerSize","uncompData","uncompSize","push","feedUncompressed","lc","lp","pb","newProps","setLcLpPb","stateReset","resetProbabilities","useSolid","compData","compSize","streamDecoder","write","undefined","decodeWithSink","flushOutWindow","err","flush","unpackSize","setDecoderProperties","chunks","allocBufferUnsafe","i","copy"],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC;;;;;;;;;;;QAgBeA;eAAAA;;QAgKAC;eAAAA;;;mCA9K6B;kCACZ;6BACL;uBACa;AAWlC,SAASD,mBAAmBE,UAA+B;IAChE,IAAI,CAACA,cAAcA,WAAWC,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAMC,WAAWC,IAAAA,iCAAwB,EAACJ,UAAU,CAAC,EAAE;IAEvD,8DAA8D;IAC9D,IAAMK,UAAU,IAAIC,0BAAW;IAC/BD,QAAQE,iBAAiB,CAACJ;IAE1B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ASmC;YACX;QACF;IACF;AACF"}
@@ -22,7 +22,7 @@ _export(exports, {
22
22
  }
23
23
  });
24
24
  var _extractbaseiterator = require("extract-base-iterator");
25
- var _Lzma2ChunkParserts = require("../Lzma2ChunkParser.js");
25
+ var _Lzma2ChunkParserts = require("../lib/Lzma2ChunkParser.js");
26
26
  var _typests = require("../types.js");
27
27
  var _LzmaDecoderts = require("./LzmaDecoder.js");
28
28
  function _class_call_check(instance, Constructor) {
@@ -115,9 +115,11 @@ var Lzma2Decoder = /*#__PURE__*/ function() {
115
115
  throw new Error("Invalid LZMA properties: lc=".concat(lc, " lp=").concat(lp, " pb=").concat(pb));
116
116
  }
117
117
  this.propsSet = true;
118
- }
119
- if (!this.propsSet) {
120
- throw new Error('LZMA chunk without properties');
118
+ } else {
119
+ // No new properties, check if we already have them
120
+ if (!this.propsSet) {
121
+ throw new Error('LZMA chunk without properties');
122
+ }
121
123
  }
122
124
  // Reset probabilities if state reset
123
125
  if (chunk.stateReset) {
@@ -188,9 +190,11 @@ var Lzma2Decoder = /*#__PURE__*/ function() {
188
190
  throw new Error("Invalid LZMA properties: lc=".concat(lc, " lp=").concat(lp, " pb=").concat(pb));
189
191
  }
190
192
  this.propsSet = true;
191
- }
192
- if (!this.propsSet) {
193
- throw new Error('LZMA chunk without properties');
193
+ } else {
194
+ // No new properties, check if we already have them
195
+ if (!this.propsSet) {
196
+ throw new Error('LZMA chunk without properties');
197
+ }
194
198
  }
195
199
  // Reset probabilities if state reset
196
200
  if (chunk.stateReset) {
@@ -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 - 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,a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C,OAAOiB,YAAYP,MAAMG,UAAU,EAAEY,cAAcC,WAAWJ;oBACnHI,aAAaK;gBACf,OAAO;oBACL,6DAA6D;oBAC7D,IAAME,YAAYjC,MAAMmB,KAAK,CAACF,YAAYA,aAAaP,MAAMI,QAAQ;oBACrE,IAAMoB,UAAU,IAAI,CAAC/C,WAAW,CAACiB,MAAM,CAAC6B,WAAW,GAAGvB,MAAMG,UAAU,EAAES;oBACxEK,aAAaG,IAAI,CAACI;gBACpB;gBAEAjC,SAASgB,aAAaP,MAAMI,QAAQ;YACtC;QACF;QAEA,qDAAqD;QACrD,IAAIW,cAAc;YAChB,OAAOC,YAAYD,aAAa1C,MAAM,GAAG0C,aAAaN,KAAK,CAAC,GAAGO,aAAaD;QAC9E;QACA,OAAOU,OAAOC,MAAM,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"}
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 '../lib/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 } else {\n // No new properties, check if we already have them\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\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 } else {\n // No new properties, check if we already have them\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\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;;QA6PGC;eAAAA;;;mCArQkB;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,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AAO;oBACL,6DAA6D;oBAC7D,IAAME,YAAYjC,MAAMmB,KAAK,CAACF,YAAYA,aAAaP,MAAMI,QAAQ;oBACrE,IAAMoB,UAAU,IAAI,CAAC/C,WAAW,CAACiB,MAAM,CAAC6B,WAAW,GAAGvB,MAAMG,UAAU,EAAES;oBACxEK,aAAaG,IAAI,CAACI;gBACpB;gBAEAjC,SAASgB,aAAaP,MAAMI,QAAQ;YACtC;QACF;QAEA,qDAAqD;QACrD,IAAIW,cAAc;YAChB,OAAOC,YAAYD,aAAa1C,MAAM,GAAG0C,aAAaN,KAAK,CAAC,GAAGO,aAAaD;QAC9E;QACA,OAAOU,OAAOC,MAAM,CAACT;IACvB;WAlPWhD;;AA6PN,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"}
@@ -24,8 +24,5 @@ interface NativeModule {
24
24
  * Returns null if not available or Node version is too old
25
25
  */
26
26
  export declare function tryLoadNative(): NativeModule | null;
27
- /**
28
- * Check if native acceleration is available
29
- */
30
27
  export declare function isNativeAvailable(): boolean;
31
28
  export {};
@@ -24,8 +24,5 @@ interface NativeModule {
24
24
  * Returns null if not available or Node version is too old
25
25
  */
26
26
  export declare function tryLoadNative(): NativeModule | null;
27
- /**
28
- * Check if native acceleration is available
29
- */
30
27
  export declare function isNativeAvailable(): boolean;
31
28
  export {};
@@ -35,83 +35,30 @@ var _require = typeof require === 'undefined' ? _module.default.createRequire(re
35
35
  var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
36
36
  // Get node_modules path (go up from dist/cjs to package root, then to node_modules)
37
37
  var nodeModulesPath = _path.default.join(__dirname, '..', '..', 'node_modules');
38
+ var major = +process.versions.node.split('.')[0];
38
39
  // Cache for native module loading result
39
- var nativeModule;
40
- var nodeVersionChecked = false;
41
- var nodeVersionSupported = false;
40
+ var nativeModule = null;
42
41
  var installationAttempted = false;
43
- /**
44
- * Check if Node.js version supports native module (14+)
45
- */ function checkNodeVersion() {
46
- if (nodeVersionChecked) return nodeVersionSupported;
47
- nodeVersionChecked = true;
48
- try {
49
- var version = process.versions.node;
50
- var major = parseInt(version.split('.')[0], 10);
51
- nodeVersionSupported = major >= 14;
52
- } catch (unused) {
53
- nodeVersionSupported = false;
54
- }
55
- return nodeVersionSupported;
56
- }
57
- /**
58
- * Install @napi-rs/lzma using install-module-linked
59
- */ function installNativeModule(callback) {
60
- // Only attempt installation once
61
- if (installationAttempted) {
62
- callback(new Error('Installation already attempted'));
63
- return;
64
- }
42
+ function tryLoadNative() {
43
+ if (major < 14) return null;
44
+ if (installationAttempted) return nativeModule;
65
45
  installationAttempted = true;
46
+ // check if installed already
66
47
  try {
67
- // eslint-disable-next-line @typescript-eslint/no-var-requires
68
- var installModule = _require('install-module-linked').default;
69
- console.log('Installing @napi-rs/lzma for native acceleration...');
70
- installModule('@napi-rs/lzma', nodeModulesPath, {}, function(err) {
71
- if (err) {
72
- console.warn('Failed to install @napi-rs/lzma:', err.message);
73
- } else {
74
- console.log('Successfully installed @napi-rs/lzma');
75
- }
76
- callback(err);
77
- });
78
- } catch (err) {
79
- callback(err);
80
- }
81
- }
82
- function tryLoadNative() {
83
- // Return cached result
84
- if (nativeModule !== undefined) return nativeModule;
85
- // Check Node version first
86
- if (!checkNodeVersion()) {
87
- nativeModule = null;
88
- return null;
89
- }
90
- // Try to load native module (it should be installed at module load time)
48
+ nativeModule = _require('@napi-rs/lzma');
49
+ return nativeModule;
50
+ } catch (unused) {}
51
+ // try to install
91
52
  try {
92
- // eslint-disable-next-line @typescript-eslint/no-require-imports
53
+ console.log('Installing @napi-rs/lzma for native acceleration...');
54
+ var installModule = _require('install-module-linked').default;
55
+ installModule.sync('@napi-rs/lzma', nodeModulesPath, {});
93
56
  nativeModule = _require('@napi-rs/lzma');
94
57
  return nativeModule;
95
58
  } catch (unused) {
96
- // Module not installed yet - return null
97
- nativeModule = null;
98
59
  return null;
99
60
  }
100
61
  }
101
- // At module load time, attempt to install @napi-rs/lzma on Node 14+
102
- // This is done asynchronously so it doesn't block module initialization
103
- if (checkNodeVersion()) {
104
- installNativeModule(function() {
105
- // Installation complete - clear cache and try to load
106
- nativeModule = undefined; // Clear cache to force re-check
107
- try {
108
- nativeModule = _require('@napi-rs/lzma');
109
- } catch (unused) {
110
- // Module still not available
111
- nativeModule = null;
112
- }
113
- });
114
- }
115
62
  function isNativeAvailable() {
116
63
  return tryLoadNative() !== null;
117
64
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/native.ts"],"sourcesContent":["/**\n * Native Acceleration Module\n *\n * Provides optional native acceleration via @napi-rs/lzma on Node.js 14+.\n * Falls back gracefully to pure JS implementation on older Node versions\n * or when the native module is not available.\n */\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\n// Get __dirname for ES modules\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n// Get node_modules path (go up from dist/cjs to package root, then to node_modules)\nconst nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');\n\n// Cache for native module loading result\nlet nativeModule: NativeModule | null | undefined;\nlet nodeVersionChecked = false;\nlet nodeVersionSupported = false;\nlet installationAttempted = false;\n\ninterface NativeModule {\n xz: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma2: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n}\n\n/**\n * Check if Node.js version supports native module (14+)\n */\nfunction checkNodeVersion(): boolean {\n if (nodeVersionChecked) return nodeVersionSupported;\n nodeVersionChecked = true;\n\n try {\n const version = process.versions.node;\n const major = parseInt(version.split('.')[0], 10);\n nodeVersionSupported = major >= 14;\n } catch {\n nodeVersionSupported = false;\n }\n\n return nodeVersionSupported;\n}\n\n/**\n * Install @napi-rs/lzma using install-module-linked\n */\nfunction installNativeModule(callback: (err: Error | null) => void): void {\n // Only attempt installation once\n if (installationAttempted) {\n callback(new Error('Installation already attempted'));\n return;\n }\n installationAttempted = true;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const installModule = _require('install-module-linked').default;\n\n console.log('Installing @napi-rs/lzma for native acceleration...');\n installModule('@napi-rs/lzma', nodeModulesPath, {}, (err: Error | null) => {\n if (err) {\n console.warn('Failed to install @napi-rs/lzma:', err.message);\n } else {\n console.log('Successfully installed @napi-rs/lzma');\n }\n callback(err);\n });\n } catch (err) {\n callback(err as Error);\n }\n}\n\n/**\n * Try to load the native @napi-rs/lzma module\n * Returns null if not available or Node version is too old\n */\nexport function tryLoadNative(): NativeModule | null {\n // Return cached result\n if (nativeModule !== undefined) return nativeModule;\n\n // Check Node version first\n if (!checkNodeVersion()) {\n nativeModule = null;\n return null;\n }\n\n // Try to load native module (it should be installed at module load time)\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {\n // Module not installed yet - return null\n nativeModule = null;\n return null;\n }\n}\n\n// At module load time, attempt to install @napi-rs/lzma on Node 14+\n// This is done asynchronously so it doesn't block module initialization\nif (checkNodeVersion()) {\n installNativeModule(() => {\n // Installation complete - clear cache and try to load\n nativeModule = undefined; // Clear cache to force re-check\n try {\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n } catch {\n // Module still not available\n nativeModule = null;\n }\n });\n}\n\n/**\n * Check if native acceleration is available\n */\nexport function isNativeAvailable(): boolean {\n return tryLoadNative() !== null;\n}\n"],"names":["isNativeAvailable","tryLoadNative","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","nodeModulesPath","join","nativeModule","nodeVersionChecked","nodeVersionSupported","installationAttempted","checkNodeVersion","version","process","versions","node","major","parseInt","split","installNativeModule","callback","Error","installModule","default","console","log","err","warn","message","undefined"],"mappings":"AAAA;;;;;;CAMC;;;;;;;;;;;QA6HeA;eAAAA;;QAxCAC;eAAAA;;;6DAnFG;2DACF;0DACD;;;;;;AAEhB,+BAA+B;AAC/B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAElG,oFAAoF;AACpF,IAAMC,kBAAkBL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,MAAM;AAEzD,yCAAyC;AACzC,IAAIQ;AACJ,IAAIC,qBAAqB;AACzB,IAAIC,uBAAuB;AAC3B,IAAIC,wBAAwB;AAiB5B;;CAEC,GACD,SAASC;IACP,IAAIH,oBAAoB,OAAOC;IAC/BD,qBAAqB;IAErB,IAAI;QACF,IAAMI,UAAUC,QAAQC,QAAQ,CAACC,IAAI;QACrC,IAAMC,QAAQC,SAASL,QAAQM,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE;QAC9CT,uBAAuBO,SAAS;IAClC,EAAE,eAAM;QACNP,uBAAuB;IACzB;IAEA,OAAOA;AACT;AAEA;;CAEC,GACD,SAASU,oBAAoBC,QAAqC;IAChE,iCAAiC;IACjC,IAAIV,uBAAuB;QACzBU,SAAS,IAAIC,MAAM;QACnB;IACF;IACAX,wBAAwB;IAExB,IAAI;QACF,8DAA8D;QAC9D,IAAMY,gBAAgB3B,SAAS,yBAAyB4B,OAAO;QAE/DC,QAAQC,GAAG,CAAC;QACZH,cAAc,iBAAiBjB,iBAAiB,CAAC,GAAG,SAACqB;YACnD,IAAIA,KAAK;gBACPF,QAAQG,IAAI,CAAC,oCAAoCD,IAAIE,OAAO;YAC9D,OAAO;gBACLJ,QAAQC,GAAG,CAAC;YACd;YACAL,SAASM;QACX;IACF,EAAE,OAAOA,KAAK;QACZN,SAASM;IACX;AACF;AAMO,SAAShC;IACd,uBAAuB;IACvB,IAAIa,iBAAiBsB,WAAW,OAAOtB;IAEvC,2BAA2B;IAC3B,IAAI,CAACI,oBAAoB;QACvBJ,eAAe;QACf,OAAO;IACT;IAEA,yEAAyE;IACzE,IAAI;QACF,iEAAiE;QACjEA,eAAeZ,SAAS;QACxB,OAAOY;IACT,EAAE,eAAM;QACN,yCAAyC;QACzCA,eAAe;QACf,OAAO;IACT;AACF;AAEA,oEAAoE;AACpE,wEAAwE;AACxE,IAAII,oBAAoB;IACtBQ,oBAAoB;QAClB,sDAAsD;QACtDZ,eAAesB,WAAW,gCAAgC;QAC1D,IAAI;YACFtB,eAAeZ,SAAS;QAC1B,EAAE,eAAM;YACN,6BAA6B;YAC7BY,eAAe;QACjB;IACF;AACF;AAKO,SAASd;IACd,OAAOC,oBAAoB;AAC7B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/native.ts"],"sourcesContent":["/**\n * Native Acceleration Module\n *\n * Provides optional native acceleration via @napi-rs/lzma on Node.js 14+.\n * Falls back gracefully to pure JS implementation on older Node versions\n * or when the native module is not available.\n */\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\n// Get __dirname for ES modules\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n// Get node_modules path (go up from dist/cjs to package root, then to node_modules)\nconst nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');\nconst major = +process.versions.node.split('.')[0];\n\n// Cache for native module loading result\nlet nativeModule: NativeModule | null = null;\nlet installationAttempted = false;\n\ninterface NativeModule {\n xz: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma2: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n}\n\n/**\n * Try to load the native @napi-rs/lzma module\n * Returns null if not available or Node version is too old\n */\nexport function tryLoadNative(): NativeModule | null {\n if (major < 14) return null;\n if (installationAttempted) return nativeModule;\n installationAttempted = true;\n\n // check if installed already\n try {\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {}\n\n // try to install\n try {\n console.log('Installing @napi-rs/lzma for native acceleration...');\n const installModule = _require('install-module-linked').default;\n installModule.sync('@napi-rs/lzma', nodeModulesPath, {});\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {\n return null;\n }\n}\n\nexport function isNativeAvailable(): boolean {\n return tryLoadNative() !== null;\n}\n"],"names":["isNativeAvailable","tryLoadNative","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","nodeModulesPath","join","major","process","versions","node","split","nativeModule","installationAttempted","console","log","installModule","default","sync"],"mappings":"AAAA;;;;;;CAMC;;;;;;;;;;;QA4DeA;eAAAA;;QAvBAC;eAAAA;;;6DAnCG;2DACF;0DACD;;;;;;AAEhB,+BAA+B;AAC/B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAElG,oFAAoF;AACpF,IAAMC,kBAAkBL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,MAAM;AACzD,IAAMQ,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,yCAAyC;AACzC,IAAIC,eAAoC;AACxC,IAAIC,wBAAwB;AAqBrB,SAASnB;IACd,IAAIa,QAAQ,IAAI,OAAO;IACvB,IAAIM,uBAAuB,OAAOD;IAClCC,wBAAwB;IAExB,6BAA6B;IAC7B,IAAI;QACFD,eAAejB,SAAS;QACxB,OAAOiB;IACT,EAAE,eAAM,CAAC;IAET,iBAAiB;IACjB,IAAI;QACFE,QAAQC,GAAG,CAAC;QACZ,IAAMC,gBAAgBrB,SAAS,yBAAyBsB,OAAO;QAC/DD,cAAcE,IAAI,CAAC,iBAAiBb,iBAAiB,CAAC;QACtDO,eAAejB,SAAS;QACxB,OAAOiB;IACT,EAAE,eAAM;QACN,OAAO;IACT;AACF;AAEO,SAASnB;IACd,OAAOC,oBAAoB;AAC7B"}
@@ -57,10 +57,11 @@ function decode7zLzma(data, properties, unpackSize) {
57
57
  properties,
58
58
  data
59
59
  ]);
60
- return native.lzma.decompressSync(selfDescribing);
61
- } catch (unused) {
62
- // Fall back to pure JS if native fails (e.g., format mismatch)
63
- }
60
+ var result = native.lzma2.decompressSync(selfDescribing);
61
+ if (result.length > 0) return result;
62
+ } catch (unused) {}
63
+ // Fall back to pure JS if native fails (e.g., format mismatch)
64
+ // console.log('Native decode7zLzma failed. Defaulting to JavaScript');
64
65
  }
65
66
  // Pure JS fallback - use fast path directly (no sink wrapper for buffering)
66
67
  return (0, _LzmaDecoderts.decodeLzma)(data, properties, unpackSize);
@@ -75,10 +76,12 @@ function decode7zLzma2(data, properties, unpackSize) {
75
76
  properties,
76
77
  data
77
78
  ]);
78
- return native.lzma2.decompressSync(selfDescribing);
79
- } catch (unused) {
80
- // Fall back to pure JS if native fails (e.g., format mismatch)
81
- }
79
+ var result = native.lzma2.decompressSync(selfDescribing);
80
+ if (result.length > 0) return result;
81
+ // Empty result from native - fall through to JS decoder
82
+ } catch (unused) {}
83
+ // Fall back to pure JS if native fails (e.g., format mismatch)
84
+ // console.log('Native decode7zLzma2 failed. Defaulting to JavaScript');
82
85
  }
83
86
  // Pure JS fallback - use fast path directly (no sink wrapper for buffering)
84
87
  return (0, _Lzma2Decoderts.decodeLzma2)(data, properties, unpackSize);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/sevenz.ts"],"sourcesContent":["/**\n * High-Level 7z-Specific Decoders\n *\n * These functions accept properties separately (matching 7z format structure)\n * and internally wrap them with the data to use @napi-rs/lzma when available.\n *\n * This provides automatic native acceleration for 7z files while maintaining\n * the API that 7z-iterator expects.\n *\n * IMPORTANT: Buffer Management Pattern\n *\n * ❌ SLOW - DO NOT use OutputSink with buffering:\n * const chunks: Buffer[] = [];\n * decodeLzma2(data, props, size, { write: c => chunks.push(c) });\n * return Buffer.concat(chunks); // ← 3 copies: push + concat + return\n *\n * OutWindow → chunks.push(chunk) → Buffer.concat(chunks) → result\n * COPY TO ARRAY COPY ALL FINAL BUFFER\n *\n * ✅ FAST - Direct return (let decoder manage buffer):\n * return decodeLzma2(data, props, size) as Buffer; // ← 1 copy\n *\n * OutWindow → pre-allocated buffer → result\n * DIRECT WRITE\n *\n * The decodeLzma2() function internally pre-allocates the exact output size\n * and writes directly to it. Wrapping with an OutputSink that buffers to an\n * array defeats this optimization by creating unnecessary intermediate copies.\n */\n\nimport { decodeLzma2 } from './lzma/sync/Lzma2Decoder.ts';\nimport { decodeLzma } from './lzma/sync/LzmaDecoder.ts';\nimport { tryLoadNative } from './native.ts';\n\n/**\n * Decode LZMA-compressed data from a 7z file\n *\n * @param data - LZMA compressed data (without properties)\n * @param properties - 5-byte LZMA properties (lc/lp/pb + dictionary size)\n * @param unpackSize - Expected output size\n * @returns Decompressed data\n */\nexport function decode7zLzma(data: Buffer, properties: Buffer, unpackSize: number): Buffer {\n // Try native acceleration first\n const native = tryLoadNative();\n if (native) {\n try {\n // @napi-rs/lzma expects properties embedded at the start of the data\n const selfDescribing = Buffer.concat([properties, data]);\n return native.lzma.decompressSync(selfDescribing);\n } catch {\n // Fall back to pure JS if native fails (e.g., format mismatch)\n }\n }\n\n // Pure JS fallback - use fast path directly (no sink wrapper for buffering)\n return decodeLzma(data, properties, unpackSize) as Buffer;\n}\n\n/**\n * Decode LZMA2-compressed data from a 7z file\n *\n * @param data - LZMA2 compressed data (without properties)\n * @param properties - 1-byte LZMA2 properties (dictionary size)\n * @param unpackSize - Expected output size (optional)\n * @returns Decompressed data\n */\nexport function decode7zLzma2(data: Buffer, properties: Buffer, unpackSize?: number): Buffer {\n // Try native acceleration first\n const native = tryLoadNative();\n if (native) {\n try {\n // @napi-rs/lzma expects properties embedded at the start of the data\n const selfDescribing = Buffer.concat([properties, data]);\n return native.lzma2.decompressSync(selfDescribing);\n } catch {\n // Fall back to pure JS if native fails (e.g., format mismatch)\n }\n }\n\n // Pure JS fallback - use fast path directly (no sink wrapper for buffering)\n return decodeLzma2(data, properties, unpackSize) as Buffer;\n}\n"],"names":["decode7zLzma","decode7zLzma2","data","properties","unpackSize","native","tryLoadNative","selfDescribing","Buffer","concat","lzma","decompressSync","decodeLzma","lzma2","decodeLzma2"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC;;;;;;;;;;;QAceA;eAAAA;;QAyBAC;eAAAA;;;8BArCY;6BACD;wBACG;AAUvB,SAASD,aAAaE,IAAY,EAAEC,UAAkB,EAAEC,UAAkB;IAC/E,gCAAgC;IAChC,IAAMC,SAASC,IAAAA,uBAAa;IAC5B,IAAID,QAAQ;QACV,IAAI;YACF,qEAAqE;YACrE,IAAME,iBAAiBC,OAAOC,MAAM,CAAC;gBAACN;gBAAYD;aAAK;YACvD,OAAOG,OAAOK,IAAI,CAACC,cAAc,CAACJ;QACpC,EAAE,eAAM;QACN,+DAA+D;QACjE;IACF;IAEA,4EAA4E;IAC5E,OAAOK,IAAAA,yBAAU,EAACV,MAAMC,YAAYC;AACtC;AAUO,SAASH,cAAcC,IAAY,EAAEC,UAAkB,EAAEC,UAAmB;IACjF,gCAAgC;IAChC,IAAMC,SAASC,IAAAA,uBAAa;IAC5B,IAAID,QAAQ;QACV,IAAI;YACF,qEAAqE;YACrE,IAAME,iBAAiBC,OAAOC,MAAM,CAAC;gBAACN;gBAAYD;aAAK;YACvD,OAAOG,OAAOQ,KAAK,CAACF,cAAc,CAACJ;QACrC,EAAE,eAAM;QACN,+DAA+D;QACjE;IACF;IAEA,4EAA4E;IAC5E,OAAOO,IAAAA,2BAAW,EAACZ,MAAMC,YAAYC;AACvC"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/sevenz.ts"],"sourcesContent":["/**\n * High-Level 7z-Specific Decoders\n *\n * These functions accept properties separately (matching 7z format structure)\n * and internally wrap them with the data to use @napi-rs/lzma when available.\n *\n * This provides automatic native acceleration for 7z files while maintaining\n * the API that 7z-iterator expects.\n *\n * IMPORTANT: Buffer Management Pattern\n *\n * ❌ SLOW - DO NOT use OutputSink with buffering:\n * const chunks: Buffer[] = [];\n * decodeLzma2(data, props, size, { write: c => chunks.push(c) });\n * return Buffer.concat(chunks); // ← 3 copies: push + concat + return\n *\n * OutWindow → chunks.push(chunk) → Buffer.concat(chunks) → result\n * COPY TO ARRAY COPY ALL FINAL BUFFER\n *\n * ✅ FAST - Direct return (let decoder manage buffer):\n * return decodeLzma2(data, props, size) as Buffer; // ← 1 copy\n *\n * OutWindow → pre-allocated buffer → result\n * DIRECT WRITE\n *\n * The decodeLzma2() function internally pre-allocates the exact output size\n * and writes directly to it. Wrapping with an OutputSink that buffers to an\n * array defeats this optimization by creating unnecessary intermediate copies.\n */\n\nimport { decodeLzma2 } from './lzma/sync/Lzma2Decoder.ts';\nimport { decodeLzma } from './lzma/sync/LzmaDecoder.ts';\nimport { tryLoadNative } from './native.ts';\n\n/**\n * Decode LZMA-compressed data from a 7z file\n *\n * @param data - LZMA compressed data (without properties)\n * @param properties - 5-byte LZMA properties (lc/lp/pb + dictionary size)\n * @param unpackSize - Expected output size\n * @returns Decompressed data\n */\nexport function decode7zLzma(data: Buffer, properties: Buffer, unpackSize: number): Buffer {\n // Try native acceleration first\n const native = tryLoadNative();\n if (native) {\n try {\n // @napi-rs/lzma expects properties embedded at the start of the data\n const selfDescribing = Buffer.concat([properties, data]);\n const result = native.lzma2.decompressSync(selfDescribing);\n if (result.length > 0) return result;\n } catch {}\n // Fall back to pure JS if native fails (e.g., format mismatch)\n // console.log('Native decode7zLzma failed. Defaulting to JavaScript');\n }\n\n // Pure JS fallback - use fast path directly (no sink wrapper for buffering)\n return decodeLzma(data, properties, unpackSize) as Buffer;\n}\n\n/**\n * Decode LZMA2-compressed data from a 7z file\n *\n * @param data - LZMA2 compressed data (without properties)\n * @param properties - 1-byte LZMA2 properties (dictionary size)\n * @param unpackSize - Expected output size (optional)\n * @returns Decompressed data\n */\nexport function decode7zLzma2(data: Buffer, properties: Buffer, unpackSize?: number): Buffer {\n // Try native acceleration first\n const native = tryLoadNative();\n if (native) {\n try {\n // @napi-rs/lzma expects properties embedded at the start of the data\n const selfDescribing = Buffer.concat([properties, data]);\n const result = native.lzma2.decompressSync(selfDescribing);\n if (result.length > 0) return result;\n // Empty result from native - fall through to JS decoder\n } catch {}\n // Fall back to pure JS if native fails (e.g., format mismatch)\n // console.log('Native decode7zLzma2 failed. Defaulting to JavaScript');\n }\n\n // Pure JS fallback - use fast path directly (no sink wrapper for buffering)\n return decodeLzma2(data, properties, unpackSize) as Buffer;\n}\n"],"names":["decode7zLzma","decode7zLzma2","data","properties","unpackSize","native","tryLoadNative","selfDescribing","Buffer","concat","result","lzma2","decompressSync","length","decodeLzma","decodeLzma2"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC;;;;;;;;;;;QAceA;eAAAA;;QA0BAC;eAAAA;;;8BAtCY;6BACD;wBACG;AAUvB,SAASD,aAAaE,IAAY,EAAEC,UAAkB,EAAEC,UAAkB;IAC/E,gCAAgC;IAChC,IAAMC,SAASC,IAAAA,uBAAa;IAC5B,IAAID,QAAQ;QACV,IAAI;YACF,qEAAqE;YACrE,IAAME,iBAAiBC,OAAOC,MAAM,CAAC;gBAACN;gBAAYD;aAAK;YACvD,IAAMQ,SAASL,OAAOM,KAAK,CAACC,cAAc,CAACL;YAC3C,IAAIG,OAAOG,MAAM,GAAG,GAAG,OAAOH;QAChC,EAAE,eAAM,CAAC;IACT,+DAA+D;IAC/D,uEAAuE;IACzE;IAEA,4EAA4E;IAC5E,OAAOI,IAAAA,yBAAU,EAACZ,MAAMC,YAAYC;AACtC;AAUO,SAASH,cAAcC,IAAY,EAAEC,UAAkB,EAAEC,UAAmB;IACjF,gCAAgC;IAChC,IAAMC,SAASC,IAAAA,uBAAa;IAC5B,IAAID,QAAQ;QACV,IAAI;YACF,qEAAqE;YACrE,IAAME,iBAAiBC,OAAOC,MAAM,CAAC;gBAACN;gBAAYD;aAAK;YACvD,IAAMQ,SAASL,OAAOM,KAAK,CAACC,cAAc,CAACL;YAC3C,IAAIG,OAAOG,MAAM,GAAG,GAAG,OAAOH;QAC9B,wDAAwD;QAC1D,EAAE,eAAM,CAAC;IACT,+DAA+D;IAC/D,wEAAwE;IAC1E;IAEA,4EAA4E;IAC5E,OAAOK,IAAAA,2BAAW,EAACb,MAAMC,YAAYC;AACvC"}
@@ -367,17 +367,11 @@ function decodeXZ(input) {
367
367
  var native = (0, _nativets.tryLoadNative)();
368
368
  if (native) {
369
369
  try {
370
- return native.xz.decompressSync(input);
371
- } catch (nativeErr) {
372
- // Native failed - try pure JS (handles more edge cases like
373
- // stream padding, concatenated streams, SHA-256 checksums)
374
- try {
375
- return decodeXZPure(input);
376
- } catch (unused) {
377
- // Both failed - throw the native error (usually more informative)
378
- throw nativeErr;
379
- }
380
- }
370
+ var result = native.xz.decompressSync(input);
371
+ if (result.length > 0) return result;
372
+ } catch (unused) {}
373
+ // Fall back to pure JS if native fails (e.g., format mismatch)
374
+ // console.log('Native decodeXZ failed. Defaulting to JavaScript');
381
375
  }
382
376
  return decodeXZPure(input);
383
377
  }