7z-iterator 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.d.cts +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.d.ts +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/cjs/sevenz/codecs/index.d.cts +3 -2
- package/dist/cjs/sevenz/codecs/index.d.ts +3 -2
- package/dist/cjs/sevenz/codecs/index.js +21 -16
- package/dist/cjs/sevenz/codecs/index.js.map +1 -1
- package/dist/esm/sevenz/codecs/createBufferingDecoder.d.ts +1 -1
- package/dist/esm/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/esm/sevenz/codecs/index.d.ts +3 -2
- package/dist/esm/sevenz/codecs/index.js +19 -16
- package/dist/esm/sevenz/codecs/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/lib/runDecode.d.cts +0 -5
- package/dist/cjs/lib/runDecode.d.ts +0 -5
- package/dist/cjs/lib/runDecode.js +0 -55
- package/dist/cjs/lib/runDecode.js.map +0 -1
- package/dist/esm/lib/runDecode.d.ts +0 -5
- package/dist/esm/lib/runDecode.js +0 -29
- package/dist/esm/lib/runDecode.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'extract-base-iterator';
|
|
2
|
-
import type { DecodeCallback } from '
|
|
2
|
+
import type { DecodeCallback } from 'xz-compat';
|
|
3
3
|
export type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;
|
|
4
4
|
/**
|
|
5
5
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'extract-base-iterator';
|
|
2
|
-
import type { DecodeCallback } from '
|
|
2
|
+
import type { DecodeCallback } from 'xz-compat';
|
|
3
3
|
export type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;
|
|
4
4
|
/**
|
|
5
5
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from '
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from 'xz-compat';\n\ntype TransformCallback = (error?: Error | null, data?: Buffer) => void;\n\nexport type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;\n\n/**\n * Create a Transform stream that buffers all input, then decodes in flush\n * This is the common pattern for codecs that can't stream (need full input)\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): InstanceType<typeof Transform> {\n const chunks: Buffer[] = [];\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: TransformCallback) => {\n chunks.push(chunk);\n callback();\n },\n flush: function (callback: TransformCallback) {\n const input = Buffer.concat(chunks);\n const finish = (err?: Error | null, output?: Buffer) => {\n if (err) {\n callback(err);\n return;\n }\n if (output) {\n this.push(output);\n }\n callback();\n };\n\n try {\n const maybeResult = decodeFn(input, properties, unpackSize, finish);\n if (maybeResult && typeof (maybeResult as Promise<Buffer>).then === 'function') {\n (maybeResult as Promise<Buffer>).then(\n (value) => finish(null, value),\n (err) => finish(err as Error)\n );\n return;\n }\n if (Buffer.isBuffer(maybeResult)) {\n finish(null, maybeResult);\n }\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["createBufferingDecoder","decodeFn","properties","unpackSize","chunks","Transform","transform","chunk","_encoding","callback","push","flush","input","Buffer","concat","finish","err","output","maybeResult","then","value","isBuffer"],"mappings":"AAAA,6EAA6E;AAC7E,0FAA0F;;;;;+BAS1F;;;CAGC,GACD;;;eAAwBA;;;mCAXE;AAWX,SAASA,uBAAuBC,QAAkB,EAAEC,UAAmB,EAAEC,UAAmB;IACzG,IAAMC,SAAmB,EAAE;IAE3B,OAAO,IAAIC,8BAAS,CAAC;QACnBC,WAAW,SAACC,OAAeC,WAAmBC;YAC5CL,OAAOM,IAAI,CAACH;YACZE;QACF;QACAE,OAAO,SAAPA,MAAiBF,QAA2B;;YAC1C,IAAMG,QAAQC,OAAOC,MAAM,CAACV;YAC5B,IAAMW,SAAS,SAACC,KAAoBC;gBAClC,IAAID,KAAK;oBACPP,SAASO;oBACT;gBACF;gBACA,IAAIC,QAAQ;oBACV,MAAKP,IAAI,CAACO;gBACZ;gBACAR;YACF;YAEA,IAAI;gBACF,IAAMS,cAAcjB,SAASW,OAAOV,YAAYC,YAAYY;gBAC5D,IAAIG,eAAe,OAAO,AAACA,YAAgCC,IAAI,KAAK,YAAY;oBAC7ED,YAAgCC,IAAI,CACnC,SAACC;+BAAUL,OAAO,MAAMK;uBACxB,SAACJ;+BAAQD,OAAOC;;oBAElB;gBACF;gBACA,IAAIH,OAAOQ,QAAQ,CAACH,cAAc;oBAChCH,OAAO,MAAMG;gBACf;YACF,EAAE,OAAOF,KAAK;gBACZP,SAASO;YACX;QACF;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { BufferLike } from 'extract-base-iterator';
|
|
1
2
|
import type { Transform } from 'stream';
|
|
2
|
-
import { type DecodeCallback as CodecDecodeCallback } from '
|
|
3
|
+
import { type DecodeCallback as CodecDecodeCallback } from 'xz-compat';
|
|
3
4
|
import { getPassword, setPassword } from './Aes.js';
|
|
4
5
|
import { decodeBcj2Multi } from './Bcj2.js';
|
|
5
6
|
export { getPassword, setPassword };
|
|
6
7
|
export interface Codec {
|
|
7
|
-
decode: (input:
|
|
8
|
+
decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;
|
|
8
9
|
createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { BufferLike } from 'extract-base-iterator';
|
|
1
2
|
import type { Transform } from 'stream';
|
|
2
|
-
import { type DecodeCallback as CodecDecodeCallback } from '
|
|
3
|
+
import { type DecodeCallback as CodecDecodeCallback } from 'xz-compat';
|
|
3
4
|
import { getPassword, setPassword } from './Aes.js';
|
|
4
5
|
import { decodeBcj2Multi } from './Bcj2.js';
|
|
5
6
|
export { getPassword, setPassword };
|
|
6
7
|
export interface Codec {
|
|
7
|
-
decode: (input:
|
|
8
|
+
decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;
|
|
8
9
|
createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -37,31 +37,36 @@ _export(exports, {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
var _xzcompat = require("xz-compat");
|
|
40
|
-
var _runDecodets = require("../../lib/runDecode.js");
|
|
41
40
|
var _constantsts = require("../constants.js");
|
|
42
41
|
var _Aests = require("./Aes.js");
|
|
43
42
|
var _Bcj2ts = require("./Bcj2.js");
|
|
44
43
|
var _BZip2ts = require("./BZip2.js");
|
|
45
44
|
var _Copyts = require("./Copy.js");
|
|
46
45
|
var _Deflatets = require("./Deflate.js");
|
|
46
|
+
var schedule = typeof setImmediate === 'function' ? setImmediate : function(fn) {
|
|
47
|
+
return process.nextTick(fn);
|
|
48
|
+
};
|
|
47
49
|
function wrapSyncDecode(fn) {
|
|
48
50
|
return function(input, properties, unpackSize, callback) {
|
|
49
|
-
(
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
schedule(function() {
|
|
52
|
+
try {
|
|
53
|
+
// Convert BufferList to Buffer if needed
|
|
54
|
+
var buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
55
|
+
callback(null, fn(buf, properties, unpackSize));
|
|
56
|
+
} catch (err) {
|
|
57
|
+
callback(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
52
60
|
};
|
|
53
61
|
}
|
|
54
|
-
// Simple wrappers with validation that use xz-compat's optimized
|
|
62
|
+
// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2
|
|
55
63
|
function decodeLzma(input, properties, unpackSize, callback) {
|
|
56
|
-
if (
|
|
64
|
+
if (properties.length < 5) {
|
|
57
65
|
throw new Error('LZMA requires 5-byte properties');
|
|
58
66
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(0, _runDecodets.runDecode)(function(done) {
|
|
63
|
-
(0, _xzcompat.decode7zLzma)(input, properties, unpackSize, done);
|
|
64
|
-
}, callback);
|
|
67
|
+
// Convert BufferList to Buffer if needed
|
|
68
|
+
var buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
69
|
+
(0, _xzcompat.decode7zLzma)(buf, properties, unpackSize, callback);
|
|
65
70
|
}
|
|
66
71
|
function createLzmaDecoder(properties, unpackSize) {
|
|
67
72
|
if (!properties || properties.length < 5) {
|
|
@@ -73,12 +78,12 @@ function createLzmaDecoder(properties, unpackSize) {
|
|
|
73
78
|
return (0, _xzcompat.createLzmaDecoder)(properties, unpackSize);
|
|
74
79
|
}
|
|
75
80
|
function decodeLzma2(input, properties, unpackSize, callback) {
|
|
76
|
-
if (
|
|
81
|
+
if (properties.length < 1) {
|
|
77
82
|
throw new Error('LZMA2 requires properties byte');
|
|
78
83
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
// Convert BufferList to Buffer if needed
|
|
85
|
+
var buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
86
|
+
(0, _xzcompat.decode7zLzma2)(buf, properties, unpackSize, callback);
|
|
82
87
|
}
|
|
83
88
|
function createLzma2Decoder(properties, _unpackSize) {
|
|
84
89
|
if (!properties || properties.length < 1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { type DecodeCallback as CodecDecodeCallback, runDecode } from '../../lib/runDecode.ts';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n runDecode((done) => {\n done(null, fn(input, properties, unpackSize));\n }, callback);\n };\n}\n\nexport interface Codec {\n decode: (input: Buffer, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLjma/decode7zLzma2\nfunction decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n runDecode((done) => {\n decode7zLzma(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n runDecode((done) => {\n decode7zLzma2(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["decodeBcj2Multi","getCodec","getCodecName","getPassword","isBcj2Codec","isCodecSupported","registerCodec","setPassword","wrapSyncDecode","fn","input","properties","unpackSize","callback","runDecode","done","decodeLzma","length","Error","decode7zLzma","createLzmaDecoder","_createLzmaDecoder","decodeLzma2","decode7zLzma2","createLzma2Decoder","_unpackSize","_createLzma2Decoder","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","codec","key","createCodedError","ErrorCode","UNSUPPORTED_CODEC","undefined","CodecId","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","decode","decodeCopy","createDecoder","createCopyDecoder","decodeBcj","createBcjDecoder","decodeBcjArm","createBcjArmDecoder","decodeBcjArmt","createBcjArmtDecoder","decodeBcjArm64","createBcjArm64Decoder","decodeBcjPpc","createBcjPpcDecoder","decodeBcjIa64","createBcjIa64Decoder","decodeBcjSparc","createBcjSparcDecoder","decodeDelta","createDeltaDecoder","decodeDeflate","createDeflateDecoder","decodeBzip2","createBzip2Decoder","decodeAes","createAesDecoder","decode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IACpClB,eAAemB,+BAAoB;AACrC;AAEA,cAAc;AACd7E,cAAcuC,oBAAO,CAACe,KAAK,EAAE;IAC3BE,QAAQtD,eAAe4E,oBAAW;IAClCpB,eAAeqB,2BAAkB;AACnC;AAEA,iCAAiC;AACjC/E,cAAcuC,oBAAO,CAACgB,GAAG,EAAE;IACzBC,QAAQtD,eAAe8E,gBAAS;IAChCtB,eAAeuB,uBAAgB;AACjC;AAEA,sCAAsC;AACtC,sFAAsF;AACtFjF,cAAcuC,oBAAO,CAACW,IAAI,EAAE;IAC1BM,QAAQ0B,kBAAU;IAClBxB,eAAeyB,yBAAiB;AAClC,IAEA,kEAAkE"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { BufferLike } from 'extract-base-iterator';\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n type DecodeCallback as CodecDecodeCallback,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n schedule(() => {\n try {\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n callback(null, fn(buf, properties, unpackSize));\n } catch (err) {\n callback(err as Error);\n }\n });\n };\n}\n\nexport interface Codec {\n decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2\nfunction decodeLzma(input: BufferLike, properties: Buffer, unpackSize: number, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma(buf, properties, unpackSize, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: BufferLike, properties: Buffer, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma2(buf, properties, unpackSize, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["decodeBcj2Multi","getCodec","getCodecName","getPassword","isBcj2Codec","isCodecSupported","registerCodec","setPassword","schedule","setImmediate","fn","process","nextTick","wrapSyncDecode","input","properties","unpackSize","callback","buf","Buffer","isBuffer","toBuffer","err","decodeLzma","length","Error","decode7zLzma","createLzmaDecoder","_createLzmaDecoder","decodeLzma2","decode7zLzma2","createLzma2Decoder","_unpackSize","_createLzma2Decoder","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","codec","key","createCodedError","ErrorCode","UNSUPPORTED_CODEC","undefined","CodecId","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","decode","decodeCopy","createDecoder","createCopyDecoder","decodeBcj","createBcjDecoder","decodeBcjArm","createBcjArmDecoder","decodeBcjArmt","createBcjArmtDecoder","decodeBcjArm64","createBcjArm64Decoder","decodeBcjPpc","createBcjPpcDecoder","decodeBcjIa64","createBcjIa64Decoder","decodeBcjSparc","createBcjSparcDecoder","decodeDelta","createDeltaDecoder","decodeDeflate","createDeflateDecoder","decodeBzip2","createBzip2Decoder","decodeAes","createAesDecoder","decodeBcj2","createBcj2Decoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;;;;;;;;;;;;QAiLlEA;eAAAA,uBAAe;;QA/CRC;eAAAA;;QAmBAC;eAAAA;;QAlHPC;eAAAA,kBAAW;;QAyIJC;eAAAA;;QA9BAC;eAAAA;;QApBAC;eAAAA;;QAvFMC;eAAAA,kBAAW;;;wBAT1B;2BAC8C;qBACiB;sBACP;uBACf;sBACF;yBACM;AAKpD,IAAMC,WAAW,OAAOC,iBAAiB,aAAaA,eAAe,SAACC;WAAmBC,QAAQC,QAAQ,CAACF;;AAE1G,SAASG,eAAeH,EAAuE;IAC7F,OAAO,SAACI,OAAOC,YAAYC,YAAYC;QACrCT,SAAS;YACP,IAAI;gBACF,yCAAyC;gBACzC,IAAMU,MAAMC,OAAOC,QAAQ,CAACN,SAASA,QAAQA,MAAMO,QAAQ;gBAC3DJ,SAAS,MAAMP,GAAGQ,KAAKH,YAAYC;YACrC,EAAE,OAAOM,KAAK;gBACZL,SAASK;YACX;QACF;IACF;AACF;AAOA,4FAA4F;AAC5F,SAASC,WAAWT,KAAiB,EAAEC,UAAkB,EAAEC,UAAkB,EAAEC,QAAqC;IAClH,IAAIF,WAAWS,MAAM,GAAG,GAAG;QACzB,MAAM,IAAIC,MAAM;IAClB;IACA,yCAAyC;IACzC,IAAMP,MAAMC,OAAOC,QAAQ,CAACN,SAASA,QAAQA,MAAMO,QAAQ;IAC3DK,IAAAA,sBAAY,EAACR,KAAKH,YAAYC,YAAYC;AAC5C;AAEA,SAASU,k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V,eAAeW,6BAAmB;AACpC;AAEA,oBAAoB;AACpB5E,cAAc8C,oBAAO,CAACS,QAAQ,EAAE;IAC9BQ,QAAQxD,eAAesE,uBAAa;IACpCZ,eAAea,8BAAoB;AACrC;AAEA,qBAAqB;AACrB9E,cAAc8C,oBAAO,CAACU,SAAS,EAAE;IAC/BO,QAAQxD,eAAewE,wBAAc;IACrCd,eAAee,+BAAqB;AACtC;AAEA,eAAe;AACfhF,cAAc8C,oBAAO,CAACa,KAAK,EAAE;IAC3BI,QAAQxD,eAAe0E,qBAAW;IAClChB,eAAeiB,4BAAkB;AACnC;AAEA,gBAAgB;AAChBlF,cAAc8C,oBAAO,CAACc,OAAO,EAAE;IAC7BG,QAAQxD,eAAe4E,wBAAa;IACpClB,eAAemB,+BAAoB;AACrC;AAEA,cAAc;AACdpF,cAAc8C,oBAAO,CAACe,KAAK,EAAE;IAC3BE,QAAQxD,eAAe8E,oBAAW;IAClCpB,eAAeqB,2BAAkB;AACnC;AAEA,iCAAiC;AACjCtF,cAAc8C,oBAAO,CAACgB,GAAG,EAAE;IACzBC,QAAQxD,eAAegF,gBAAS;IAChCtB,eAAeuB,uBAAgB;AACjC;AAEA,sCAAsC;AACtC,sFAAsF;AACtFxF,cAAc8C,oBAAO,CAACW,IAAI,EAAE;IAC1BM,QAAQ0B,kBAAU;IAClBxB,eAAeyB,yBAAiB;AAClC,IAEA,kEAAkE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'extract-base-iterator';
|
|
2
|
-
import type { DecodeCallback } from '
|
|
2
|
+
import type { DecodeCallback } from 'xz-compat';
|
|
3
3
|
export type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;
|
|
4
4
|
/**
|
|
5
5
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from '
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport { Transform } from 'extract-base-iterator';\nimport type { DecodeCallback } from 'xz-compat';\n\ntype TransformCallback = (error?: Error | null, data?: Buffer) => void;\n\nexport type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number, callback?: DecodeCallback<Buffer>) => Buffer | Promise<Buffer> | void;\n\n/**\n * Create a Transform stream that buffers all input, then decodes in flush\n * This is the common pattern for codecs that can't stream (need full input)\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): InstanceType<typeof Transform> {\n const chunks: Buffer[] = [];\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: TransformCallback) => {\n chunks.push(chunk);\n callback();\n },\n flush: function (callback: TransformCallback) {\n const input = Buffer.concat(chunks);\n const finish = (err?: Error | null, output?: Buffer) => {\n if (err) {\n callback(err);\n return;\n }\n if (output) {\n this.push(output);\n }\n callback();\n };\n\n try {\n const maybeResult = decodeFn(input, properties, unpackSize, finish);\n if (maybeResult && typeof (maybeResult as Promise<Buffer>).then === 'function') {\n (maybeResult as Promise<Buffer>).then(\n (value) => finish(null, value),\n (err) => finish(err as Error)\n );\n return;\n }\n if (Buffer.isBuffer(maybeResult)) {\n finish(null, maybeResult);\n }\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["Transform","createBufferingDecoder","decodeFn","properties","unpackSize","chunks","transform","chunk","_encoding","callback","push","flush","input","Buffer","concat","finish","err","output","maybeResult","then","value","isBuffer"],"mappings":"AAAA,6EAA6E;AAC7E,0FAA0F;AAE1F,SAASA,SAAS,QAAQ,wBAAwB;AAOlD;;;CAGC,GACD,eAAe,SAASC,uBAAuBC,QAAkB,EAAEC,UAAmB,EAAEC,UAAmB;IACzG,MAAMC,SAAmB,EAAE;IAE3B,OAAO,IAAIL,UAAU;QACnBM,WAAW,CAACC,OAAeC,WAAmBC;YAC5CJ,OAAOK,IAAI,CAACH;YACZE;QACF;QACAE,OAAO,SAAUF,QAA2B;YAC1C,MAAMG,QAAQC,OAAOC,MAAM,CAACT;YAC5B,MAAMU,SAAS,CAACC,KAAoBC;gBAClC,IAAID,KAAK;oBACPP,SAASO;oBACT;gBACF;gBACA,IAAIC,QAAQ;oBACV,IAAI,CAACP,IAAI,CAACO;gBACZ;gBACAR;YACF;YAEA,IAAI;gBACF,MAAMS,cAAchB,SAASU,OAAOT,YAAYC,YAAYW;gBAC5D,IAAIG,eAAe,OAAO,AAACA,YAAgCC,IAAI,KAAK,YAAY;oBAC7ED,YAAgCC,IAAI,CACnC,CAACC,QAAUL,OAAO,MAAMK,QACxB,CAACJ,MAAQD,OAAOC;oBAElB;gBACF;gBACA,IAAIH,OAAOQ,QAAQ,CAACH,cAAc;oBAChCH,OAAO,MAAMG;gBACf;YACF,EAAE,OAAOF,KAAK;gBACZP,SAASO;YACX;QACF;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { BufferLike } from 'extract-base-iterator';
|
|
1
2
|
import type { Transform } from 'stream';
|
|
2
|
-
import { type DecodeCallback as CodecDecodeCallback } from '
|
|
3
|
+
import { type DecodeCallback as CodecDecodeCallback } from 'xz-compat';
|
|
3
4
|
import { getPassword, setPassword } from './Aes.js';
|
|
4
5
|
import { decodeBcj2Multi } from './Bcj2.js';
|
|
5
6
|
export { getPassword, setPassword };
|
|
6
7
|
export interface Codec {
|
|
7
|
-
decode: (input:
|
|
8
|
+
decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;
|
|
8
9
|
createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Codec registry for 7z decompression
|
|
2
2
|
// Each codec provides a decode function and optionally a streaming decoder
|
|
3
3
|
import { createLzma2Decoder as _createLzma2Decoder, createLzmaDecoder as _createLzmaDecoder, createBcjArm64Decoder, createBcjArmDecoder, createBcjArmtDecoder, createBcjDecoder, createBcjIa64Decoder, createBcjPpcDecoder, createBcjSparcDecoder, createDeltaDecoder, decode7zLzma, decode7zLzma2, decodeBcj, decodeBcjArm, decodeBcjArm64, decodeBcjArmt, decodeBcjIa64, decodeBcjPpc, decodeBcjSparc, decodeDelta } from 'xz-compat';
|
|
4
|
-
import { runDecode } from '../../lib/runDecode.js';
|
|
5
4
|
import { CodecId, createCodedError, ErrorCode } from '../constants.js';
|
|
6
5
|
import { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.js';
|
|
7
6
|
import { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.js';
|
|
@@ -10,24 +9,28 @@ import { createCopyDecoder, decodeCopy } from './Copy.js';
|
|
|
10
9
|
import { createDeflateDecoder, decodeDeflate } from './Deflate.js';
|
|
11
10
|
// Re-export password functions for API access
|
|
12
11
|
export { getPassword, setPassword };
|
|
12
|
+
const schedule = typeof setImmediate === 'function' ? setImmediate : (fn)=>process.nextTick(fn);
|
|
13
13
|
function wrapSyncDecode(fn) {
|
|
14
14
|
return (input, properties, unpackSize, callback)=>{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
schedule(()=>{
|
|
16
|
+
try {
|
|
17
|
+
// Convert BufferList to Buffer if needed
|
|
18
|
+
const buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
19
|
+
callback(null, fn(buf, properties, unpackSize));
|
|
20
|
+
} catch (err) {
|
|
21
|
+
callback(err);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
// Simple wrappers with validation that use xz-compat's optimized
|
|
26
|
+
// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2
|
|
21
27
|
function decodeLzma(input, properties, unpackSize, callback) {
|
|
22
|
-
if (
|
|
28
|
+
if (properties.length < 5) {
|
|
23
29
|
throw new Error('LZMA requires 5-byte properties');
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
runDecode((done)=>{
|
|
29
|
-
decode7zLzma(input, properties, unpackSize, done);
|
|
30
|
-
}, callback);
|
|
31
|
+
// Convert BufferList to Buffer if needed
|
|
32
|
+
const buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
33
|
+
decode7zLzma(buf, properties, unpackSize, callback);
|
|
31
34
|
}
|
|
32
35
|
function createLzmaDecoder(properties, unpackSize) {
|
|
33
36
|
if (!properties || properties.length < 5) {
|
|
@@ -39,12 +42,12 @@ function createLzmaDecoder(properties, unpackSize) {
|
|
|
39
42
|
return _createLzmaDecoder(properties, unpackSize);
|
|
40
43
|
}
|
|
41
44
|
function decodeLzma2(input, properties, unpackSize, callback) {
|
|
42
|
-
if (
|
|
45
|
+
if (properties.length < 1) {
|
|
43
46
|
throw new Error('LZMA2 requires properties byte');
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
// Convert BufferList to Buffer if needed
|
|
49
|
+
const buf = Buffer.isBuffer(input) ? input : input.toBuffer();
|
|
50
|
+
decode7zLzma2(buf, properties, unpackSize, callback);
|
|
48
51
|
}
|
|
49
52
|
function createLzma2Decoder(properties, _unpackSize) {
|
|
50
53
|
if (!properties || properties.length < 1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { type DecodeCallback as CodecDecodeCallback, runDecode } from '../../lib/runDecode.ts';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n runDecode((done) => {\n done(null, fn(input, properties, unpackSize));\n }, callback);\n };\n}\n\nexport interface Codec {\n decode: (input: Buffer, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLjma/decode7zLzma2\nfunction decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n runDecode((done) => {\n decode7zLzma(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number, callback?: CodecDecodeCallback<Buffer>): void {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n runDecode((done) => {\n decode7zLzma2(input, properties, unpackSize, done);\n }, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["createLzma2Decoder","_createLzma2Decoder","createLzmaDecoder","_createLzmaDecoder","createBcjArm64Decoder","createBcjArmDecoder","createBcjArmtDecoder","createBcjDecoder","createBcjIa64Decoder","createBcjPpcDecoder","createBcjSparcDecoder","createDeltaDecoder","decode7zLzma","decode7zLzma2","decodeBcj","decodeBcjArm","decodeBcjArm64","decodeBcjArmt","decodeBcjIa64","decodeBcjPpc","decodeBcjSparc","decodeDelta","runDecode","CodecId","createCodedError","ErrorCode","createAesDecoder","decodeAes","getPassword","setPassword","createBcj2Decoder","decodeBcj2","decodeBcj2Multi","createBzip2Decoder","decodeBzip2","createCopyDecoder","decodeCopy","createDeflateDecoder","decodeDeflate","wrapSyncDecode","fn","input","properties","unpackSize","callback","done","decodeLzma","length","Error","decodeLzma2","_unpackSize","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","registerCodec","codec","getCodec","key","UNSUPPORTED_CODEC","isCodecSupported","undefined","getCodecName","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","isBcj2Codec","decode","createDecoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAG3E,SACEA,sBAAsBC,mBAAmB,EACzCC,qBAAqBC,kBAAkB,EACvCC,qBAAqB,EACrBC,mBAAmB,EACnBC,oBAAoB,EACpBC,gBAAgB,EAChBC,oBAAoB,EACpBC,mBAAmB,EACnBC,qBAAqB,EACrBC,kBAAkB,EAClBC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,aAAa,EACbC,aAAa,EACbC,YAAY,EACZC,cAAc,EACdC,WAAW,QACN,YAAY;AACnB,SAAqDC,SAAS,QAAQ,yBAAyB;AAC/F,SAASC,OA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jC8B,cAAcxC,QAAQ+D,GAAG,EAAE;IACzBE,QAAQjD,eAAeZ;IACvB8D,eAAe/D;AACjB;AAEA,sCAAsC;AACtC,sFAAsF;AACtFqC,cAAcxC,QAAQ0D,IAAI,EAAE;IAC1BO,QAAQzD;IACR0D,eAAe3D;AACjB,IAEA,kEAAkE"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { BufferLike } from 'extract-base-iterator';\nimport type { Transform } from 'stream';\nimport {\n createLzma2Decoder as _createLzma2Decoder,\n createLzmaDecoder as _createLzmaDecoder,\n type DecodeCallback as CodecDecodeCallback,\n createBcjArm64Decoder,\n createBcjArmDecoder,\n createBcjArmtDecoder,\n createBcjDecoder,\n createBcjIa64Decoder,\n createBcjPpcDecoder,\n createBcjSparcDecoder,\n createDeltaDecoder,\n decode7zLzma,\n decode7zLzma2,\n decodeBcj,\n decodeBcjArm,\n decodeBcjArm64,\n decodeBcjArmt,\n decodeBcjIa64,\n decodeBcjPpc,\n decodeBcjSparc,\n decodeDelta,\n} from 'xz-compat';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nfunction wrapSyncDecode(fn: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer): Codec['decode'] {\n return (input, properties, unpackSize, callback) => {\n schedule(() => {\n try {\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n callback(null, fn(buf, properties, unpackSize));\n } catch (err) {\n callback(err as Error);\n }\n });\n };\n}\n\nexport interface Codec {\n decode: (input: BufferLike, properties: Buffer | undefined, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>) => void;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Simple wrappers with validation that use xz-compat's optimized decode7zLzma/decode7zLzma2\nfunction decodeLzma(input: BufferLike, properties: Buffer, unpackSize: number, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma(buf, properties, unpackSize, callback);\n}\n\nfunction createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n return _createLzmaDecoder(properties, unpackSize) as Transform;\n}\n\nfunction decodeLzma2(input: BufferLike, properties: Buffer, unpackSize: number | undefined, callback: CodecDecodeCallback<Buffer>): void {\n if (properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n // Convert BufferList to Buffer if needed\n const buf = Buffer.isBuffer(input) ? input : input.toBuffer();\n decode7zLzma2(buf, properties, unpackSize, callback);\n}\n\nfunction createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n return _createLzma2Decoder(properties) as Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: wrapSyncDecode(decodeCopy),\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: wrapSyncDecode(decodeBcj),\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: wrapSyncDecode(decodeBcjArm),\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: wrapSyncDecode(decodeBcjArmt),\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: wrapSyncDecode(decodeBcjArm64),\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: wrapSyncDecode(decodeBcjPpc),\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: wrapSyncDecode(decodeBcjIa64),\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: wrapSyncDecode(decodeBcjSparc),\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: wrapSyncDecode(decodeDelta),\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: wrapSyncDecode(decodeDeflate),\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: wrapSyncDecode(decodeBzip2),\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: wrapSyncDecode(decodeAes),\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["createLzma2Decoder","_createLzma2Decoder","createLzmaDecoder","_createLzmaDecoder","createBcjArm64Decoder","createBcjArmDecoder","createBcjArmtDecoder","createBcjDecoder","createBcjIa64Decoder","createBcjPpcDecoder","createBcjSparcDecoder","createDeltaDecoder","decode7zLzma","decode7zLzma2","decodeBcj","decodeBcjArm","decodeBcjArm64","decodeBcjArmt","decodeBcjIa64","decodeBcjPpc","decodeBcjSparc","decodeDelta","CodecId","createCodedError","ErrorCode","createAesDecoder","decodeAes","getPassword","setPassword","createBcj2Decoder","decodeBcj2","decodeBcj2Multi","createBzip2Decoder","decodeBzip2","createCopyDecoder","decodeCopy","createDeflateDecoder","decodeDeflate","schedule","setImmediate","fn","process","nextTick","wrapSyncDecode","input","properties","unpackSize","callback","buf","Buffer","isBuffer","toBuffer","err","decodeLzma","length","Error","decodeLzma2","_unpackSize","codecs","codecIdToKey","id","parts","i","push","toString","toUpperCase","join","codecIdEquals","a","b","registerCodec","codec","getCodec","key","UNSUPPORTED_CODEC","isCodecSupported","undefined","getCodecName","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM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chD,QAAQ8D,SAAS,EAAE;IAC/BW,QAAQpD,eAAe3B;IACvBgF,eAAe5F;AACjB;AAEA,uBAAuB;AACvBkE,cAAchD,QAAQ+D,OAAO,EAAE;IAC7BU,QAAQpD,eAAexB;IACvB6E,eAAevF;AACjB;AAEA,oBAAoB;AACpB6D,cAAchD,QAAQgE,QAAQ,EAAE;IAC9BS,QAAQpD,eAAezB;IACvB8E,eAAexF;AACjB;AAEA,qBAAqB;AACrB8D,cAAchD,QAAQiE,SAAS,EAAE;IAC/BQ,QAAQpD,eAAevB;IACvB4E,eAAetF;AACjB;AAEA,eAAe;AACf4D,cAAchD,QAAQoE,KAAK,EAAE;IAC3BK,QAAQpD,eAAetB;IACvB2E,eAAerF;AACjB;AAEA,gBAAgB;AAChB2D,cAAchD,QAAQqE,OAAO,EAAE;IAC7BI,QAAQpD,eAAeN;IACvB2D,eAAe5D;AACjB;AAEA,cAAc;AACdkC,cAAchD,QAAQsE,KAAK,EAAE;IAC3BG,QAAQpD,eAAeV;IACvB+D,eAAehE;AACjB;AAEA,iCAAiC;AACjCsC,cAAchD,QAAQuE,GAAG,EAAE;IACzBE,QAAQpD,eAAejB;IACvBsE,eAAevE;AACjB;AAEA,sCAAsC;AACtC,sFAAsF;AACtF6C,cAAchD,QAAQkE,IAAI,EAAE;IAC1BO,QAAQjE;IACRkE,eAAenE;AACjB,IAEA,kEAAkE"}
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;
|
|
2
|
-
type Executor<T> = (callback: DecodeCallback<T>) => void;
|
|
3
|
-
export declare function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void;
|
|
4
|
-
export declare function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void;
|
|
5
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;
|
|
2
|
-
type Executor<T> = (callback: DecodeCallback<T>) => void;
|
|
3
|
-
export declare function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void;
|
|
4
|
-
export declare function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void;
|
|
5
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get runDecode () {
|
|
13
|
-
return runDecode;
|
|
14
|
-
},
|
|
15
|
-
get runSync () {
|
|
16
|
-
return runSync;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
20
|
-
function _interop_require_default(obj) {
|
|
21
|
-
return obj && obj.__esModule ? obj : {
|
|
22
|
-
default: obj
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
var schedule = typeof setImmediate === 'function' ? setImmediate : function(fn) {
|
|
26
|
-
return process.nextTick(fn);
|
|
27
|
-
};
|
|
28
|
-
function runDecode(executor, callback) {
|
|
29
|
-
if (typeof callback === 'function') {
|
|
30
|
-
executor((0, _calloncefn.default)(callback));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (typeof Promise === 'undefined') {
|
|
34
|
-
throw new Error('Promises are not available in this runtime. Please provide a callback.');
|
|
35
|
-
}
|
|
36
|
-
return new Promise(function(resolve, reject) {
|
|
37
|
-
executor((0, _calloncefn.default)(function(err, value) {
|
|
38
|
-
if (err) {
|
|
39
|
-
reject(err);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
resolve(value);
|
|
43
|
-
}));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function runSync(fn, callback) {
|
|
47
|
-
schedule(function() {
|
|
48
|
-
try {
|
|
49
|
-
callback(null, fn());
|
|
50
|
-
} catch (err) {
|
|
51
|
-
callback(err);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/* 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; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lib/runDecode.ts"],"sourcesContent":["import once from 'call-once-fn';\n\nexport type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;\n\ntype Executor<T> = (callback: DecodeCallback<T>) => void;\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nexport function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void {\n if (typeof callback === 'function') {\n executor(once(callback));\n return;\n }\n\n if (typeof Promise === 'undefined') {\n throw new Error('Promises are not available in this runtime. Please provide a callback.');\n }\n\n return new Promise<T>((resolve, reject) => {\n executor(\n once((err, value) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(value as T);\n })\n );\n });\n}\n\nexport function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void {\n schedule(() => {\n try {\n callback(null, fn());\n } catch (err) {\n callback(err as Error);\n }\n });\n}\n"],"names":["runDecode","runSync","schedule","setImmediate","fn","process","nextTick","executor","callback","once","Promise","Error","resolve","reject","err","value"],"mappings":";;;;;;;;;;;QAQgBA;eAAAA;;QAuBAC;eAAAA;;;iEA/BC;;;;;;AAMjB,IAAMC,WAAW,OAAOC,iBAAiB,aAAaA,eAAe,SAACC;WAAmBC,QAAQC,QAAQ,CAACF;;AAEnG,SAASJ,UAAaO,QAAqB,EAAEC,QAA4B;IAC9E,IAAI,OAAOA,aAAa,YAAY;QAClCD,SAASE,IAAAA,mBAAI,EAACD;QACd;IACF;IAEA,IAAI,OAAOE,YAAY,aAAa;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAO,IAAID,QAAW,SAACE,SAASC;QAC9BN,SACEE,IAAAA,mBAAI,EAAC,SAACK,KAAKC;YACT,IAAID,KAAK;gBACPD,OAAOC;gBACP;YACF;YACAF,QAAQG;QACV;IAEJ;AACF;AAEO,SAASd,QAAWG,EAAW,EAAEI,QAA2B;IACjEN,SAAS;QACP,IAAI;YACFM,SAAS,MAAMJ;QACjB,EAAE,OAAOU,KAAK;YACZN,SAASM;QACX;IACF;AACF"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;
|
|
2
|
-
type Executor<T> = (callback: DecodeCallback<T>) => void;
|
|
3
|
-
export declare function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void;
|
|
4
|
-
export declare function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void;
|
|
5
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import once from 'call-once-fn';
|
|
2
|
-
const schedule = typeof setImmediate === 'function' ? setImmediate : (fn)=>process.nextTick(fn);
|
|
3
|
-
export function runDecode(executor, callback) {
|
|
4
|
-
if (typeof callback === 'function') {
|
|
5
|
-
executor(once(callback));
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
if (typeof Promise === 'undefined') {
|
|
9
|
-
throw new Error('Promises are not available in this runtime. Please provide a callback.');
|
|
10
|
-
}
|
|
11
|
-
return new Promise((resolve, reject)=>{
|
|
12
|
-
executor(once((err, value)=>{
|
|
13
|
-
if (err) {
|
|
14
|
-
reject(err);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
resolve(value);
|
|
18
|
-
}));
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function runSync(fn, callback) {
|
|
22
|
-
schedule(()=>{
|
|
23
|
-
try {
|
|
24
|
-
callback(null, fn());
|
|
25
|
-
} catch (err) {
|
|
26
|
-
callback(err);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lib/runDecode.ts"],"sourcesContent":["import once from 'call-once-fn';\n\nexport type DecodeCallback<T = Buffer> = (error: Error | null, result?: T) => void;\n\ntype Executor<T> = (callback: DecodeCallback<T>) => void;\n\nconst schedule = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => process.nextTick(fn);\n\nexport function runDecode<T>(executor: Executor<T>, callback?: DecodeCallback<T>): Promise<T> | void {\n if (typeof callback === 'function') {\n executor(once(callback));\n return;\n }\n\n if (typeof Promise === 'undefined') {\n throw new Error('Promises are not available in this runtime. Please provide a callback.');\n }\n\n return new Promise<T>((resolve, reject) => {\n executor(\n once((err, value) => {\n if (err) {\n reject(err);\n return;\n }\n resolve(value as T);\n })\n );\n });\n}\n\nexport function runSync<T>(fn: () => T, callback: DecodeCallback<T>): void {\n schedule(() => {\n try {\n callback(null, fn());\n } catch (err) {\n callback(err as Error);\n }\n });\n}\n"],"names":["once","schedule","setImmediate","fn","process","nextTick","runDecode","executor","callback","Promise","Error","resolve","reject","err","value","runSync"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAMhC,MAAMC,WAAW,OAAOC,iBAAiB,aAAaA,eAAe,CAACC,KAAmBC,QAAQC,QAAQ,CAACF;AAE1G,OAAO,SAASG,UAAaC,QAAqB,EAAEC,QAA4B;IAC9E,IAAI,OAAOA,aAAa,YAAY;QAClCD,SAASP,KAAKQ;QACd;IACF;IAEA,IAAI,OAAOC,YAAY,aAAa;QAClC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAO,IAAID,QAAW,CAACE,SAASC;QAC9BL,SACEP,KAAK,CAACa,KAAKC;YACT,IAAID,KAAK;gBACPD,OAAOC;gBACP;YACF;YACAF,QAAQG;QACV;IAEJ;AACF;AAEA,OAAO,SAASC,QAAWZ,EAAW,EAAEK,QAA2B;IACjEP,SAAS;QACP,IAAI;YACFO,SAAS,MAAML;QACjB,EAAE,OAAOU,KAAK;YACZL,SAASK;QACX;IACF;AACF"}
|