xz-compat 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/LICENSE +42 -0
  2. package/README.md +248 -0
  3. package/dist/cjs/compat.d.cts +1 -0
  4. package/dist/cjs/compat.d.ts +1 -0
  5. package/dist/cjs/compat.js +23 -0
  6. package/dist/cjs/compat.js.map +1 -0
  7. package/dist/cjs/filters/bcj/Bcj.d.cts +16 -0
  8. package/dist/cjs/filters/bcj/Bcj.d.ts +16 -0
  9. package/dist/cjs/filters/bcj/Bcj.js +192 -0
  10. package/dist/cjs/filters/bcj/Bcj.js.map +1 -0
  11. package/dist/cjs/filters/bcj/BcjArm.d.cts +16 -0
  12. package/dist/cjs/filters/bcj/BcjArm.d.ts +16 -0
  13. package/dist/cjs/filters/bcj/BcjArm.js +122 -0
  14. package/dist/cjs/filters/bcj/BcjArm.js.map +1 -0
  15. package/dist/cjs/filters/bcj/BcjArm64.d.cts +21 -0
  16. package/dist/cjs/filters/bcj/BcjArm64.d.ts +21 -0
  17. package/dist/cjs/filters/bcj/BcjArm64.js +65 -0
  18. package/dist/cjs/filters/bcj/BcjArm64.js.map +1 -0
  19. package/dist/cjs/filters/bcj/BcjArmt.d.cts +19 -0
  20. package/dist/cjs/filters/bcj/BcjArmt.d.ts +19 -0
  21. package/dist/cjs/filters/bcj/BcjArmt.js +76 -0
  22. package/dist/cjs/filters/bcj/BcjArmt.js.map +1 -0
  23. package/dist/cjs/filters/bcj/BcjIa64.d.cts +15 -0
  24. package/dist/cjs/filters/bcj/BcjIa64.d.ts +15 -0
  25. package/dist/cjs/filters/bcj/BcjIa64.js +141 -0
  26. package/dist/cjs/filters/bcj/BcjIa64.js.map +1 -0
  27. package/dist/cjs/filters/bcj/BcjPpc.d.cts +20 -0
  28. package/dist/cjs/filters/bcj/BcjPpc.d.ts +20 -0
  29. package/dist/cjs/filters/bcj/BcjPpc.js +64 -0
  30. package/dist/cjs/filters/bcj/BcjPpc.js.map +1 -0
  31. package/dist/cjs/filters/bcj/BcjSparc.d.cts +19 -0
  32. package/dist/cjs/filters/bcj/BcjSparc.d.ts +19 -0
  33. package/dist/cjs/filters/bcj/BcjSparc.js +69 -0
  34. package/dist/cjs/filters/bcj/BcjSparc.js.map +1 -0
  35. package/dist/cjs/filters/delta/Delta.d.cts +16 -0
  36. package/dist/cjs/filters/delta/Delta.d.ts +16 -0
  37. package/dist/cjs/filters/delta/Delta.js +74 -0
  38. package/dist/cjs/filters/delta/Delta.js.map +1 -0
  39. package/dist/cjs/filters/index.d.cts +8 -0
  40. package/dist/cjs/filters/index.d.ts +8 -0
  41. package/dist/cjs/filters/index.js +27 -0
  42. package/dist/cjs/filters/index.js.map +1 -0
  43. package/dist/cjs/index.d.cts +4 -0
  44. package/dist/cjs/index.d.ts +4 -0
  45. package/dist/cjs/index.js +58 -0
  46. package/dist/cjs/index.js.map +1 -0
  47. package/dist/cjs/lzma/Lzma2ChunkParser.d.cts +73 -0
  48. package/dist/cjs/lzma/Lzma2ChunkParser.d.ts +73 -0
  49. package/dist/cjs/lzma/Lzma2ChunkParser.js +148 -0
  50. package/dist/cjs/lzma/Lzma2ChunkParser.js.map +1 -0
  51. package/dist/cjs/lzma/index.d.cts +31 -0
  52. package/dist/cjs/lzma/index.d.ts +31 -0
  53. package/dist/cjs/lzma/index.js +83 -0
  54. package/dist/cjs/lzma/index.js.map +1 -0
  55. package/dist/cjs/lzma/stream/transforms.d.cts +46 -0
  56. package/dist/cjs/lzma/stream/transforms.d.ts +46 -0
  57. package/dist/cjs/lzma/stream/transforms.js +193 -0
  58. package/dist/cjs/lzma/stream/transforms.js.map +1 -0
  59. package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +63 -0
  60. package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +63 -0
  61. package/dist/cjs/lzma/sync/Lzma2Decoder.js +231 -0
  62. package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -0
  63. package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +97 -0
  64. package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +97 -0
  65. package/dist/cjs/lzma/sync/LzmaDecoder.js +582 -0
  66. package/dist/cjs/lzma/sync/LzmaDecoder.js.map +1 -0
  67. package/dist/cjs/lzma/sync/RangeDecoder.d.cts +69 -0
  68. package/dist/cjs/lzma/sync/RangeDecoder.d.ts +69 -0
  69. package/dist/cjs/lzma/sync/RangeDecoder.js +162 -0
  70. package/dist/cjs/lzma/sync/RangeDecoder.js.map +1 -0
  71. package/dist/cjs/lzma/types.d.cts +117 -0
  72. package/dist/cjs/lzma/types.d.ts +117 -0
  73. package/dist/cjs/lzma/types.js +264 -0
  74. package/dist/cjs/lzma/types.js.map +1 -0
  75. package/dist/cjs/package.json +1 -0
  76. package/dist/cjs/utils/createBufferingDecoder.d.cts +10 -0
  77. package/dist/cjs/utils/createBufferingDecoder.d.ts +10 -0
  78. package/dist/cjs/utils/createBufferingDecoder.js +41 -0
  79. package/dist/cjs/utils/createBufferingDecoder.js.map +1 -0
  80. package/dist/cjs/xz/Decoder.d.cts +21 -0
  81. package/dist/cjs/xz/Decoder.d.ts +21 -0
  82. package/dist/cjs/xz/Decoder.js +325 -0
  83. package/dist/cjs/xz/Decoder.js.map +1 -0
  84. package/dist/esm/compat.d.ts +1 -0
  85. package/dist/esm/compat.js +7 -0
  86. package/dist/esm/compat.js.map +1 -0
  87. package/dist/esm/filters/bcj/Bcj.d.ts +16 -0
  88. package/dist/esm/filters/bcj/Bcj.js +184 -0
  89. package/dist/esm/filters/bcj/Bcj.js.map +1 -0
  90. package/dist/esm/filters/bcj/BcjArm.d.ts +16 -0
  91. package/dist/esm/filters/bcj/BcjArm.js +114 -0
  92. package/dist/esm/filters/bcj/BcjArm.js.map +1 -0
  93. package/dist/esm/filters/bcj/BcjArm64.d.ts +21 -0
  94. package/dist/esm/filters/bcj/BcjArm64.js +57 -0
  95. package/dist/esm/filters/bcj/BcjArm64.js.map +1 -0
  96. package/dist/esm/filters/bcj/BcjArmt.d.ts +19 -0
  97. package/dist/esm/filters/bcj/BcjArmt.js +66 -0
  98. package/dist/esm/filters/bcj/BcjArmt.js.map +1 -0
  99. package/dist/esm/filters/bcj/BcjIa64.d.ts +15 -0
  100. package/dist/esm/filters/bcj/BcjIa64.js +127 -0
  101. package/dist/esm/filters/bcj/BcjIa64.js.map +1 -0
  102. package/dist/esm/filters/bcj/BcjPpc.d.ts +20 -0
  103. package/dist/esm/filters/bcj/BcjPpc.js +55 -0
  104. package/dist/esm/filters/bcj/BcjPpc.js.map +1 -0
  105. package/dist/esm/filters/bcj/BcjSparc.d.ts +19 -0
  106. package/dist/esm/filters/bcj/BcjSparc.js +59 -0
  107. package/dist/esm/filters/bcj/BcjSparc.js.map +1 -0
  108. package/dist/esm/filters/delta/Delta.d.ts +16 -0
  109. package/dist/esm/filters/delta/Delta.js +66 -0
  110. package/dist/esm/filters/delta/Delta.js.map +1 -0
  111. package/dist/esm/filters/index.d.ts +8 -0
  112. package/dist/esm/filters/index.js +9 -0
  113. package/dist/esm/filters/index.js.map +1 -0
  114. package/dist/esm/index.d.ts +4 -0
  115. package/dist/esm/index.js +5 -0
  116. package/dist/esm/index.js.map +1 -0
  117. package/dist/esm/lzma/Lzma2ChunkParser.d.ts +73 -0
  118. package/dist/esm/lzma/Lzma2ChunkParser.js +137 -0
  119. package/dist/esm/lzma/Lzma2ChunkParser.js.map +1 -0
  120. package/dist/esm/lzma/index.d.ts +31 -0
  121. package/dist/esm/lzma/index.js +44 -0
  122. package/dist/esm/lzma/index.js.map +1 -0
  123. package/dist/esm/lzma/stream/transforms.d.ts +46 -0
  124. package/dist/esm/lzma/stream/transforms.js +190 -0
  125. package/dist/esm/lzma/stream/transforms.js.map +1 -0
  126. package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +63 -0
  127. package/dist/esm/lzma/sync/Lzma2Decoder.js +211 -0
  128. package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -0
  129. package/dist/esm/lzma/sync/LzmaDecoder.d.ts +97 -0
  130. package/dist/esm/lzma/sync/LzmaDecoder.js +545 -0
  131. package/dist/esm/lzma/sync/LzmaDecoder.js.map +1 -0
  132. package/dist/esm/lzma/sync/RangeDecoder.d.ts +69 -0
  133. package/dist/esm/lzma/sync/RangeDecoder.js +132 -0
  134. package/dist/esm/lzma/sync/RangeDecoder.js.map +1 -0
  135. package/dist/esm/lzma/types.d.ts +117 -0
  136. package/dist/esm/lzma/types.js +154 -0
  137. package/dist/esm/lzma/types.js.map +1 -0
  138. package/dist/esm/package.json +1 -0
  139. package/dist/esm/utils/createBufferingDecoder.d.ts +10 -0
  140. package/dist/esm/utils/createBufferingDecoder.js +30 -0
  141. package/dist/esm/utils/createBufferingDecoder.js.map +1 -0
  142. package/dist/esm/xz/Decoder.d.ts +21 -0
  143. package/dist/esm/xz/Decoder.js +313 -0
  144. package/dist/esm/xz/Decoder.js.map +1 -0
  145. package/package.json +75 -0
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Synchronous Range Decoder for LZMA
3
+ *
4
+ * Decodes arithmetic-coded bits from a buffer.
5
+ * All operations are synchronous - for streaming use the async version.
6
+ */
7
+ /**
8
+ * Range decoder for synchronous buffer-based LZMA decoding
9
+ */
10
+ export declare class RangeDecoder {
11
+ private input;
12
+ private pos;
13
+ private code;
14
+ private range;
15
+ constructor();
16
+ /**
17
+ * Set input buffer and initialize decoder state
18
+ */
19
+ setInput(input: Buffer, offset?: number): void;
20
+ /**
21
+ * Initialize range decoder (reads first 5 bytes)
22
+ */
23
+ private init;
24
+ /**
25
+ * Get current position in input buffer
26
+ */
27
+ getPosition(): number;
28
+ /**
29
+ * Normalize range if needed (read more bytes)
30
+ */
31
+ private normalize;
32
+ /**
33
+ * Decode a single bit using probability model
34
+ * @param probs - Probability array
35
+ * @param index - Index into probability array
36
+ * @returns Decoded bit (0 or 1)
37
+ */
38
+ decodeBit(probs: Uint16Array, index: number): number;
39
+ /**
40
+ * Decode direct bits (not probability-based)
41
+ * @param numTotalBits - Number of bits to decode
42
+ * @returns Decoded value
43
+ */
44
+ decodeDirectBits(numTotalBits: number): number;
45
+ }
46
+ /**
47
+ * Bit tree decoder for multi-bit symbols
48
+ */
49
+ export declare class BitTreeDecoder {
50
+ private numBitLevels;
51
+ private models;
52
+ constructor(numBitLevels: number);
53
+ /**
54
+ * Initialize probability models
55
+ */
56
+ init(): void;
57
+ /**
58
+ * Decode a symbol (forward bit order)
59
+ */
60
+ decode(rangeDecoder: RangeDecoder): number;
61
+ /**
62
+ * Decode a symbol (reverse bit order)
63
+ */
64
+ reverseDecode(rangeDecoder: RangeDecoder): number;
65
+ }
66
+ /**
67
+ * Static reverse decode from external probability array
68
+ */
69
+ export declare function reverseDecodeFromArray(models: Uint16Array, startIndex: number, rangeDecoder: RangeDecoder, numBitLevels: number): number;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Synchronous Range Decoder for LZMA
3
+ *
4
+ * Decodes arithmetic-coded bits from a buffer.
5
+ * All operations are synchronous - for streaming use the async version.
6
+ */ import { allocBuffer } from 'extract-base-iterator';
7
+ /**
8
+ * Range decoder for synchronous buffer-based LZMA decoding
9
+ */ export class RangeDecoder {
10
+ /**
11
+ * Set input buffer and initialize decoder state
12
+ */ setInput(input, offset = 0) {
13
+ this.input = input;
14
+ this.pos = offset;
15
+ this.init();
16
+ }
17
+ /**
18
+ * Initialize range decoder (reads first 5 bytes)
19
+ */ init() {
20
+ this.code = 0;
21
+ this.range = -1; // 0xFFFFFFFF as signed int
22
+ // First byte is ignored (should be 0)
23
+ this.pos++;
24
+ // Read 4 bytes into code
25
+ for(let i = 0; i < 4; i++){
26
+ this.code = this.code << 8 | this.input[this.pos++];
27
+ }
28
+ }
29
+ /**
30
+ * Get current position in input buffer
31
+ */ getPosition() {
32
+ return this.pos;
33
+ }
34
+ /**
35
+ * Normalize range if needed (read more bytes)
36
+ */ normalize() {
37
+ if ((this.range & 0xff000000) === 0) {
38
+ this.code = this.code << 8 | this.input[this.pos++];
39
+ this.range <<= 8;
40
+ }
41
+ }
42
+ /**
43
+ * Decode a single bit using probability model
44
+ * @param probs - Probability array
45
+ * @param index - Index into probability array
46
+ * @returns Decoded bit (0 or 1)
47
+ */ decodeBit(probs, index) {
48
+ const prob = probs[index];
49
+ const newBound = (this.range >>> 11) * prob;
50
+ if ((this.code ^ 0x80000000) < (newBound ^ 0x80000000)) {
51
+ this.range = newBound;
52
+ probs[index] += 2048 - prob >>> 5;
53
+ this.normalize();
54
+ return 0;
55
+ }
56
+ this.range -= newBound;
57
+ this.code -= newBound;
58
+ probs[index] -= prob >>> 5;
59
+ this.normalize();
60
+ return 1;
61
+ }
62
+ /**
63
+ * Decode direct bits (not probability-based)
64
+ * @param numTotalBits - Number of bits to decode
65
+ * @returns Decoded value
66
+ */ decodeDirectBits(numTotalBits) {
67
+ let result = 0;
68
+ for(let i = numTotalBits; i > 0; i--){
69
+ this.range >>>= 1;
70
+ const t = this.code - this.range >>> 31;
71
+ this.code -= this.range & t - 1;
72
+ result = result << 1 | 1 - t;
73
+ this.normalize();
74
+ }
75
+ return result;
76
+ }
77
+ constructor(){
78
+ this.input = allocBuffer(0); // Replaced by setInput() before use
79
+ this.pos = 0;
80
+ this.code = 0;
81
+ this.range = 0;
82
+ }
83
+ }
84
+ /**
85
+ * Bit tree decoder for multi-bit symbols
86
+ */ export class BitTreeDecoder {
87
+ /**
88
+ * Initialize probability models
89
+ */ init() {
90
+ for(let i = 0; i < this.models.length; i++){
91
+ this.models[i] = 1024; // kProbInitValue
92
+ }
93
+ }
94
+ /**
95
+ * Decode a symbol (forward bit order)
96
+ */ decode(rangeDecoder) {
97
+ let m = 1;
98
+ for(let i = this.numBitLevels; i > 0; i--){
99
+ m = m << 1 | rangeDecoder.decodeBit(this.models, m);
100
+ }
101
+ return m - (1 << this.numBitLevels);
102
+ }
103
+ /**
104
+ * Decode a symbol (reverse bit order)
105
+ */ reverseDecode(rangeDecoder) {
106
+ let m = 1;
107
+ let symbol = 0;
108
+ for(let i = 0; i < this.numBitLevels; i++){
109
+ const bit = rangeDecoder.decodeBit(this.models, m);
110
+ m = m << 1 | bit;
111
+ symbol |= bit << i;
112
+ }
113
+ return symbol;
114
+ }
115
+ constructor(numBitLevels){
116
+ this.numBitLevels = numBitLevels;
117
+ this.models = new Uint16Array(1 << numBitLevels);
118
+ this.init();
119
+ }
120
+ }
121
+ /**
122
+ * Static reverse decode from external probability array
123
+ */ export function reverseDecodeFromArray(models, startIndex, rangeDecoder, numBitLevels) {
124
+ let m = 1;
125
+ let symbol = 0;
126
+ for(let i = 0; i < numBitLevels; i++){
127
+ const bit = rangeDecoder.decodeBit(models, startIndex + m);
128
+ m = m << 1 | bit;
129
+ symbol |= bit << i;
130
+ }
131
+ return symbol;
132
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/lzma/sync/RangeDecoder.ts"],"sourcesContent":["/**\n * Synchronous Range Decoder for LZMA\n *\n * Decodes arithmetic-coded bits from a buffer.\n * All operations are synchronous - for streaming use the async version.\n */\n\nimport { allocBuffer } from 'extract-base-iterator';\n\n/**\n * Range decoder for synchronous buffer-based LZMA decoding\n */\nexport class RangeDecoder {\n private input: Buffer;\n private pos: number;\n private code: number;\n private range: number;\n\n constructor() {\n this.input = allocBuffer(0); // Replaced by setInput() before use\n this.pos = 0;\n this.code = 0;\n this.range = 0;\n }\n\n /**\n * Set input buffer and initialize decoder state\n */\n setInput(input: Buffer, offset = 0): void {\n this.input = input;\n this.pos = offset;\n this.init();\n }\n\n /**\n * Initialize range decoder (reads first 5 bytes)\n */\n private init(): void {\n this.code = 0;\n this.range = -1; // 0xFFFFFFFF as signed int\n\n // First byte is ignored (should be 0)\n this.pos++;\n\n // Read 4 bytes into code\n for (let i = 0; i < 4; i++) {\n this.code = (this.code << 8) | this.input[this.pos++];\n }\n }\n\n /**\n * Get current position in input buffer\n */\n getPosition(): number {\n return this.pos;\n }\n\n /**\n * Normalize range if needed (read more bytes)\n */\n private normalize(): void {\n if ((this.range & 0xff000000) === 0) {\n this.code = (this.code << 8) | this.input[this.pos++];\n this.range <<= 8;\n }\n }\n\n /**\n * Decode a single bit using probability model\n * @param probs - Probability array\n * @param index - Index into probability array\n * @returns Decoded bit (0 or 1)\n */\n decodeBit(probs: Uint16Array, index: number): number {\n const prob = probs[index];\n const newBound = (this.range >>> 11) * prob;\n\n if ((this.code ^ 0x80000000) < (newBound ^ 0x80000000)) {\n this.range = newBound;\n probs[index] += (2048 - prob) >>> 5;\n this.normalize();\n return 0;\n }\n this.range -= newBound;\n this.code -= newBound;\n probs[index] -= prob >>> 5;\n this.normalize();\n return 1;\n }\n\n /**\n * Decode direct bits (not probability-based)\n * @param numTotalBits - Number of bits to decode\n * @returns Decoded value\n */\n decodeDirectBits(numTotalBits: number): number {\n let result = 0;\n for (let i = numTotalBits; i > 0; i--) {\n this.range >>>= 1;\n const t = (this.code - this.range) >>> 31;\n this.code -= this.range & (t - 1);\n result = (result << 1) | (1 - t);\n this.normalize();\n }\n return result;\n }\n}\n\n/**\n * Bit tree decoder for multi-bit symbols\n */\nexport class BitTreeDecoder {\n private numBitLevels: number;\n private models: Uint16Array;\n\n constructor(numBitLevels: number) {\n this.numBitLevels = numBitLevels;\n this.models = new Uint16Array(1 << numBitLevels);\n this.init();\n }\n\n /**\n * Initialize probability models\n */\n init(): void {\n for (let i = 0; i < this.models.length; i++) {\n this.models[i] = 1024; // kProbInitValue\n }\n }\n\n /**\n * Decode a symbol (forward bit order)\n */\n decode(rangeDecoder: RangeDecoder): number {\n let m = 1;\n for (let i = this.numBitLevels; i > 0; i--) {\n m = (m << 1) | rangeDecoder.decodeBit(this.models, m);\n }\n return m - (1 << this.numBitLevels);\n }\n\n /**\n * Decode a symbol (reverse bit order)\n */\n reverseDecode(rangeDecoder: RangeDecoder): number {\n let m = 1;\n let symbol = 0;\n for (let i = 0; i < this.numBitLevels; i++) {\n const bit = rangeDecoder.decodeBit(this.models, m);\n m = (m << 1) | bit;\n symbol |= bit << i;\n }\n return symbol;\n }\n}\n\n/**\n * Static reverse decode from external probability array\n */\nexport function reverseDecodeFromArray(models: Uint16Array, startIndex: number, rangeDecoder: RangeDecoder, numBitLevels: number): number {\n let m = 1;\n let symbol = 0;\n for (let i = 0; i < numBitLevels; i++) {\n const bit = rangeDecoder.decodeBit(models, startIndex + m);\n m = (m << 1) | bit;\n symbol |= bit << i;\n }\n return symbol;\n}\n"],"names":["allocBuffer","RangeDecoder","setInput","input","offset","pos","init","code","range","i","getPosition","normalize","decodeBit","probs","index","prob","newBound","decodeDirectBits","numTotalBits","result","t","BitTreeDecoder","models","length","decode","rangeDecoder","m","numBitLevels","reverseDecode","symbol","bit","Uint16Array","reverseDecodeFromArray","startIndex"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,WAAW,QAAQ,wBAAwB;AAEpD;;CAEC,GACD,OAAO,MAAMC;IAaX;;GAEC,GACDC,SAASC,KAAa,EAAEC,SAAS,CAAC,EAAQ;QACxC,IAAI,CAACD,KAAK,GAAGA;QACb,IAAI,CAACE,GAAG,GAAGD;QACX,IAAI,CAACE,IAAI;IACX;IAEA;;GAEC,GACD,AAAQA,OAAa;QACnB,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACC,KAAK,GAAG,CAAC,GAAG,2BAA2B;QAE5C,sCAAsC;QACtC,IAAI,CAACH,GAAG;QAER,yBAAyB;QACzB,IAAK,IAAII,IAAI,GAAGA,IAAI,GAAGA,IAAK;YAC1B,IAAI,CAACF,IAAI,GAAG,AAAC,IAAI,CAACA,IAAI,IAAI,IAAK,IAAI,CAACJ,KAAK,CAAC,IAAI,CAACE,GAAG,GAAG;QACvD;IACF;IAEA;;GAEC,GACDK,cAAsB;QACpB,OAAO,IAAI,CAACL,GAAG;IACjB;IAEA;;GAEC,GACD,AAAQM,YAAkB;QACxB,IAAI,AAAC,CAAA,IAAI,CAACH,KAAK,GAAG,UAAS,MAAO,GAAG;YACnC,IAAI,CA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ZMA Types and Constants
3
+ *
4
+ * Shared types, constants, and state transition functions for LZMA decoding.
5
+ * Based on the LZMA SDK specification.
6
+ */
7
+ export declare const kNumRepDistances = 4;
8
+ export declare const kNumStates = 12;
9
+ export declare const kNumPosSlotBits = 6;
10
+ export declare const kDicLogSizeMin = 0;
11
+ export declare const kNumLenToPosStatesBits = 2;
12
+ export declare const kNumLenToPosStates: number;
13
+ export declare const kMatchMinLen = 2;
14
+ export declare const kNumLowLenBits = 3;
15
+ export declare const kNumMidLenBits = 3;
16
+ export declare const kNumHighLenBits = 8;
17
+ export declare const kNumLowLenSymbols: number;
18
+ export declare const kNumMidLenSymbols: number;
19
+ export declare const kNumLenSymbols: number;
20
+ export declare const kMatchMaxLen: number;
21
+ export declare const kNumAlignBits = 4;
22
+ export declare const kAlignTableSize: number;
23
+ export declare const kAlignMask: number;
24
+ export declare const kStartPosModelIndex = 4;
25
+ export declare const kEndPosModelIndex = 14;
26
+ export declare const kNumPosModels: number;
27
+ export declare const kNumFullDistances: number;
28
+ export declare const kNumLitPosStatesBitsEncodingMax = 4;
29
+ export declare const kNumLitContextBitsMax = 8;
30
+ export declare const kNumPosStatesBitsMax = 4;
31
+ export declare const kNumPosStatesMax: number;
32
+ export declare const kNumPosStatesBitsEncodingMax = 4;
33
+ export declare const kNumPosStatesEncodingMax: number;
34
+ export declare const kNumBitModelTotalBits = 11;
35
+ export declare const kBitModelTotal: number;
36
+ export declare const kNumMoveBits = 5;
37
+ export declare const kProbInitValue: number;
38
+ /**
39
+ * State transition: after literal byte
40
+ */
41
+ export declare function stateUpdateChar(state: number): number;
42
+ /**
43
+ * State transition: after match
44
+ */
45
+ export declare function stateUpdateMatch(state: number): number;
46
+ /**
47
+ * State transition: after rep (repeated match)
48
+ */
49
+ export declare function stateUpdateRep(state: number): number;
50
+ /**
51
+ * State transition: after short rep
52
+ */
53
+ export declare function stateUpdateShortRep(state: number): number;
54
+ /**
55
+ * Check if state indicates previous symbol was a character (literal)
56
+ */
57
+ export declare function stateIsCharState(state: number): boolean;
58
+ /**
59
+ * Get length-to-position state index
60
+ */
61
+ export declare function getLenToPosState(len: number): number;
62
+ /**
63
+ * Initialize probability array with default values
64
+ * @param probs - Array to initialize (or null to create new)
65
+ * @param count - Number of probabilities
66
+ * @returns Initialized probability array
67
+ */
68
+ export declare function initBitModels(probs: Uint16Array | null, count?: number): Uint16Array;
69
+ /**
70
+ * LZMA properties parsed from the 5-byte header
71
+ */
72
+ export interface LzmaProperties {
73
+ /** Literal context bits (0-8) */
74
+ lc: number;
75
+ /** Literal pos bits (0-4) */
76
+ lp: number;
77
+ /** Pos bits (0-4) */
78
+ pb: number;
79
+ /** Dictionary size in bytes */
80
+ dictionarySize: number;
81
+ }
82
+ /**
83
+ * Parse LZMA properties from a 5-byte buffer
84
+ */
85
+ export declare function parseProperties(properties: Buffer | Uint8Array): LzmaProperties;
86
+ /**
87
+ * LZMA2 control byte meanings
88
+ */
89
+ export declare const LZMA2_CONTROL: {
90
+ readonly END: 0;
91
+ readonly UNCOMPRESSED_RESET_DIC: 1;
92
+ readonly UNCOMPRESSED: 2;
93
+ readonly LZMA_RESET_STATE_NEW_PROP: 224;
94
+ };
95
+ /**
96
+ * Check if LZMA2 control byte indicates reset state (new properties)
97
+ */
98
+ export declare function lzma2NeedsNewProps(control: number): boolean;
99
+ /**
100
+ * Check if LZMA2 control byte indicates reset probabilities
101
+ */
102
+ export declare function lzma2NeedsResetProbs(control: number): boolean;
103
+ /**
104
+ * Check if LZMA2 control byte indicates uncompressed chunk
105
+ */
106
+ export declare function lzma2IsUncompressed(control: number): boolean;
107
+ /**
108
+ * Parse LZMA2 dictionary size from property byte
109
+ */
110
+ export declare function parseLzma2DictionarySize(prop: number): number;
111
+ /**
112
+ * Output sink interface for fast streaming decode
113
+ * Can be a Buffer (with write method) or a stream with write() method
114
+ */
115
+ export interface OutputSink {
116
+ write(buffer: Buffer): void;
117
+ }
@@ -0,0 +1,154 @@
1
+ /**
2
+ * LZMA Types and Constants
3
+ *
4
+ * Shared types, constants, and state transition functions for LZMA decoding.
5
+ * Based on the LZMA SDK specification.
6
+ */ // LZMA State Machine Constants
7
+ export const kNumRepDistances = 4;
8
+ export const kNumStates = 12;
9
+ // Position slot constants
10
+ export const kNumPosSlotBits = 6;
11
+ export const kDicLogSizeMin = 0;
12
+ export const kNumLenToPosStatesBits = 2;
13
+ export const kNumLenToPosStates = 1 << kNumLenToPosStatesBits; // 4
14
+ // Match length constants
15
+ export const kMatchMinLen = 2;
16
+ export const kNumLowLenBits = 3;
17
+ export const kNumMidLenBits = 3;
18
+ export const kNumHighLenBits = 8;
19
+ export const kNumLowLenSymbols = 1 << kNumLowLenBits; // 8
20
+ export const kNumMidLenSymbols = 1 << kNumMidLenBits; // 8
21
+ export const kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + (1 << kNumHighLenBits); // 272
22
+ export const kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; // 273
23
+ // Alignment constants
24
+ export const kNumAlignBits = 4;
25
+ export const kAlignTableSize = 1 << kNumAlignBits; // 16
26
+ export const kAlignMask = kAlignTableSize - 1; // 15
27
+ // Position model constants
28
+ export const kStartPosModelIndex = 4;
29
+ export const kEndPosModelIndex = 14;
30
+ export const kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; // 10
31
+ export const kNumFullDistances = 1 << (kEndPosModelIndex >>> 1); // 128
32
+ // Literal/pos state constants
33
+ export const kNumLitPosStatesBitsEncodingMax = 4;
34
+ export const kNumLitContextBitsMax = 8;
35
+ export const kNumPosStatesBitsMax = 4;
36
+ export const kNumPosStatesMax = 1 << kNumPosStatesBitsMax; // 16
37
+ export const kNumPosStatesBitsEncodingMax = 4;
38
+ export const kNumPosStatesEncodingMax = 1 << kNumPosStatesBitsEncodingMax; // 16
39
+ // Range coder probability constants
40
+ export const kNumBitModelTotalBits = 11;
41
+ export const kBitModelTotal = 1 << kNumBitModelTotalBits; // 2048
42
+ export const kNumMoveBits = 5;
43
+ export const kProbInitValue = kBitModelTotal >>> 1; // 1024
44
+ /**
45
+ * State transition: after literal byte
46
+ */ export function stateUpdateChar(state) {
47
+ if (state < 4) return 0;
48
+ if (state < 10) return state - 3;
49
+ return state - 6;
50
+ }
51
+ /**
52
+ * State transition: after match
53
+ */ export function stateUpdateMatch(state) {
54
+ return state < 7 ? 7 : 10;
55
+ }
56
+ /**
57
+ * State transition: after rep (repeated match)
58
+ */ export function stateUpdateRep(state) {
59
+ return state < 7 ? 8 : 11;
60
+ }
61
+ /**
62
+ * State transition: after short rep
63
+ */ export function stateUpdateShortRep(state) {
64
+ return state < 7 ? 9 : 11;
65
+ }
66
+ /**
67
+ * Check if state indicates previous symbol was a character (literal)
68
+ */ export function stateIsCharState(state) {
69
+ return state < 7;
70
+ }
71
+ /**
72
+ * Get length-to-position state index
73
+ */ export function getLenToPosState(len) {
74
+ len -= kMatchMinLen;
75
+ return len < kNumLenToPosStates ? len : kNumLenToPosStates - 1;
76
+ }
77
+ /**
78
+ * Initialize probability array with default values
79
+ * @param probs - Array to initialize (or null to create new)
80
+ * @param count - Number of probabilities
81
+ * @returns Initialized probability array
82
+ */ export function initBitModels(probs, count) {
83
+ if (probs === null) {
84
+ if (count === undefined) {
85
+ throw new Error('count required when probs is null');
86
+ }
87
+ probs = new Uint16Array(count);
88
+ }
89
+ for(let i = 0; i < probs.length; i++){
90
+ probs[i] = kProbInitValue;
91
+ }
92
+ return probs;
93
+ }
94
+ /**
95
+ * Parse LZMA properties from a 5-byte buffer
96
+ */ export function parseProperties(properties) {
97
+ if (properties.length < 5) {
98
+ throw new Error('LZMA properties must be at least 5 bytes');
99
+ }
100
+ const d = properties[0] & 0xff;
101
+ const lc = d % 9;
102
+ const remainder = ~~(d / 9);
103
+ const lp = remainder % 5;
104
+ const pb = ~~(remainder / 5);
105
+ if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {
106
+ throw new Error('Invalid LZMA properties');
107
+ }
108
+ let dictionarySize = 0;
109
+ for(let i = 0; i < 4; i++){
110
+ dictionarySize |= (properties[1 + i] & 0xff) << i * 8;
111
+ }
112
+ return {
113
+ lc,
114
+ lp,
115
+ pb,
116
+ dictionarySize
117
+ };
118
+ }
119
+ /**
120
+ * LZMA2 control byte meanings
121
+ */ export const LZMA2_CONTROL = {
122
+ END: 0x00,
123
+ UNCOMPRESSED_RESET_DIC: 0x01,
124
+ UNCOMPRESSED: 0x02,
125
+ LZMA_RESET_STATE_NEW_PROP: 0xe0
126
+ };
127
+ /**
128
+ * Check if LZMA2 control byte indicates reset state (new properties)
129
+ */ export function lzma2NeedsNewProps(control) {
130
+ return control >= 0xe0;
131
+ }
132
+ /**
133
+ * Check if LZMA2 control byte indicates reset probabilities
134
+ */ export function lzma2NeedsResetProbs(control) {
135
+ return control >= 0xa0;
136
+ }
137
+ /**
138
+ * Check if LZMA2 control byte indicates uncompressed chunk
139
+ */ export function lzma2IsUncompressed(control) {
140
+ return control < 0x80;
141
+ }
142
+ /**
143
+ * Parse LZMA2 dictionary size from property byte
144
+ */ export function parseLzma2DictionarySize(prop) {
145
+ if (prop > 40) {
146
+ throw new Error('Invalid LZMA2 dictionary size property');
147
+ }
148
+ if (prop === 40) {
149
+ return 0xffffffff;
150
+ }
151
+ const base = 2 | prop & 1;
152
+ const exp = (prop >>> 1) + 11;
153
+ return base << exp;
154
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/lzma/types.ts"],"sourcesContent":["/**\n * LZMA Types and Constants\n *\n * Shared types, constants, and state transition functions for LZMA decoding.\n * Based on the LZMA SDK specification.\n */\n\n// LZMA State Machine Constants\nexport const kNumRepDistances = 4;\nexport const kNumStates = 12;\n\n// Position slot constants\nexport const kNumPosSlotBits = 6;\nexport const kDicLogSizeMin = 0;\nexport const kNumLenToPosStatesBits = 2;\nexport const kNumLenToPosStates = 1 << kNumLenToPosStatesBits; // 4\n\n// Match length constants\nexport const kMatchMinLen = 2;\nexport const kNumLowLenBits = 3;\nexport const kNumMidLenBits = 3;\nexport const kNumHighLenBits = 8;\nexport const kNumLowLenSymbols = 1 << kNumLowLenBits; // 8\nexport const kNumMidLenSymbols = 1 << kNumMidLenBits; // 8\nexport const kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + (1 << kNumHighLenBits); // 272\nexport const kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; // 273\n\n// Alignment constants\nexport const kNumAlignBits = 4;\nexport const kAlignTableSize = 1 << kNumAlignBits; // 16\nexport const kAlignMask = kAlignTableSize - 1; // 15\n\n// Position model constants\nexport const kStartPosModelIndex = 4;\nexport const kEndPosModelIndex = 14;\nexport const kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; // 10\nexport const kNumFullDistances = 1 << (kEndPosModelIndex >>> 1); // 128\n\n// Literal/pos state constants\nexport const kNumLitPosStatesBitsEncodingMax = 4;\nexport const kNumLitContextBitsMax = 8;\nexport const kNumPosStatesBitsMax = 4;\nexport const kNumPosStatesMax = 1 << kNumPosStatesBitsMax; // 16\nexport const kNumPosStatesBitsEncodingMax = 4;\nexport const kNumPosStatesEncodingMax = 1 << kNumPosStatesBitsEncodingMax; // 16\n\n// Range coder probability constants\nexport const kNumBitModelTotalBits = 11;\nexport const kBitModelTotal = 1 << kNumBitModelTotalBits; // 2048\nexport const kNumMoveBits = 5;\nexport const kProbInitValue = kBitModelTotal >>> 1; // 1024\n\n/**\n * State transition: after literal byte\n */\nexport function stateUpdateChar(state: number): number {\n if (state < 4) return 0;\n if (state < 10) return state - 3;\n return state - 6;\n}\n\n/**\n * State transition: after match\n */\nexport function stateUpdateMatch(state: number): number {\n return state < 7 ? 7 : 10;\n}\n\n/**\n * State transition: after rep (repeated match)\n */\nexport function stateUpdateRep(state: number): number {\n return state < 7 ? 8 : 11;\n}\n\n/**\n * State transition: after short rep\n */\nexport function stateUpdateShortRep(state: number): number {\n return state < 7 ? 9 : 11;\n}\n\n/**\n * Check if state indicates previous symbol was a character (literal)\n */\nexport function stateIsCharState(state: number): boolean {\n return state < 7;\n}\n\n/**\n * Get length-to-position state index\n */\nexport function getLenToPosState(len: number): number {\n len -= kMatchMinLen;\n return len < kNumLenToPosStates ? len : kNumLenToPosStates - 1;\n}\n\n/**\n * Initialize probability array with default values\n * @param probs - Array to initialize (or null to create new)\n * @param count - Number of probabilities\n * @returns Initialized probability array\n */\nexport function initBitModels(probs: Uint16Array | null, count?: number): Uint16Array {\n if (probs === null) {\n if (count === undefined) {\n throw new Error('count required when probs is null');\n }\n probs = new Uint16Array(count);\n }\n for (let i = 0; i < probs.length; i++) {\n probs[i] = kProbInitValue;\n }\n return probs;\n}\n\n/**\n * LZMA properties parsed from the 5-byte header\n */\nexport interface LzmaProperties {\n /** Literal context bits (0-8) */\n lc: number;\n /** Literal pos bits (0-4) */\n lp: number;\n /** Pos bits (0-4) */\n pb: number;\n /** Dictionary size in bytes */\n dictionarySize: number;\n}\n\n/**\n * Parse LZMA properties from a 5-byte buffer\n */\nexport function parseProperties(properties: Buffer | Uint8Array): LzmaProperties {\n if (properties.length < 5) {\n throw new Error('LZMA properties must be at least 5 bytes');\n }\n\n const d = properties[0] & 0xff;\n const lc = d % 9;\n const remainder = ~~(d / 9);\n const lp = remainder % 5;\n const pb = ~~(remainder / 5);\n\n if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {\n throw new Error('Invalid LZMA properties');\n }\n\n let dictionarySize = 0;\n for (let i = 0; i < 4; i++) {\n dictionarySize |= (properties[1 + i] & 0xff) << (i * 8);\n }\n\n return { lc, lp, pb, dictionarySize };\n}\n\n/**\n * LZMA2 control byte meanings\n */\nexport const LZMA2_CONTROL = {\n END: 0x00,\n UNCOMPRESSED_RESET_DIC: 0x01,\n UNCOMPRESSED: 0x02,\n LZMA_RESET_STATE_NEW_PROP: 0xe0,\n} as const;\n\n/**\n * Check if LZMA2 control byte indicates reset state (new properties)\n */\nexport function lzma2NeedsNewProps(control: number): boolean {\n return control >= 0xe0;\n}\n\n/**\n * Check if LZMA2 control byte indicates reset probabilities\n */\nexport function lzma2NeedsResetProbs(control: number): boolean {\n return control >= 0xa0;\n}\n\n/**\n * Check if LZMA2 control byte indicates uncompressed chunk\n */\nexport function lzma2IsUncompressed(control: number): boolean {\n return control < 0x80;\n}\n\n/**\n * Parse LZMA2 dictionary size from property byte\n */\nexport function parseLzma2DictionarySize(prop: number): number {\n if (prop > 40) {\n throw new Error('Invalid LZMA2 dictionary size property');\n }\n if (prop === 40) {\n return 0xffffffff;\n }\n const base = 2 | (prop & 1);\n const exp = (prop >>> 1) + 11;\n return base << exp;\n}\n\n/**\n * Output sink interface for fast streaming decode\n * Can be a Buffer (with write method) or a stream with write() method\n */\nexport interface OutputSink {\n write(buffer: Buffer): void;\n}\n"],"names":["kNumRepDistances","kNumStates","kNumPosSlotBits","kDicLogSizeMin","kNumLenToPosStatesBits","kNumLenToPosStates","kMatchMinLen","kNumLowLenBits","kNumMidLenBits","kNumHighLenBits","kNumLowLenSymbols","kNumMidLenSymbols","kNumLenSymbols","kMatchMaxLen","kNumAlignBits","kAlignTableSize","kAlignMask","kStartPosModelIndex","kEndPosModelIndex","kNumPosModels","kNumFullDistances","kNumLitPosStatesBitsEncodingMax","kNumLitContextBitsMax","kNumPosStatesBitsMax","kNumPosStatesMax","kNumPosStatesBitsEncodingMax","kNumPosStatesEncodingMax","kNumBitModelTotalBits","kBitModelTotal","kNumMoveBits","kProbInitValue","stateUpdateChar","state","stateUpdateMatch","stateUpdateRep","stateUpdateShortRep","stateIsCharState","getLenToPosState","len","initBitModels","probs","count","undefined","Error","Uint16Array","i","length","parseProperties","properties","d","lc","remainder","lp","pb","dictionarySize","LZMA2_CONTROL","END","UNCOMPRESSED_RESET_DIC","UNCOMPRESSED","LZMA_RESET_STATE_NEW_PROP","lzma2NeedsNewProps","control","lzma2NeedsResetProbs","lzma2IsUncompressed","parseLzma2DictionarySize","prop","base","exp"],"mappings":"AAAA;;;;;CAKC,GAED,+BAA+B;AAC/B,O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;IAEA,MAAMM,IAAID,UAAU,CAAC,EAAE,GAAG;IAC1B,MAAME,KAAKD,IAAI;IACf,MAAME,YAAY,CAAC,CAAEF,CAAAA,IAAI,CAAA;IACzB,MAAMG,KAAKD,YAAY;IACvB,MAAME,KAAK,CAAC,CAAEF,CAAAA,YAAY,CAAA;IAE1B,IAAID,KAAK5B,yBAAyB8B,KAAK,KAAKC,KAAK9B,sBAAsB;QACrE,MAAM,IAAIoB,MAAM;IAClB;IAEA,IAAIW,iBAAiB;IACrB,IAAK,IAAIT,IAAI,GAAGA,IAAI,GAAGA,IAAK;QAC1BS,kBAAkB,AAACN,CAAAA,UAAU,CAAC,IAAIH,EAAE,GAAG,IAAG,KAAOA,IAAI;IACvD;IAEA,OAAO;QAAEK;QAAIE;QAAIC;QAAIC;IAAe;AACtC;AAEA;;CAEC,GACD,OAAO,MAAMC,gBAAgB;IAC3BC,KAAK;IACLC,wBAAwB;IACxBC,cAAc;IACdC,2BAA2B;AAC7B,EAAW;AAEX;;CAEC,GACD,OAAO,SAASC,mBAAmBC,OAAe;IAChD,OAAOA,WAAW;AACpB;AAEA;;CAEC,GACD,OAAO,SAASC,qBAAqBD,OAAe;IAClD,OAAOA,WAAW;AACpB;AAEA;;CAEC,GACD,OAAO,SAASE,oBAAoBF,OAAe;IACjD,OAAOA,UAAU;AACnB;AAEA;;CAEC,GACD,OAAO,SAASG,yBAAyBC,IAAY;IACnD,IAAIA,OAAO,IAAI;QACb,MAAM,IAAItB,MAAM;IAClB;IACA,IAAIsB,SAAS,IAAI;QACf,OAAO;IACT;IACA,MAAMC,OAAO,IAAKD,OAAO;IACzB,MAAME,MAAM,AAACF,CAAAA,SAAS,CAAA,IAAK;IAC3B,OAAOC,QAAQC;AACjB"}
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,10 @@
1
+ import type { Transform as TransformType } from 'stream';
2
+ type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer;
3
+ /**
4
+ * Helper to create a Transform stream from a synchronous decoder
5
+ *
6
+ * This buffers all input and applies the decoder when the stream ends.
7
+ * This is suitable for codecs that don't support true streaming.
8
+ */
9
+ export default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): InstanceType<typeof TransformType>;
10
+ export {};
@@ -0,0 +1,30 @@
1
+ import { bufferFrom, Transform } from 'extract-base-iterator';
2
+ /**
3
+ * Helper to create a Transform stream from a synchronous decoder
4
+ *
5
+ * This buffers all input and applies the decoder when the stream ends.
6
+ * This is suitable for codecs that don't support true streaming.
7
+ */ export default function createBufferingDecoder(decodeFn, properties, unpackSize) {
8
+ const chunks = [];
9
+ let _totalSize = 0;
10
+ return new Transform({
11
+ transform: (chunk, _encoding, callback)=>{
12
+ chunks.push(chunk);
13
+ _totalSize += chunk.length;
14
+ callback();
15
+ },
16
+ flush: function(callback) {
17
+ try {
18
+ // Concatenate all chunks
19
+ const input = bufferFrom(Buffer.concat(chunks));
20
+ // Decode using the synchronous decoder
21
+ const output = decodeFn(input, properties, unpackSize);
22
+ // Push the result
23
+ this.push(output);
24
+ callback();
25
+ } catch (err) {
26
+ callback(err);
27
+ }
28
+ }
29
+ });
30
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/utils/createBufferingDecoder.ts"],"sourcesContent":["import { bufferFrom, Transform } from 'extract-base-iterator';\nimport type { Transform as TransformType } from 'stream';\n\ntype DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer;\n\n/**\n * Helper to create a Transform stream from a synchronous decoder\n *\n * This buffers all input and applies the decoder when the stream ends.\n * This is suitable for codecs that don't support true streaming.\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): InstanceType<typeof TransformType> {\n const chunks: Buffer[] = [];\n let _totalSize = 0;\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: (err?: Error | null, data?: Buffer) => void) => {\n chunks.push(chunk);\n _totalSize += chunk.length;\n callback();\n },\n flush: function (this: InstanceType<typeof TransformType>, callback: (err?: Error | null) => void) {\n try {\n // Concatenate all chunks\n const input = bufferFrom(Buffer.concat(chunks));\n // Decode using the synchronous decoder\n const output = decodeFn(input, properties, unpackSize);\n // Push the result\n this.push(output);\n callback();\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["bufferFrom","Transform","createBufferingDecoder","decodeFn","properties","unpackSize","chunks","_totalSize","transform","chunk","_encoding","callback","push","length","flush","input","Buffer","concat","output","err"],"mappings":"AAAA,SAASA,UAAU,EAAEC,SAAS,QAAQ,wBAAwB;AAK9D;;;;;CAKC,GACD,eAAe,SAASC,uBAAuBC,QAAkB,EAAEC,UAAmB,EAAEC,UAAmB;IACzG,MAAMC,SAAmB,EAAE;IAC3B,IAAIC,aAAa;IAEjB,OAAO,IAAIN,UAAU;QACnBO,WAAW,CAACC,OAAeC,WAAmBC;YAC5CL,OAAOM,IAAI,CAACH;YACZF,cAAcE,MAAMI,MAAM;YAC1BF;QACF;QACAG,OAAO,SAAoDH,QAAsC;YAC/F,IAAI;gBACF,yBAAyB;gBACzB,MAAMI,QAAQf,WAAWgB,OAAOC,MAAM,CAACX;gBACvC,uCAAuC;gBACvC,MAAMY,SAASf,SAASY,OAAOX,YAAYC;gBAC3C,kBAAkB;gBAClB,IAAI,CAACO,IAAI,CAACM;gBACVP;YACF,EAAE,OAAOQ,KAAK;gBACZR,SAASQ;YACX;QACF;IACF;AACF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * XZ Decompression Module
3
+ *
4
+ * XZ is a container format that wraps LZMA2 compressed data.
5
+ * This module provides both synchronous and streaming XZ decoders.
6
+ *
7
+ * Pure JavaScript implementation, works on Node.js 0.8+
8
+ */
9
+ import type { Transform as TransformType } from 'stream';
10
+ /**
11
+ * Decompress XZ data synchronously
12
+ * Properly handles multi-block XZ files and stream padding
13
+ * @param input - XZ compressed data
14
+ * @returns Decompressed data
15
+ */
16
+ export declare function decodeXZ(input: Buffer): Buffer;
17
+ /**
18
+ * Create an XZ decompression Transform stream
19
+ * @returns Transform stream that decompresses XZ data
20
+ */
21
+ export declare function createXZDecoder(): TransformType;