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.
- package/LICENSE +42 -0
- package/README.md +248 -0
- package/dist/cjs/compat.d.cts +1 -0
- package/dist/cjs/compat.d.ts +1 -0
- package/dist/cjs/compat.js +23 -0
- package/dist/cjs/compat.js.map +1 -0
- package/dist/cjs/filters/bcj/Bcj.d.cts +16 -0
- package/dist/cjs/filters/bcj/Bcj.d.ts +16 -0
- package/dist/cjs/filters/bcj/Bcj.js +192 -0
- package/dist/cjs/filters/bcj/Bcj.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjArm.d.cts +16 -0
- package/dist/cjs/filters/bcj/BcjArm.d.ts +16 -0
- package/dist/cjs/filters/bcj/BcjArm.js +122 -0
- package/dist/cjs/filters/bcj/BcjArm.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjArm64.d.cts +21 -0
- package/dist/cjs/filters/bcj/BcjArm64.d.ts +21 -0
- package/dist/cjs/filters/bcj/BcjArm64.js +65 -0
- package/dist/cjs/filters/bcj/BcjArm64.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjArmt.d.cts +19 -0
- package/dist/cjs/filters/bcj/BcjArmt.d.ts +19 -0
- package/dist/cjs/filters/bcj/BcjArmt.js +76 -0
- package/dist/cjs/filters/bcj/BcjArmt.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjIa64.d.cts +15 -0
- package/dist/cjs/filters/bcj/BcjIa64.d.ts +15 -0
- package/dist/cjs/filters/bcj/BcjIa64.js +141 -0
- package/dist/cjs/filters/bcj/BcjIa64.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjPpc.d.cts +20 -0
- package/dist/cjs/filters/bcj/BcjPpc.d.ts +20 -0
- package/dist/cjs/filters/bcj/BcjPpc.js +64 -0
- package/dist/cjs/filters/bcj/BcjPpc.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjSparc.d.cts +19 -0
- package/dist/cjs/filters/bcj/BcjSparc.d.ts +19 -0
- package/dist/cjs/filters/bcj/BcjSparc.js +69 -0
- package/dist/cjs/filters/bcj/BcjSparc.js.map +1 -0
- package/dist/cjs/filters/delta/Delta.d.cts +16 -0
- package/dist/cjs/filters/delta/Delta.d.ts +16 -0
- package/dist/cjs/filters/delta/Delta.js +74 -0
- package/dist/cjs/filters/delta/Delta.js.map +1 -0
- package/dist/cjs/filters/index.d.cts +8 -0
- package/dist/cjs/filters/index.d.ts +8 -0
- package/dist/cjs/filters/index.js +27 -0
- package/dist/cjs/filters/index.js.map +1 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.d.cts +73 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.d.ts +73 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.js +148 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.js.map +1 -0
- package/dist/cjs/lzma/index.d.cts +31 -0
- package/dist/cjs/lzma/index.d.ts +31 -0
- package/dist/cjs/lzma/index.js +83 -0
- package/dist/cjs/lzma/index.js.map +1 -0
- package/dist/cjs/lzma/stream/transforms.d.cts +46 -0
- package/dist/cjs/lzma/stream/transforms.d.ts +46 -0
- package/dist/cjs/lzma/stream/transforms.js +193 -0
- package/dist/cjs/lzma/stream/transforms.js.map +1 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +63 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +63 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.js +231 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +97 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +97 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.js +582 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.js.map +1 -0
- package/dist/cjs/lzma/sync/RangeDecoder.d.cts +69 -0
- package/dist/cjs/lzma/sync/RangeDecoder.d.ts +69 -0
- package/dist/cjs/lzma/sync/RangeDecoder.js +162 -0
- package/dist/cjs/lzma/sync/RangeDecoder.js.map +1 -0
- package/dist/cjs/lzma/types.d.cts +117 -0
- package/dist/cjs/lzma/types.d.ts +117 -0
- package/dist/cjs/lzma/types.js +264 -0
- package/dist/cjs/lzma/types.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/utils/createBufferingDecoder.d.cts +10 -0
- package/dist/cjs/utils/createBufferingDecoder.d.ts +10 -0
- package/dist/cjs/utils/createBufferingDecoder.js +41 -0
- package/dist/cjs/utils/createBufferingDecoder.js.map +1 -0
- package/dist/cjs/xz/Decoder.d.cts +21 -0
- package/dist/cjs/xz/Decoder.d.ts +21 -0
- package/dist/cjs/xz/Decoder.js +325 -0
- package/dist/cjs/xz/Decoder.js.map +1 -0
- package/dist/esm/compat.d.ts +1 -0
- package/dist/esm/compat.js +7 -0
- package/dist/esm/compat.js.map +1 -0
- package/dist/esm/filters/bcj/Bcj.d.ts +16 -0
- package/dist/esm/filters/bcj/Bcj.js +184 -0
- package/dist/esm/filters/bcj/Bcj.js.map +1 -0
- package/dist/esm/filters/bcj/BcjArm.d.ts +16 -0
- package/dist/esm/filters/bcj/BcjArm.js +114 -0
- package/dist/esm/filters/bcj/BcjArm.js.map +1 -0
- package/dist/esm/filters/bcj/BcjArm64.d.ts +21 -0
- package/dist/esm/filters/bcj/BcjArm64.js +57 -0
- package/dist/esm/filters/bcj/BcjArm64.js.map +1 -0
- package/dist/esm/filters/bcj/BcjArmt.d.ts +19 -0
- package/dist/esm/filters/bcj/BcjArmt.js +66 -0
- package/dist/esm/filters/bcj/BcjArmt.js.map +1 -0
- package/dist/esm/filters/bcj/BcjIa64.d.ts +15 -0
- package/dist/esm/filters/bcj/BcjIa64.js +127 -0
- package/dist/esm/filters/bcj/BcjIa64.js.map +1 -0
- package/dist/esm/filters/bcj/BcjPpc.d.ts +20 -0
- package/dist/esm/filters/bcj/BcjPpc.js +55 -0
- package/dist/esm/filters/bcj/BcjPpc.js.map +1 -0
- package/dist/esm/filters/bcj/BcjSparc.d.ts +19 -0
- package/dist/esm/filters/bcj/BcjSparc.js +59 -0
- package/dist/esm/filters/bcj/BcjSparc.js.map +1 -0
- package/dist/esm/filters/delta/Delta.d.ts +16 -0
- package/dist/esm/filters/delta/Delta.js +66 -0
- package/dist/esm/filters/delta/Delta.js.map +1 -0
- package/dist/esm/filters/index.d.ts +8 -0
- package/dist/esm/filters/index.js +9 -0
- package/dist/esm/filters/index.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lzma/Lzma2ChunkParser.d.ts +73 -0
- package/dist/esm/lzma/Lzma2ChunkParser.js +137 -0
- package/dist/esm/lzma/Lzma2ChunkParser.js.map +1 -0
- package/dist/esm/lzma/index.d.ts +31 -0
- package/dist/esm/lzma/index.js +44 -0
- package/dist/esm/lzma/index.js.map +1 -0
- package/dist/esm/lzma/stream/transforms.d.ts +46 -0
- package/dist/esm/lzma/stream/transforms.js +190 -0
- package/dist/esm/lzma/stream/transforms.js.map +1 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +63 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.js +211 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -0
- package/dist/esm/lzma/sync/LzmaDecoder.d.ts +97 -0
- package/dist/esm/lzma/sync/LzmaDecoder.js +545 -0
- package/dist/esm/lzma/sync/LzmaDecoder.js.map +1 -0
- package/dist/esm/lzma/sync/RangeDecoder.d.ts +69 -0
- package/dist/esm/lzma/sync/RangeDecoder.js +132 -0
- package/dist/esm/lzma/sync/RangeDecoder.js.map +1 -0
- package/dist/esm/lzma/types.d.ts +117 -0
- package/dist/esm/lzma/types.js +154 -0
- package/dist/esm/lzma/types.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/utils/createBufferingDecoder.d.ts +10 -0
- package/dist/esm/utils/createBufferingDecoder.js +30 -0
- package/dist/esm/utils/createBufferingDecoder.js.map +1 -0
- package/dist/esm/xz/Decoder.d.ts +21 -0
- package/dist/esm/xz/Decoder.js +313 -0
- package/dist/esm/xz/Decoder.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// BCJ (PowerPC) filter codec - converts PowerPC branch instruction addresses
|
|
2
|
+
// This filter makes PowerPC executables more compressible by LZMA
|
|
3
|
+
//
|
|
4
|
+
// PowerPC is big-endian. Branch instructions use 26-bit signed offsets.
|
|
5
|
+
//
|
|
6
|
+
// Reference: https://github.com/kornelski/7z/blob/main/C/Bra.c
|
|
7
|
+
"use strict";
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
function _export(target, all) {
|
|
12
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
_export(exports, {
|
|
18
|
+
get createBcjPpcDecoder () {
|
|
19
|
+
return createBcjPpcDecoder;
|
|
20
|
+
},
|
|
21
|
+
get decodeBcjPpc () {
|
|
22
|
+
return decodeBcjPpc;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var _extractbaseiterator = require("extract-base-iterator");
|
|
26
|
+
var _createBufferingDecoderts = /*#__PURE__*/ _interop_require_default(require("../../utils/createBufferingDecoder.js"));
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function decodeBcjPpc(input, _properties, _unpackSize) {
|
|
33
|
+
var output = (0, _extractbaseiterator.bufferFrom)(input); // Copy since we modify in place
|
|
34
|
+
var pos = 0;
|
|
35
|
+
// Process 4-byte aligned positions
|
|
36
|
+
while(pos + 4 <= output.length){
|
|
37
|
+
// Read 32-bit value (big-endian)
|
|
38
|
+
var instr = output[pos] << 24 | output[pos + 1] << 16 | output[pos + 2] << 8 | output[pos + 3];
|
|
39
|
+
// Check for B/BL instruction: (instr & 0xFC000003) === 0x48000001
|
|
40
|
+
if ((instr & 0xfc000003) === 0x48000001) {
|
|
41
|
+
// Extract 26-bit offset (bits 2-27, the LI field)
|
|
42
|
+
var addr = instr & 0x03fffffc;
|
|
43
|
+
// Sign-extend 26-bit to 32-bit
|
|
44
|
+
if (addr & 0x02000000) {
|
|
45
|
+
addr |= 0xfc000000;
|
|
46
|
+
}
|
|
47
|
+
// Convert absolute to relative: subtract current position
|
|
48
|
+
var relAddr = addr - pos;
|
|
49
|
+
// Clear old offset and write new one
|
|
50
|
+
instr = instr & 0xfc000003 | relAddr & 0x03fffffc;
|
|
51
|
+
// Write back (big-endian)
|
|
52
|
+
output[pos] = instr >>> 24 & 0xff;
|
|
53
|
+
output[pos + 1] = instr >>> 16 & 0xff;
|
|
54
|
+
output[pos + 2] = instr >>> 8 & 0xff;
|
|
55
|
+
output[pos + 3] = instr & 0xff;
|
|
56
|
+
}
|
|
57
|
+
pos += 4;
|
|
58
|
+
}
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
61
|
+
function createBcjPpcDecoder(properties, unpackSize) {
|
|
62
|
+
return (0, _createBufferingDecoderts.default)(decodeBcjPpc, properties, unpackSize);
|
|
63
|
+
}
|
|
64
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/filters/bcj/BcjPpc.ts"],"sourcesContent":["// BCJ (PowerPC) filter codec - converts PowerPC branch instruction addresses\n// This filter makes PowerPC executables more compressible by LZMA\n//\n// PowerPC is big-endian. Branch instructions use 26-bit signed offsets.\n//\n// Reference: https://github.com/kornelski/7z/blob/main/C/Bra.c\n\nimport { bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'stream';\nimport createBufferingDecoder from '../../utils/createBufferingDecoder.ts';\n\n/**\n * Decode PowerPC BCJ filtered data\n * Reverses the BCJ transformation by converting absolute addresses back to relative\n *\n * PowerPC B/BL instruction format (big-endian):\n * - 4 bytes aligned\n * - Opcode 0x48 in high byte with AA=0, LK=1 (0x48000001 mask 0xFC000003)\n * - Bits 6-29 are 24-bit signed offset (in words)\n *\n * @param input - PowerPC BCJ filtered data\n * @param _properties - Unused for PowerPC BCJ\n * @param _unpackSize - Unused for PowerPC BCJ\n * @returns Unfiltered data\n */\nexport function decodeBcjPpc(input: Buffer, _properties?: Buffer, _unpackSize?: number): Buffer {\n const output = bufferFrom(input); // Copy since we modify in place\n let pos = 0;\n\n // Process 4-byte aligned positions\n while (pos + 4 <= output.length) {\n // Read 32-bit value (big-endian)\n let instr = (output[pos] << 24) | (output[pos + 1] << 16) | (output[pos + 2] << 8) | output[pos + 3];\n\n // Check for B/BL instruction: (instr & 0xFC000003) === 0x48000001\n if ((instr & 0xfc000003) === 0x48000001) {\n // Extract 26-bit offset (bits 2-27, the LI field)\n let addr = instr & 0x03fffffc;\n\n // Sign-extend 26-bit to 32-bit\n if (addr & 0x02000000) {\n addr |= 0xfc000000;\n }\n\n // Convert absolute to relative: subtract current position\n const relAddr = addr - pos;\n\n // Clear old offset and write new one\n instr = (instr & 0xfc000003) | (relAddr & 0x03fffffc);\n\n // Write back (big-endian)\n output[pos] = (instr >>> 24) & 0xff;\n output[pos + 1] = (instr >>> 16) & 0xff;\n output[pos + 2] = (instr >>> 8) & 0xff;\n output[pos + 3] = instr & 0xff;\n }\n pos += 4;\n }\n\n return output;\n}\n\n/**\n * Create a PowerPC BCJ decoder Transform stream\n */\nexport function createBcjPpcDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeBcjPpc, properties, unpackSize);\n}\n"],"names":["createBcjPpcDecoder","decodeBcjPpc","input","_properties","_unpackSize","output","bufferFrom","pos","length","instr","addr","relAddr","properties","unpackSize","createBufferingDecoder"],"mappings":"AAAA,6EAA6E;AAC7E,kEAAkE;AAClE,EAAE;AACF,wEAAwE;AACxE,EAAE;AACF,+DAA+D;;;;;;;;;;;;QA4D/CA;eAAAA;;QAxCAC;eAAAA;;;mCAlBW;+EAEQ;;;;;;AAgB5B,SAASA,aAAaC,KAAa,EAAEC,WAAoB,EAAEC,WAAoB;IACpF,IAAMC,SAASC,IAAAA,+BAAU,EAACJ,QAAQ,gCAAgC;IAClE,IAAIK,MAAM;IAEV,mCAAmC;IACnC,MAAOA,MAAM,KAAKF,OAAOG,MAAM,CAAE;QAC/B,iCAAiC;QACjC,IAAIC,QAAQ,AAACJ,MAAM,CAACE,IAAI,IAAI,KAAOF,MAAM,CAACE,MAAM,EAAE,IAAI,KAAOF,MAAM,CAACE,MAAM,EAAE,IAAI,IAAKF,MAAM,CAACE,MAAM,EAAE;QAEpG,kEAAkE;QAClE,IAAI,AAACE,CAAAA,QAAQ,UAAS,MAAO,YAAY;YACvC,kDAAkD;YAClD,IAAIC,OAAOD,QAAQ;YAEnB,+BAA+B;YAC/B,IAAIC,OAAO,YAAY;gBACrBA,QAAQ;YACV;YAEA,0DAA0D;YAC1D,IAAMC,UAAUD,OAAOH;YAEvB,qCAAqC;YACrCE,QAAQ,AAACA,QAAQ,aAAeE,UAAU;YAE1C,0BAA0B;YAC1BN,MAAM,CAACE,IAAI,GAAG,AAACE,UAAU,KAAM;YAC/BJ,MAAM,CAACE,MAAM,EAAE,GAAG,AAACE,UAAU,KAAM;YACnCJ,MAAM,CAACE,MAAM,EAAE,GAAG,AAACE,UAAU,IAAK;YAClCJ,MAAM,CAACE,MAAM,EAAE,GAAGE,QAAQ;QAC5B;QACAF,OAAO;IACT;IAEA,OAAOF;AACT;AAKO,SAASL,oBAAoBY,UAAmB,EAAEC,UAAmB;IAC1E,OAAOC,IAAAA,iCAAsB,EAACb,cAAcW,YAAYC;AAC1D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Transform } from 'stream';
|
|
2
|
+
/**
|
|
3
|
+
* Decode SPARC BCJ filtered data
|
|
4
|
+
* Reverses the BCJ transformation by converting absolute addresses back to relative
|
|
5
|
+
*
|
|
6
|
+
* SPARC CALL instruction matching (big-endian):
|
|
7
|
+
* - First byte 0x40 and (second byte & 0xC0) == 0x00, OR
|
|
8
|
+
* - First byte 0x7F and (second byte & 0xC0) == 0xC0
|
|
9
|
+
*
|
|
10
|
+
* @param input - SPARC BCJ filtered data
|
|
11
|
+
* @param _properties - Unused for SPARC BCJ
|
|
12
|
+
* @param _unpackSize - Unused for SPARC BCJ
|
|
13
|
+
* @returns Unfiltered data
|
|
14
|
+
*/
|
|
15
|
+
export declare function decodeBcjSparc(input: Buffer, _properties?: Buffer, _unpackSize?: number): Buffer;
|
|
16
|
+
/**
|
|
17
|
+
* Create a SPARC BCJ decoder Transform stream
|
|
18
|
+
*/
|
|
19
|
+
export declare function createBcjSparcDecoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Transform } from 'stream';
|
|
2
|
+
/**
|
|
3
|
+
* Decode SPARC BCJ filtered data
|
|
4
|
+
* Reverses the BCJ transformation by converting absolute addresses back to relative
|
|
5
|
+
*
|
|
6
|
+
* SPARC CALL instruction matching (big-endian):
|
|
7
|
+
* - First byte 0x40 and (second byte & 0xC0) == 0x00, OR
|
|
8
|
+
* - First byte 0x7F and (second byte & 0xC0) == 0xC0
|
|
9
|
+
*
|
|
10
|
+
* @param input - SPARC BCJ filtered data
|
|
11
|
+
* @param _properties - Unused for SPARC BCJ
|
|
12
|
+
* @param _unpackSize - Unused for SPARC BCJ
|
|
13
|
+
* @returns Unfiltered data
|
|
14
|
+
*/
|
|
15
|
+
export declare function decodeBcjSparc(input: Buffer, _properties?: Buffer, _unpackSize?: number): Buffer;
|
|
16
|
+
/**
|
|
17
|
+
* Create a SPARC BCJ decoder Transform stream
|
|
18
|
+
*/
|
|
19
|
+
export declare function createBcjSparcDecoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// BCJ (SPARC) filter codec - converts SPARC branch instruction addresses
|
|
2
|
+
// This filter makes SPARC executables more compressible by LZMA
|
|
3
|
+
//
|
|
4
|
+
// SPARC is big-endian. CALL instructions use 30-bit signed offsets.
|
|
5
|
+
// The filter only transforms CALL instructions with specific byte patterns.
|
|
6
|
+
//
|
|
7
|
+
// Reference: https://github.com/kornelski/7z/blob/main/C/Bra.c
|
|
8
|
+
"use strict";
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
function _export(target, all) {
|
|
13
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
_export(exports, {
|
|
19
|
+
get createBcjSparcDecoder () {
|
|
20
|
+
return createBcjSparcDecoder;
|
|
21
|
+
},
|
|
22
|
+
get decodeBcjSparc () {
|
|
23
|
+
return decodeBcjSparc;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
var _extractbaseiterator = require("extract-base-iterator");
|
|
27
|
+
var _createBufferingDecoderts = /*#__PURE__*/ _interop_require_default(require("../../utils/createBufferingDecoder.js"));
|
|
28
|
+
function _interop_require_default(obj) {
|
|
29
|
+
return obj && obj.__esModule ? obj : {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function decodeBcjSparc(input, _properties, _unpackSize) {
|
|
34
|
+
var output = (0, _extractbaseiterator.bufferFrom)(input); // Copy since we modify in place
|
|
35
|
+
var pos = 0;
|
|
36
|
+
// Process 4-byte aligned positions
|
|
37
|
+
while(pos + 4 <= output.length){
|
|
38
|
+
var b0 = output[pos];
|
|
39
|
+
var b1 = output[pos + 1];
|
|
40
|
+
// Check for CALL instruction with specific byte patterns:
|
|
41
|
+
// (b0 == 0x40 && (b1 & 0xC0) == 0x00) || (b0 == 0x7F && (b1 & 0xC0) == 0xC0)
|
|
42
|
+
if (b0 === 0x40 && (b1 & 0xc0) === 0x00 || b0 === 0x7f && (b1 & 0xc0) === 0xc0) {
|
|
43
|
+
// Read 32-bit value (big-endian)
|
|
44
|
+
var src = b0 << 24 | b1 << 16 | output[pos + 2] << 8 | output[pos + 3];
|
|
45
|
+
// Shift left by 2 (multiply by 4 for word addressing)
|
|
46
|
+
src <<= 2;
|
|
47
|
+
// Decoding: subtract position
|
|
48
|
+
var dest = src - pos;
|
|
49
|
+
// Shift right by 2
|
|
50
|
+
dest >>>= 2;
|
|
51
|
+
// Reconstruct with sign extension and opcode
|
|
52
|
+
// (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000
|
|
53
|
+
var signBit = dest >>> 22 & 1;
|
|
54
|
+
var signExtend = signBit ? 0x3fc00000 : 0;
|
|
55
|
+
dest = signExtend | dest & 0x3fffff | 0x40000000;
|
|
56
|
+
// Write back (big-endian)
|
|
57
|
+
output[pos] = dest >>> 24 & 0xff;
|
|
58
|
+
output[pos + 1] = dest >>> 16 & 0xff;
|
|
59
|
+
output[pos + 2] = dest >>> 8 & 0xff;
|
|
60
|
+
output[pos + 3] = dest & 0xff;
|
|
61
|
+
}
|
|
62
|
+
pos += 4;
|
|
63
|
+
}
|
|
64
|
+
return output;
|
|
65
|
+
}
|
|
66
|
+
function createBcjSparcDecoder(properties, unpackSize) {
|
|
67
|
+
return (0, _createBufferingDecoderts.default)(decodeBcjSparc, properties, unpackSize);
|
|
68
|
+
}
|
|
69
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/filters/bcj/BcjSparc.ts"],"sourcesContent":["// BCJ (SPARC) filter codec - converts SPARC branch instruction addresses\n// This filter makes SPARC executables more compressible by LZMA\n//\n// SPARC is big-endian. CALL instructions use 30-bit signed offsets.\n// The filter only transforms CALL instructions with specific byte patterns.\n//\n// Reference: https://github.com/kornelski/7z/blob/main/C/Bra.c\n\nimport { bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'stream';\nimport createBufferingDecoder from '../../utils/createBufferingDecoder.ts';\n\n/**\n * Decode SPARC BCJ filtered data\n * Reverses the BCJ transformation by converting absolute addresses back to relative\n *\n * SPARC CALL instruction matching (big-endian):\n * - First byte 0x40 and (second byte & 0xC0) == 0x00, OR\n * - First byte 0x7F and (second byte & 0xC0) == 0xC0\n *\n * @param input - SPARC BCJ filtered data\n * @param _properties - Unused for SPARC BCJ\n * @param _unpackSize - Unused for SPARC BCJ\n * @returns Unfiltered data\n */\nexport function decodeBcjSparc(input: Buffer, _properties?: Buffer, _unpackSize?: number): Buffer {\n const output = bufferFrom(input); // Copy since we modify in place\n let pos = 0;\n\n // Process 4-byte aligned positions\n while (pos + 4 <= output.length) {\n const b0 = output[pos];\n const b1 = output[pos + 1];\n\n // Check for CALL instruction with specific byte patterns:\n // (b0 == 0x40 && (b1 & 0xC0) == 0x00) || (b0 == 0x7F && (b1 & 0xC0) == 0xC0)\n if ((b0 === 0x40 && (b1 & 0xc0) === 0x00) || (b0 === 0x7f && (b1 & 0xc0) === 0xc0)) {\n // Read 32-bit value (big-endian)\n let src = (b0 << 24) | (b1 << 16) | (output[pos + 2] << 8) | output[pos + 3];\n\n // Shift left by 2 (multiply by 4 for word addressing)\n src <<= 2;\n\n // Decoding: subtract position\n let dest = src - pos;\n\n // Shift right by 2\n dest >>>= 2;\n\n // Reconstruct with sign extension and opcode\n // (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000\n const signBit = (dest >>> 22) & 1;\n const signExtend = signBit ? 0x3fc00000 : 0;\n dest = signExtend | (dest & 0x3fffff) | 0x40000000;\n\n // Write back (big-endian)\n output[pos] = (dest >>> 24) & 0xff;\n output[pos + 1] = (dest >>> 16) & 0xff;\n output[pos + 2] = (dest >>> 8) & 0xff;\n output[pos + 3] = dest & 0xff;\n }\n\n pos += 4;\n }\n\n return output;\n}\n\n/**\n * Create a SPARC BCJ decoder Transform stream\n */\nexport function createBcjSparcDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeBcjSparc, properties, unpackSize);\n}\n"],"names":["createBcjSparcDecoder","decodeBcjSparc","input","_properties","_unpackSize","output","bufferFrom","pos","length","b0","b1","src","dest","signBit","signExtend","properties","unpackSize","createBufferingDecoder"],"mappings":"AAAA,yEAAyE;AACzE,gEAAgE;AAChE,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,EAAE;AACF,+DAA+D;;;;;;;;;;;;QAiE/CA;eAAAA;;QA9CAC;eAAAA;;;mCAjBW;+EAEQ;;;;;;AAe5B,SAASA,eAAeC,KAAa,EAAEC,WAAoB,EAAEC,WAAoB;IACtF,IAAMC,SAASC,IAAAA,+BAAU,EAACJ,QAAQ,gCAAgC;IAClE,IAAIK,MAAM;IAEV,mCAAmC;IACnC,MAAOA,MAAM,KAAKF,OAAOG,MAAM,CAAE;QAC/B,IAAMC,KAAKJ,MAAM,CAACE,IAAI;QACtB,IAAMG,KAAKL,MAAM,CAACE,MAAM,EAAE;QAE1B,0DAA0D;QAC1D,6EAA6E;QAC7E,IAAI,AAACE,OAAO,QAAQ,AAACC,CAAAA,KAAK,IAAG,MAAO,QAAUD,OAAO,QAAQ,AAACC,CAAAA,KAAK,IAAG,MAAO,MAAO;YAClF,iCAAiC;YACjC,IAAIC,MAAM,AAACF,MAAM,KAAOC,MAAM,KAAOL,MAAM,CAACE,MAAM,EAAE,IAAI,IAAKF,MAAM,CAACE,MAAM,EAAE;YAE5E,sDAAsD;YACtDI,QAAQ;YAER,8BAA8B;YAC9B,IAAIC,OAAOD,MAAMJ;YAEjB,mBAAmB;YACnBK,UAAU;YAEV,6CAA6C;YAC7C,mFAAmF;YACnF,IAAMC,UAAU,AAACD,SAAS,KAAM;YAChC,IAAME,aAAaD,UAAU,aAAa;YAC1CD,OAAOE,aAAcF,OAAO,WAAY;YAExC,0BAA0B;YAC1BP,MAAM,CAACE,IAAI,GAAG,AAACK,SAAS,KAAM;YAC9BP,MAAM,CAACE,MAAM,EAAE,GAAG,AAACK,SAAS,KAAM;YAClCP,MAAM,CAACE,MAAM,EAAE,GAAG,AAACK,SAAS,IAAK;YACjCP,MAAM,CAACE,MAAM,EAAE,GAAGK,OAAO;QAC3B;QAEAL,OAAO;IACT;IAEA,OAAOF;AACT;AAKO,SAASL,sBAAsBe,UAAmB,EAAEC,UAAmB;IAC5E,OAAOC,IAAAA,iCAAsB,EAAChB,gBAAgBc,YAAYC;AAC5D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transform } from 'extract-base-iterator';
|
|
2
|
+
/**
|
|
3
|
+
* Decode Delta filtered data (synchronous, for buffered use)
|
|
4
|
+
* Reverses the delta transformation by adding previous values
|
|
5
|
+
*
|
|
6
|
+
* @param input - Delta filtered data
|
|
7
|
+
* @param properties - Optional 1-byte properties (distance - 1)
|
|
8
|
+
* @param _unpackSize - Unused for Delta
|
|
9
|
+
* @returns Unfiltered data
|
|
10
|
+
*/
|
|
11
|
+
export declare function decodeDelta(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer;
|
|
12
|
+
/**
|
|
13
|
+
* Create a streaming Delta decoder Transform.
|
|
14
|
+
* Processes data chunk by chunk, maintaining state between chunks.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createDeltaDecoder(properties?: Buffer, _unpackSize?: number): InstanceType<typeof Transform>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transform } from 'extract-base-iterator';
|
|
2
|
+
/**
|
|
3
|
+
* Decode Delta filtered data (synchronous, for buffered use)
|
|
4
|
+
* Reverses the delta transformation by adding previous values
|
|
5
|
+
*
|
|
6
|
+
* @param input - Delta filtered data
|
|
7
|
+
* @param properties - Optional 1-byte properties (distance - 1)
|
|
8
|
+
* @param _unpackSize - Unused for Delta
|
|
9
|
+
* @returns Unfiltered data
|
|
10
|
+
*/
|
|
11
|
+
export declare function decodeDelta(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer;
|
|
12
|
+
/**
|
|
13
|
+
* Create a streaming Delta decoder Transform.
|
|
14
|
+
* Processes data chunk by chunk, maintaining state between chunks.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createDeltaDecoder(properties?: Buffer, _unpackSize?: number): InstanceType<typeof Transform>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Delta filter codec - stores differences between consecutive bytes
|
|
2
|
+
// Useful for data with gradual changes (images, audio, sensor data)
|
|
3
|
+
//
|
|
4
|
+
// The Delta filter stores the difference between each byte and the byte
|
|
5
|
+
// N positions before it, where N is the "distance" parameter (default 1).
|
|
6
|
+
// This makes data with regular patterns more compressible.
|
|
7
|
+
//
|
|
8
|
+
// This implementation uses true streaming - processes data chunk by chunk
|
|
9
|
+
// while maintaining state between chunks.
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", {
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
function _export(target, all) {
|
|
15
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
_export(exports, {
|
|
21
|
+
get createDeltaDecoder () {
|
|
22
|
+
return createDeltaDecoder;
|
|
23
|
+
},
|
|
24
|
+
get decodeDelta () {
|
|
25
|
+
return decodeDelta;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
var _extractbaseiterator = require("extract-base-iterator");
|
|
29
|
+
function decodeDelta(input, properties, _unpackSize) {
|
|
30
|
+
// Distance parameter: default is 1
|
|
31
|
+
var distance = 1;
|
|
32
|
+
if (properties && properties.length >= 1) {
|
|
33
|
+
// Properties byte contains (distance - 1)
|
|
34
|
+
distance = properties[0] + 1;
|
|
35
|
+
}
|
|
36
|
+
var output = (0, _extractbaseiterator.bufferFrom)(input); // Copy since we modify in place
|
|
37
|
+
// State buffer for multi-byte distance
|
|
38
|
+
var state = [];
|
|
39
|
+
for(var i = 0; i < distance; i++){
|
|
40
|
+
state.push(0);
|
|
41
|
+
}
|
|
42
|
+
for(var j = 0; j < output.length; j++){
|
|
43
|
+
var idx = j % distance;
|
|
44
|
+
state[idx] = state[idx] + output[j] & 0xff;
|
|
45
|
+
output[j] = state[idx];
|
|
46
|
+
}
|
|
47
|
+
return output;
|
|
48
|
+
}
|
|
49
|
+
function createDeltaDecoder(properties, _unpackSize) {
|
|
50
|
+
// Distance parameter: default is 1
|
|
51
|
+
var distance = 1;
|
|
52
|
+
if (properties && properties.length >= 1) {
|
|
53
|
+
distance = properties[0] + 1;
|
|
54
|
+
}
|
|
55
|
+
// State buffer for multi-byte distance
|
|
56
|
+
var state = [];
|
|
57
|
+
for(var i = 0; i < distance; i++){
|
|
58
|
+
state.push(0);
|
|
59
|
+
}
|
|
60
|
+
var byteIndex = 0;
|
|
61
|
+
return new _extractbaseiterator.Transform({
|
|
62
|
+
transform: function(chunk, _encoding, callback) {
|
|
63
|
+
var output = (0, _extractbaseiterator.allocBuffer)(chunk.length);
|
|
64
|
+
for(var j = 0; j < chunk.length; j++){
|
|
65
|
+
var idx = byteIndex % distance;
|
|
66
|
+
state[idx] = state[idx] + chunk[j] & 0xff;
|
|
67
|
+
output[j] = state[idx];
|
|
68
|
+
byteIndex++;
|
|
69
|
+
}
|
|
70
|
+
callback(null, output);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/filters/delta/Delta.ts"],"sourcesContent":["// Delta filter codec - stores differences between consecutive bytes\n// Useful for data with gradual changes (images, audio, sensor data)\n//\n// The Delta filter stores the difference between each byte and the byte\n// N positions before it, where N is the \"distance\" parameter (default 1).\n// This makes data with regular patterns more compressible.\n//\n// This implementation uses true streaming - processes data chunk by chunk\n// while maintaining state between chunks.\n\nimport { allocBuffer, bufferFrom, Transform } from 'extract-base-iterator';\n\n/**\n * Decode Delta filtered data (synchronous, for buffered use)\n * Reverses the delta transformation by adding previous values\n *\n * @param input - Delta filtered data\n * @param properties - Optional 1-byte properties (distance - 1)\n * @param _unpackSize - Unused for Delta\n * @returns Unfiltered data\n */\nexport function decodeDelta(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer {\n // Distance parameter: default is 1\n let distance = 1;\n if (properties && properties.length >= 1) {\n // Properties byte contains (distance - 1)\n distance = properties[0] + 1;\n }\n\n const output = bufferFrom(input); // Copy since we modify in place\n\n // State buffer for multi-byte distance\n const state: number[] = [];\n for (let i = 0; i < distance; i++) {\n state.push(0);\n }\n\n for (let j = 0; j < output.length; j++) {\n const idx = j % distance;\n state[idx] = (state[idx] + output[j]) & 0xff;\n output[j] = state[idx];\n }\n\n return output;\n}\n\n/**\n * Create a streaming Delta decoder Transform.\n * Processes data chunk by chunk, maintaining state between chunks.\n */\nexport function createDeltaDecoder(properties?: Buffer, _unpackSize?: number): InstanceType<typeof Transform> {\n // Distance parameter: default is 1\n let distance = 1;\n if (properties && properties.length >= 1) {\n distance = properties[0] + 1;\n }\n\n // State buffer for multi-byte distance\n const state: number[] = [];\n for (let i = 0; i < distance; i++) {\n state.push(0);\n }\n\n let byteIndex = 0;\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: (err?: Error | null, data?: Buffer) => void) => {\n const output = allocBuffer(chunk.length);\n\n for (let j = 0; j < chunk.length; j++) {\n const idx = byteIndex % distance;\n state[idx] = (state[idx] + chunk[j]) & 0xff;\n output[j] = state[idx];\n byteIndex++;\n }\n\n callback(null, output);\n },\n });\n}\n"],"names":["createDeltaDecoder","decodeDelta","input","properties","_unpackSize","distance","length","output","bufferFrom","state","i","push","j","idx","byteIndex","Transform","transform","chunk","_encoding","callback","allocBuffer"],"mappings":"AAAA,oEAAoE;AACpE,oEAAoE;AACpE,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,0CAA0C;;;;;;;;;;;;QA0C1BA;eAAAA;;QA7BAC;eAAAA;;;mCAXmC;AAW5C,SAASA,YAAYC,KAAa,EAAEC,UAAmB,EAAEC,WAAoB;IAClF,mCAAmC;IACnC,IAAIC,WAAW;IACf,IAAIF,cAAcA,WAAWG,MAAM,IAAI,GAAG;QACxC,0CAA0C;QAC1CD,WAAWF,UAAU,CAAC,EAAE,GAAG;IAC7B;IAEA,IAAMI,SAASC,IAAAA,+BAAU,EAACN,QAAQ,gCAAgC;IAElE,uCAAuC;IACvC,IAAMO,QAAkB,EAAE;IAC1B,IAAK,IAAIC,IAAI,GAAGA,IAAIL,UAAUK,IAAK;QACjCD,MAAME,IAAI,CAAC;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIL,OAAOD,MAAM,EAAEM,IAAK;QACtC,IAAMC,MAAMD,IAAIP;QAChBI,KAAK,CAACI,IAAI,GAAG,AAACJ,KAAK,CAACI,IAAI,GAAGN,MAAM,CAACK,EAAE,GAAI;QACxCL,MAAM,CAACK,EAAE,GAAGH,KAAK,CAACI,IAAI;IACxB;IAEA,OAAON;AACT;AAMO,SAASP,mBAAmBG,UAAmB,EAAEC,WAAoB;IAC1E,mCAAmC;IACnC,IAAIC,WAAW;IACf,IAAIF,cAAcA,WAAWG,MAAM,IAAI,GAAG;QACxCD,WAAWF,UAAU,CAAC,EAAE,GAAG;IAC7B;IAEA,uCAAuC;IACvC,IAAMM,QAAkB,EAAE;IAC1B,IAAK,IAAIC,IAAI,GAAGA,IAAIL,UAAUK,IAAK;QACjCD,MAAME,IAAI,CAAC;IACb;IAEA,IAAIG,YAAY;IAEhB,OAAO,IAAIC,8BAAS,CAAC;QACnBC,WAAW,SAACC,OAAeC,WAAmBC;YAC5C,IAAMZ,SAASa,IAAAA,gCAAW,EAACH,MAAMX,MAAM;YAEvC,IAAK,IAAIM,IAAI,GAAGA,IAAIK,MAAMX,MAAM,EAAEM,IAAK;gBACrC,IAAMC,MAAMC,YAAYT;gBACxBI,KAAK,CAACI,IAAI,GAAG,AAACJ,KAAK,CAACI,IAAI,GAAGI,KAAK,CAACL,EAAE,GAAI;gBACvCL,MAAM,CAACK,EAAE,GAAGH,KAAK,CAACI,IAAI;gBACtBC;YACF;YAEAK,SAAS,MAAMZ;QACjB;IACF;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './bcj/Bcj.js';
|
|
2
|
+
export * from './bcj/BcjArm.js';
|
|
3
|
+
export * from './bcj/BcjArm64.js';
|
|
4
|
+
export * from './bcj/BcjArmt.js';
|
|
5
|
+
export * from './bcj/BcjIa64.js';
|
|
6
|
+
export * from './bcj/BcjPpc.js';
|
|
7
|
+
export * from './bcj/BcjSparc.js';
|
|
8
|
+
export * from './delta/Delta.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './bcj/Bcj.js';
|
|
2
|
+
export * from './bcj/BcjArm.js';
|
|
3
|
+
export * from './bcj/BcjArm64.js';
|
|
4
|
+
export * from './bcj/BcjArmt.js';
|
|
5
|
+
export * from './bcj/BcjIa64.js';
|
|
6
|
+
export * from './bcj/BcjPpc.js';
|
|
7
|
+
export * from './bcj/BcjSparc.js';
|
|
8
|
+
export * from './delta/Delta.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Filter implementations for XZ/LZMA
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
_export_star(require("./bcj/Bcj.js"), exports);
|
|
7
|
+
_export_star(require("./bcj/BcjArm.js"), exports);
|
|
8
|
+
_export_star(require("./bcj/BcjArm64.js"), exports);
|
|
9
|
+
_export_star(require("./bcj/BcjArmt.js"), exports);
|
|
10
|
+
_export_star(require("./bcj/BcjIa64.js"), exports);
|
|
11
|
+
_export_star(require("./bcj/BcjPpc.js"), exports);
|
|
12
|
+
_export_star(require("./bcj/BcjSparc.js"), exports);
|
|
13
|
+
_export_star(require("./delta/Delta.js"), exports);
|
|
14
|
+
function _export_star(from, to) {
|
|
15
|
+
Object.keys(from).forEach(function(k) {
|
|
16
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
17
|
+
Object.defineProperty(to, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return from[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return from;
|
|
26
|
+
}
|
|
27
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/filters/index.ts"],"sourcesContent":["// Filter implementations for XZ/LZMA\n\nexport * from './bcj/Bcj.ts';\nexport * from './bcj/BcjArm.ts';\nexport * from './bcj/BcjArm64.ts';\nexport * from './bcj/BcjArmt.ts';\nexport * from './bcj/BcjIa64.ts';\nexport * from './bcj/BcjPpc.ts';\nexport * from './bcj/BcjSparc.ts';\nexport * from './delta/Delta.ts';\n"],"names":[],"mappings":"AAAA,qCAAqC;;;;;qBAEvB;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './filters/index.js';
|
|
2
|
+
export type { OutputSink } from './lzma/index.js';
|
|
3
|
+
export { createLzma2Decoder, createLzmaDecoder, decodeLzma, decodeLzma2, detectLzmaFormat, Lzma2Decoder, LzmaDecoder, } from './lzma/index.js';
|
|
4
|
+
export { createXZDecoder, decodeXZ } from './xz/Decoder.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './filters/index.js';
|
|
2
|
+
export type { OutputSink } from './lzma/index.js';
|
|
3
|
+
export { createLzma2Decoder, createLzmaDecoder, decodeLzma, decodeLzma2, detectLzmaFormat, Lzma2Decoder, LzmaDecoder, } from './lzma/index.js';
|
|
4
|
+
export { createXZDecoder, decodeXZ } from './xz/Decoder.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// XZ and LZMA decoders for external use
|
|
2
|
+
// Re-export filters for convenience
|
|
3
|
+
"use strict";
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
function _export(target, all) {
|
|
8
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
_export(exports, {
|
|
14
|
+
get Lzma2Decoder () {
|
|
15
|
+
return _indexts.Lzma2Decoder;
|
|
16
|
+
},
|
|
17
|
+
get LzmaDecoder () {
|
|
18
|
+
return _indexts.LzmaDecoder;
|
|
19
|
+
},
|
|
20
|
+
get createLzma2Decoder () {
|
|
21
|
+
return _indexts.createLzma2Decoder;
|
|
22
|
+
},
|
|
23
|
+
get createLzmaDecoder () {
|
|
24
|
+
return _indexts.createLzmaDecoder;
|
|
25
|
+
},
|
|
26
|
+
get createXZDecoder () {
|
|
27
|
+
return _Decoderts.createXZDecoder;
|
|
28
|
+
},
|
|
29
|
+
get decodeLzma () {
|
|
30
|
+
return _indexts.decodeLzma;
|
|
31
|
+
},
|
|
32
|
+
get decodeLzma2 () {
|
|
33
|
+
return _indexts.decodeLzma2;
|
|
34
|
+
},
|
|
35
|
+
get decodeXZ () {
|
|
36
|
+
return _Decoderts.decodeXZ;
|
|
37
|
+
},
|
|
38
|
+
get detectLzmaFormat () {
|
|
39
|
+
return _indexts.detectLzmaFormat;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
_export_star(require("./filters/index.js"), exports);
|
|
43
|
+
var _indexts = require("./lzma/index.js");
|
|
44
|
+
var _Decoderts = require("./xz/Decoder.js");
|
|
45
|
+
function _export_star(from, to) {
|
|
46
|
+
Object.keys(from).forEach(function(k) {
|
|
47
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
48
|
+
Object.defineProperty(to, k, {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function() {
|
|
51
|
+
return from[k];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return from;
|
|
57
|
+
}
|
|
58
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/index.ts"],"sourcesContent":["// XZ and LZMA decoders for external use\n\n// Re-export filters for convenience\nexport * from './filters/index.ts';\nexport type { OutputSink } from './lzma/index.ts';\nexport {\n createLzma2Decoder,\n createLzmaDecoder,\n decodeLzma,\n decodeLzma2,\n detectLzmaFormat,\n Lzma2Decoder,\n LzmaDecoder,\n} from './lzma/index.ts';\nexport { createXZDecoder, decodeXZ } from './xz/Decoder.ts';\n"],"names":["Lzma2Decoder","LzmaDecoder","createLzma2Decoder","createLzmaDecoder","createXZDecoder","decodeLzma","decodeLzma2","decodeXZ","detectLzmaFormat"],"mappings":"AAAA,wCAAwC;AAExC,oCAAoC;;;;;;;;;;;;QASlCA;eAAAA,qBAAY;;QACZC;eAAAA,oBAAW;;QANXC;eAAAA,2BAAkB;;QAClBC;eAAAA,0BAAiB;;QAOVC;eAAAA,0BAAe;;QANtBC;eAAAA,mBAAU;;QACVC;eAAAA,oBAAW;;QAKaC;eAAAA,mBAAQ;;QAJhCC;eAAAA,yBAAgB;;;qBAPJ;uBAUP;yBACmC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA2 Chunk Parser
|
|
3
|
+
*
|
|
4
|
+
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
+
* Used by both synchronous and streaming decoders.
|
|
6
|
+
*
|
|
7
|
+
* LZMA2 control byte ranges:
|
|
8
|
+
* 0x00 = End of stream
|
|
9
|
+
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
+
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
+
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
+
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
+
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
+
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* LZMA properties extracted from chunk header
|
|
18
|
+
*/
|
|
19
|
+
export interface LzmaChunkProps {
|
|
20
|
+
lc: number;
|
|
21
|
+
lp: number;
|
|
22
|
+
pb: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parsed LZMA2 chunk information
|
|
26
|
+
*/
|
|
27
|
+
export interface Lzma2Chunk {
|
|
28
|
+
/** Chunk type */
|
|
29
|
+
type: 'end' | 'uncompressed' | 'lzma';
|
|
30
|
+
/** Total bytes consumed by header (including control byte) */
|
|
31
|
+
headerSize: number;
|
|
32
|
+
/** Whether to reset dictionary */
|
|
33
|
+
dictReset: boolean;
|
|
34
|
+
/** Whether to reset state/probabilities */
|
|
35
|
+
stateReset: boolean;
|
|
36
|
+
/** New LZMA properties (only for control >= 0xC0) */
|
|
37
|
+
newProps: LzmaChunkProps | null;
|
|
38
|
+
/** Uncompressed data size */
|
|
39
|
+
uncompSize: number;
|
|
40
|
+
/** Compressed data size (0 for uncompressed chunks) */
|
|
41
|
+
compSize: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of parsing attempt
|
|
45
|
+
*/
|
|
46
|
+
export type ParseResult = {
|
|
47
|
+
success: true;
|
|
48
|
+
chunk: Lzma2Chunk;
|
|
49
|
+
} | {
|
|
50
|
+
success: false;
|
|
51
|
+
needBytes: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Parse an LZMA2 chunk header
|
|
55
|
+
*
|
|
56
|
+
* @param input - Input buffer
|
|
57
|
+
* @param offset - Offset to start parsing
|
|
58
|
+
* @returns Parsed chunk info or number of bytes needed
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult;
|
|
61
|
+
/** Result type for hasCompleteChunk with totalSize included on success */
|
|
62
|
+
export type CompleteChunkResult = {
|
|
63
|
+
success: true;
|
|
64
|
+
chunk: Lzma2Chunk;
|
|
65
|
+
totalSize: number;
|
|
66
|
+
} | {
|
|
67
|
+
success: false;
|
|
68
|
+
needBytes: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Check if we have enough data for the complete chunk (header + data)
|
|
72
|
+
*/
|
|
73
|
+
export declare function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LZMA2 Chunk Parser
|
|
3
|
+
*
|
|
4
|
+
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
+
* Used by both synchronous and streaming decoders.
|
|
6
|
+
*
|
|
7
|
+
* LZMA2 control byte ranges:
|
|
8
|
+
* 0x00 = End of stream
|
|
9
|
+
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
+
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
+
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
+
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
+
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
+
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* LZMA properties extracted from chunk header
|
|
18
|
+
*/
|
|
19
|
+
export interface LzmaChunkProps {
|
|
20
|
+
lc: number;
|
|
21
|
+
lp: number;
|
|
22
|
+
pb: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parsed LZMA2 chunk information
|
|
26
|
+
*/
|
|
27
|
+
export interface Lzma2Chunk {
|
|
28
|
+
/** Chunk type */
|
|
29
|
+
type: 'end' | 'uncompressed' | 'lzma';
|
|
30
|
+
/** Total bytes consumed by header (including control byte) */
|
|
31
|
+
headerSize: number;
|
|
32
|
+
/** Whether to reset dictionary */
|
|
33
|
+
dictReset: boolean;
|
|
34
|
+
/** Whether to reset state/probabilities */
|
|
35
|
+
stateReset: boolean;
|
|
36
|
+
/** New LZMA properties (only for control >= 0xC0) */
|
|
37
|
+
newProps: LzmaChunkProps | null;
|
|
38
|
+
/** Uncompressed data size */
|
|
39
|
+
uncompSize: number;
|
|
40
|
+
/** Compressed data size (0 for uncompressed chunks) */
|
|
41
|
+
compSize: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of parsing attempt
|
|
45
|
+
*/
|
|
46
|
+
export type ParseResult = {
|
|
47
|
+
success: true;
|
|
48
|
+
chunk: Lzma2Chunk;
|
|
49
|
+
} | {
|
|
50
|
+
success: false;
|
|
51
|
+
needBytes: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Parse an LZMA2 chunk header
|
|
55
|
+
*
|
|
56
|
+
* @param input - Input buffer
|
|
57
|
+
* @param offset - Offset to start parsing
|
|
58
|
+
* @returns Parsed chunk info or number of bytes needed
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult;
|
|
61
|
+
/** Result type for hasCompleteChunk with totalSize included on success */
|
|
62
|
+
export type CompleteChunkResult = {
|
|
63
|
+
success: true;
|
|
64
|
+
chunk: Lzma2Chunk;
|
|
65
|
+
totalSize: number;
|
|
66
|
+
} | {
|
|
67
|
+
success: false;
|
|
68
|
+
needBytes: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Check if we have enough data for the complete chunk (header + data)
|
|
72
|
+
*/
|
|
73
|
+
export declare function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult;
|