@patrickdk77/archive-defuse 0.1.2 → 0.1.3
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/README.md +1 -1
- package/dist/lzma1/NOTICE +32 -18
- package/dist/lzma1/crc32.d.ts +2 -1
- package/dist/lzma1/crc32.js +3 -2
- package/dist/lzma1/hash234.d.ts +3 -1
- package/dist/lzma1/hash234.js +9 -4
- package/dist/lzma1/hc4.d.ts +3 -2
- package/dist/lzma1/hc4.js +6 -4
- package/dist/lzma1/header.js +1 -1
- package/dist/lzma1/lz-decoder.d.ts +14 -14
- package/dist/lzma1/lz-decoder.js +15 -33
- package/dist/lzma1/lz-encoder.d.ts +3 -2
- package/dist/lzma1/lz-encoder.js +6 -4
- package/dist/lzma1/lzma-coder.d.ts +51 -27
- package/dist/lzma1/lzma-coder.js +114 -48
- package/dist/lzma1/lzma-decoder.d.ts +41 -19
- package/dist/lzma1/lzma-decoder.js +159 -437
- package/dist/lzma1/lzma-encoder-fast.d.ts +2 -1
- package/dist/lzma1/lzma-encoder-fast.js +3 -2
- package/dist/lzma1/lzma-encoder.d.ts +68 -40
- package/dist/lzma1/lzma-encoder.js +289 -232
- package/dist/lzma1/lzma2-decoder.d.ts +17 -2
- package/dist/lzma1/lzma2-decoder.js +71 -15
- package/dist/lzma1/range-coder.d.ts +4 -0
- package/dist/lzma1/range-coder.js +5 -1
- package/dist/lzma1/range-decoder.d.ts +22 -22
- package/dist/lzma1/range-decoder.js +74 -32
- package/dist/lzma1/range-encoder.d.ts +26 -28
- package/dist/lzma1/range-encoder.js +98 -150
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -396,4 +396,4 @@ npm run format
|
|
|
396
396
|
|
|
397
397
|
## License
|
|
398
398
|
|
|
399
|
-
MIT AND Apache-2.0. The package is MIT, in LICENSE. The LZMA and LZMA2 decoders and the LZMA encoder in `src/lzma1` come from lzma1 by Filip Seman, under the Apache License 2.0. Its text and a NOTICE that lists what changed sit next to them, and both ship in `dist/lzma1`. lzma1 ports that code from XZ for Java, which is 0BSD. The branch converters and the delta filter are ported from XZ for Java directly.
|
|
399
|
+
MIT AND Apache-2.0. The package is MIT, in LICENSE. The LZMA and LZMA2 decoders and the LZMA encoder in `src/lzma1` come from lzma1 0.6.1 by Filip Seman, under the Apache License 2.0. Its text and a NOTICE that lists what changed sit next to them, and both ship in `dist/lzma1`. lzma1 ports that code from XZ for Java, which is 0BSD. The branch converters and the delta filter are ported from XZ for Java directly.
|
package/dist/lzma1/NOTICE
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
|
-
The files in this directory come from lzma1 by Filip Seman, https://github.com/xseman/lzma1, under the Apache
|
|
2
|
-
License 2.0 in LICENSE here. They
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
The files in this directory come from lzma1 0.6.1 by Filip Seman, https://github.com/xseman/lzma1, under the Apache
|
|
2
|
+
License 2.0 in LICENSE here. They are the sources of tag v0.6.1, commit fc19ffcd4022b37297760c5dfec9292edf5875cd,
|
|
3
|
+
which match the src folder of lzma1-0.6.1.tgz on npm. lzma1 ports them from XZ for Java (0BSD) by Lasse Collin and
|
|
4
|
+
Igor Pavlov.
|
|
5
|
+
|
|
6
|
+
archive-defuse carries a copy instead of depending on the npm package. lzma1 0.6.1 exports only its high-level API,
|
|
7
|
+
and archive-defuse drives the streaming LZMA and LZMA2 decoders and the raw encoder below it: it needs the input bytes
|
|
8
|
+
the data took and what follows it, and it restarts one encoder for each LZMA2 chunk it writes. lzma1 is also an ES
|
|
9
|
+
module only, and archive-defuse compiles to CommonJS for Node 18 and later.
|
|
5
10
|
|
|
6
11
|
Copied: crc32.ts, hash234.ts, hc4.ts, header.ts, lz-decoder.ts, lz-encoder.ts, lzma-coder.ts, lzma-decoder.ts,
|
|
7
12
|
lzma-encoder.ts, lzma-encoder-fast.ts, lzma2-decoder.ts, range-coder.ts, range-decoder.ts and range-encoder.ts.
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
archive-defuse changed them as follows.
|
|
10
15
|
|
|
11
16
|
In every file:
|
|
12
17
|
- Biome reformatted it to this package's style, with spaces for tabs and single quotes for double.
|
|
13
18
|
- Imports drop the ".js" suffix, since this package compiles to CommonJS.
|
|
14
|
-
- A first line names lzma1, its license and this NOTICE.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
- A first line names lzma1 0.6.1, its license and this NOTICE.
|
|
20
|
+
|
|
21
|
+
This package's lint rules forbid assigning to a parameter, so these functions copy the parameter into a local
|
|
22
|
+
variable first and work on the copy. The arithmetic is the same.
|
|
23
|
+
- hc4.ts: skip().
|
|
24
|
+
- lz-decoder.ts: repeat().
|
|
25
|
+
- lz-encoder.ts: fillWindow().
|
|
26
|
+
- lzma-encoder.ts: getNormalPrice() and getMatchedPrice() of the literal encoder, and encode() of the length encoder.
|
|
27
|
+
- lzma2-decoder.ts: readChunkHeader(), decodeProps() and copyUncompressed().
|
|
28
|
+
- range-decoder.ts: decodeDirectBits().
|
|
29
|
+
- range-encoder.ts: getBitTreePrice(), getReverseBitTreePrice(), encodeReverseBitTree() and encodeDirectBits().
|
|
30
|
+
|
|
31
|
+
In lzma-decoder.ts, the matched literal loop builds its mask with -bit where lzma1 writes (0 - bit). The lint rules
|
|
32
|
+
read 0 - x as a type conversion. Both give 0 or -1 for a bit.
|
|
33
|
+
|
|
34
|
+
In lzma-encoder.ts:
|
|
35
|
+
- The empty body of the loop in encode() holds a comment.
|
|
36
|
+
- The import of State from lzma-coder.ts is gone, since nothing in the file uses it and the compiler refuses unused
|
|
37
|
+
imports.
|
|
22
38
|
|
|
23
39
|
In lzma-encoder-fast.ts:
|
|
24
40
|
- getNextSymbol() throws if no matches were read, where it used a non-null assertion.
|
|
25
41
|
- A chained assignment is now two assignments.
|
|
26
42
|
|
|
27
|
-
In lzma-encoder.ts, the empty body of the loop in encode() holds a comment.
|
|
28
|
-
|
|
29
43
|
In lzma2-decoder.ts:
|
|
30
44
|
- The file defines INPUT_MARGIN itself instead of importing it from alone-decoder.ts, which this package does not
|
|
31
|
-
copy. The value is
|
|
45
|
+
copy. The value is lzma1's, 64.
|
|
32
46
|
- A private method, currentLzma(), returns the LZMA decoder or throws "LZMA2 chunk without properties". It replaces
|
|
33
47
|
two non-null assertions.
|
|
34
48
|
|
|
35
|
-
crc32.ts, hash234.ts, header.ts, lzma-coder.ts,
|
|
36
|
-
|
|
49
|
+
crc32.ts, hash234.ts, header.ts, lzma-coder.ts, range-coder.ts have no changes beyond formatting, imports and the
|
|
50
|
+
first line.
|
package/dist/lzma1/crc32.d.ts
CHANGED
package/dist/lzma1/crc32.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CRC32_TABLE = void 0;
|
|
4
|
-
// Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for
|
|
4
|
+
// Copied from lzma1 0.6.1 (Apache-2.0, Copyright Filip Seman) and changed for archive-defuse. NOTICE in this folder lists the changes.
|
|
5
5
|
/**
|
|
6
|
-
* CRC-32 (IEEE 802.3) lookup table. The match finders
|
|
6
|
+
* CRC-32 (IEEE 802.3) lookup table. The match finders hash with a copy of
|
|
7
|
+
* it, so changing this array does not affect compression.
|
|
7
8
|
*/
|
|
8
9
|
exports.CRC32_TABLE = createCrc32Table();
|
|
9
10
|
function createCrc32Table() {
|
package/dist/lzma1/hash234.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hash tables of the last positions of 2-, 3- and 4-byte sequences.
|
|
3
3
|
*
|
|
4
|
-
* Ported from XZ for Java (0BSD)
|
|
4
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/Hash234.java` and
|
|
5
|
+
* `CRC32Hash.java` (the table itself comes from `crc32.ts`), by Lasse
|
|
6
|
+
* Collin and Igor Pavlov.
|
|
5
7
|
*/
|
|
6
8
|
export declare class Hash234 {
|
|
7
9
|
private readonly hash4Mask;
|
package/dist/lzma1/hash234.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for
|
|
2
|
+
// Copied from lzma1 0.6.1 (Apache-2.0, Copyright Filip Seman) and changed for archive-defuse. NOTICE in this folder lists the changes.
|
|
3
3
|
/**
|
|
4
4
|
* Hash tables of the last positions of 2-, 3- and 4-byte sequences.
|
|
5
5
|
*
|
|
6
|
-
* Ported from XZ for Java (0BSD)
|
|
6
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/Hash234.java` and
|
|
7
|
+
* `CRC32Hash.java` (the table itself comes from `crc32.ts`), by Lasse
|
|
8
|
+
* Collin and Igor Pavlov.
|
|
7
9
|
*/
|
|
8
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
11
|
exports.Hash234 = void 0;
|
|
@@ -13,6 +15,9 @@ const HASH_2_SIZE = 1 << 10;
|
|
|
13
15
|
const HASH_2_MASK = HASH_2_SIZE - 1;
|
|
14
16
|
const HASH_3_SIZE = 1 << 16;
|
|
15
17
|
const HASH_3_MASK = HASH_3_SIZE - 1;
|
|
18
|
+
// An int32 copy saves converting the exported table's unsigned numbers on
|
|
19
|
+
// every read; measured faster in fast mode.
|
|
20
|
+
const CRC32_TABLE_INT32 = Int32Array.from(crc32_1.CRC32_TABLE);
|
|
16
21
|
function getHash4Size(dictSize) {
|
|
17
22
|
let h = dictSize - 1;
|
|
18
23
|
h |= h >>> 1;
|
|
@@ -40,11 +45,11 @@ class Hash234 {
|
|
|
40
45
|
this.hash4Mask = hash4Size - 1;
|
|
41
46
|
}
|
|
42
47
|
calcHashes(buf, off) {
|
|
43
|
-
let temp =
|
|
48
|
+
let temp = CRC32_TABLE_INT32[buf[off]] ^ buf[off + 1];
|
|
44
49
|
this.hash2Value = temp & HASH_2_MASK;
|
|
45
50
|
temp ^= buf[off + 2] << 8;
|
|
46
51
|
this.hash3Value = temp & HASH_3_MASK;
|
|
47
|
-
temp ^=
|
|
52
|
+
temp ^= CRC32_TABLE_INT32[buf[off + 3]] << 5;
|
|
48
53
|
this.hash4Value = temp & this.hash4Mask;
|
|
49
54
|
}
|
|
50
55
|
getHash2Pos() {
|
package/dist/lzma1/hc4.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Every position links to the previous position with the same 4-byte hash.
|
|
5
5
|
* Faster than the binary tree finder but finds fewer long matches.
|
|
6
6
|
*
|
|
7
|
-
* Ported from XZ for Java (0BSD) by
|
|
7
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/HC4.java`, by
|
|
8
|
+
* Lasse Collin and Igor Pavlov.
|
|
8
9
|
*/
|
|
9
10
|
import { LzEncoder, type LzEncoderConfig, Matches } from './lz-encoder';
|
|
10
11
|
export declare class HC4 extends LzEncoder {
|
|
@@ -25,6 +26,6 @@ export declare class HC4 extends LzEncoder {
|
|
|
25
26
|
*/
|
|
26
27
|
reset(): void;
|
|
27
28
|
getMatches(): Matches;
|
|
28
|
-
skip(
|
|
29
|
+
skip(lenIn: number): void;
|
|
29
30
|
private movePosition;
|
|
30
31
|
}
|
package/dist/lzma1/hc4.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for
|
|
2
|
+
// Copied from lzma1 0.6.1 (Apache-2.0, Copyright Filip Seman) and changed for archive-defuse. NOTICE in this folder lists the changes.
|
|
3
3
|
/**
|
|
4
4
|
* Hash chain match finder with 2-, 3- and 4-byte hashing.
|
|
5
5
|
*
|
|
6
6
|
* Every position links to the previous position with the same 4-byte hash.
|
|
7
7
|
* Faster than the binary tree finder but finds fewer long matches.
|
|
8
8
|
*
|
|
9
|
-
* Ported from XZ for Java (0BSD) by
|
|
9
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/HC4.java`, by
|
|
10
|
+
* Lasse Collin and Igor Pavlov.
|
|
10
11
|
*/
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.HC4 = void 0;
|
|
@@ -114,8 +115,9 @@ class HC4 extends lz_encoder_1.LzEncoder {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
|
-
skip(
|
|
118
|
-
|
|
118
|
+
skip(lenIn) {
|
|
119
|
+
let len = lenIn;
|
|
120
|
+
while (len-- > 0) {
|
|
119
121
|
if (this.movePosition() !== 0) {
|
|
120
122
|
this.hash.calcHashes(this.buf, this.readPos);
|
|
121
123
|
this.chain[this.cyclicPos] = this.hash.getHash4Pos();
|
package/dist/lzma1/header.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for
|
|
2
|
+
// Copied from lzma1 0.6.1 (Apache-2.0, Copyright Filip Seman) and changed for archive-defuse. NOTICE in this folder lists the changes.
|
|
3
3
|
/**
|
|
4
4
|
* The 13-byte header of the `.lzma` ("LZMA_Alone") format:
|
|
5
5
|
*
|
|
@@ -6,16 +6,23 @@
|
|
|
6
6
|
* so small outputs don't allocate the whole dictionary up front, unless
|
|
7
7
|
* `preallocate` is set. Bytes are passed to `sink` before they get
|
|
8
8
|
* overwritten.
|
|
9
|
+
*
|
|
10
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/LZDecoder.java`,
|
|
11
|
+
* by Lasse Collin and Igor Pavlov; the fixed dictionary buffer flushed by
|
|
12
|
+
* the caller became this growing buffer with a sink, and the Java code's
|
|
13
|
+
* mid-match output limit (`pendingLen`) is not needed, because
|
|
14
|
+
* `LzmaDecoder` enforces its output limit, the declared size or the end of
|
|
15
|
+
* an LZMA2 chunk, before each match.
|
|
9
16
|
*/
|
|
10
17
|
export declare class LzDecoder {
|
|
11
|
-
|
|
18
|
+
buf: Uint8Array;
|
|
12
19
|
private readonly maxSize;
|
|
13
20
|
private readonly sink;
|
|
14
21
|
/** Next write position. */
|
|
15
|
-
|
|
22
|
+
pos: number;
|
|
16
23
|
/** Start of the bytes not yet passed to the sink. */
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
start: number;
|
|
25
|
+
wrapped: boolean;
|
|
19
26
|
/**
|
|
20
27
|
* @param dictSize Largest distance a match may reach back
|
|
21
28
|
* @param sink Receives decoded data. The chunk is only valid during the call.
|
|
@@ -26,16 +33,9 @@ export declare class LzDecoder {
|
|
|
26
33
|
getByte(dist: number): number;
|
|
27
34
|
putByte(byte: number): void;
|
|
28
35
|
/** Copies `len` bytes starting `dist + 1` positions back. */
|
|
29
|
-
repeat(dist: number,
|
|
30
|
-
/**
|
|
31
|
-
* Copies `len` bytes of uncompressed data from `input` at `inPos`. XZ for
|
|
32
|
-
* Java copies up to the end of the buffer and leaves the rest to its
|
|
33
|
-
* caller; this copy continues past the end like `repeat`.
|
|
34
|
-
*/
|
|
35
|
-
copyUncompressed(input: Uint8Array, offset: number, length: number): void;
|
|
36
|
-
/** Empties the dictionary, so matches can't reach back before this point. */
|
|
37
|
-
reset(): void;
|
|
36
|
+
repeat(dist: number, lenIn: number): void;
|
|
38
37
|
/** Passes all pending bytes to the sink. */
|
|
39
38
|
flush(): void;
|
|
40
|
-
|
|
39
|
+
/** Grows the buffer, or passes its bytes to the sink and wraps around. */
|
|
40
|
+
onBufferEnd(): void;
|
|
41
41
|
}
|
package/dist/lzma1/lz-decoder.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LzDecoder = void 0;
|
|
4
|
-
// Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for
|
|
4
|
+
// Copied from lzma1 0.6.1 (Apache-2.0, Copyright Filip Seman) and changed for archive-defuse. NOTICE in this folder lists the changes.
|
|
5
5
|
/**
|
|
6
6
|
* Decoder-side LZ window: a circular buffer holding the most recent output
|
|
7
7
|
* (the dictionary), which matches copy from.
|
|
@@ -10,8 +10,19 @@ exports.LzDecoder = void 0;
|
|
|
10
10
|
* so small outputs don't allocate the whole dictionary up front, unless
|
|
11
11
|
* `preallocate` is set. Bytes are passed to `sink` before they get
|
|
12
12
|
* overwritten.
|
|
13
|
+
*
|
|
14
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/LZDecoder.java`,
|
|
15
|
+
* by Lasse Collin and Igor Pavlov; the fixed dictionary buffer flushed by
|
|
16
|
+
* the caller became this growing buffer with a sink, and the Java code's
|
|
17
|
+
* mid-match output limit (`pendingLen`) is not needed, because
|
|
18
|
+
* `LzmaDecoder` enforces its output limit, the declared size or the end of
|
|
19
|
+
* an LZMA2 chunk, before each match.
|
|
13
20
|
*/
|
|
14
21
|
class LzDecoder {
|
|
22
|
+
// Not private: `copyUncompressed` and `resetDictionary` in
|
|
23
|
+
// lzma2-decoder.ts use them. As methods here they would ship in every
|
|
24
|
+
// bundle, and as a subclass they make LZMA2 decoding about 10% slower on
|
|
25
|
+
// Node.
|
|
15
26
|
buf;
|
|
16
27
|
maxSize;
|
|
17
28
|
sink;
|
|
@@ -45,8 +56,8 @@ class LzDecoder {
|
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
/** Copies `len` bytes starting `dist + 1` positions back. */
|
|
48
|
-
repeat(dist,
|
|
49
|
-
let len =
|
|
59
|
+
repeat(dist, lenIn) {
|
|
60
|
+
let len = lenIn;
|
|
50
61
|
const history = this.wrapped ? this.buf.length : this.pos;
|
|
51
62
|
if (dist < 0 || dist >= history) {
|
|
52
63
|
throw new Error('Corrupted input: match distance is too large');
|
|
@@ -75,36 +86,6 @@ class LzDecoder {
|
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Copies `len` bytes of uncompressed data from `input` at `inPos`. XZ for
|
|
80
|
-
* Java copies up to the end of the buffer and leaves the rest to its
|
|
81
|
-
* caller; this copy continues past the end like `repeat`.
|
|
82
|
-
*/
|
|
83
|
-
copyUncompressed(input, offset, length) {
|
|
84
|
-
let inPos = offset;
|
|
85
|
-
let len = length;
|
|
86
|
-
while (len > 0) {
|
|
87
|
-
const copySize = Math.min(this.buf.length - this.pos, len);
|
|
88
|
-
this.buf.set(input.subarray(inPos, inPos + copySize), this.pos);
|
|
89
|
-
this.pos += copySize;
|
|
90
|
-
inPos += copySize;
|
|
91
|
-
len -= copySize;
|
|
92
|
-
if (this.pos === this.buf.length) {
|
|
93
|
-
this.onBufferEnd();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/** Empties the dictionary, so matches can't reach back before this point. */
|
|
98
|
-
reset() {
|
|
99
|
-
// In XZ for Java the caller flushes first. Here the sink has to get
|
|
100
|
-
// the pending bytes before the positions restart, or they are lost.
|
|
101
|
-
this.flush();
|
|
102
|
-
this.start = 0;
|
|
103
|
-
this.pos = 0;
|
|
104
|
-
this.wrapped = false;
|
|
105
|
-
// getByte(0) has to return 0x00 when nothing has been decoded.
|
|
106
|
-
this.buf[this.buf.length - 1] = 0x00;
|
|
107
|
-
}
|
|
108
89
|
/** Passes all pending bytes to the sink. */
|
|
109
90
|
flush() {
|
|
110
91
|
if (this.pos > this.start) {
|
|
@@ -112,6 +93,7 @@ class LzDecoder {
|
|
|
112
93
|
}
|
|
113
94
|
this.start = this.pos;
|
|
114
95
|
}
|
|
96
|
+
/** Grows the buffer, or passes its bytes to the sink and wraps around. */
|
|
115
97
|
onBufferEnd() {
|
|
116
98
|
if (!this.wrapped && this.buf.length < this.maxSize) {
|
|
117
99
|
const grown = new Uint8Array(Math.min(this.buf.length * 2, this.maxSize));
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* read position gets close to the end of the buffer, the window is moved
|
|
7
7
|
* back to the start of the buffer.
|
|
8
8
|
*
|
|
9
|
-
* Ported from XZ for Java (0BSD)
|
|
9
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/LZEncoder.java`,
|
|
10
|
+
* `Matches.java` and `MatchLength.java`, by Lasse Collin and Igor Pavlov.
|
|
10
11
|
*/
|
|
11
12
|
export type MatchFinderType = 'hc4' | 'bt4';
|
|
12
13
|
/** Matches found at one position, sorted by increasing length. */
|
|
@@ -60,7 +61,7 @@ export declare abstract class LzEncoder {
|
|
|
60
61
|
*
|
|
61
62
|
* @returns number of bytes consumed; call again with the rest
|
|
62
63
|
*/
|
|
63
|
-
fillWindow(input: Uint8Array, off: number,
|
|
64
|
+
fillWindow(input: Uint8Array, off: number, lenIn: number): number;
|
|
64
65
|
/** Marks the end of input so that the lookahead can be used up. */
|
|
65
66
|
setFinishing(): void;
|
|
66
67
|
isStarted(): boolean;
|
package/dist/lzma1/lz-encoder.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for
|
|
2
|
+
// Copied from lzma1 0.6.1 (Apache-2.0, Copyright Filip Seman) and changed for archive-defuse. NOTICE in this folder lists the changes.
|
|
3
3
|
/**
|
|
4
4
|
* Encoder-side LZ window and the base class of the match finders.
|
|
5
5
|
*
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* read position gets close to the end of the buffer, the window is moved
|
|
9
9
|
* back to the start of the buffer.
|
|
10
10
|
*
|
|
11
|
-
* Ported from XZ for Java (0BSD)
|
|
11
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lz/LZEncoder.java`,
|
|
12
|
+
* `Matches.java` and `MatchLength.java`, by Lasse Collin and Igor Pavlov.
|
|
12
13
|
*/
|
|
13
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
15
|
exports.LzEncoder = exports.Matches = void 0;
|
|
@@ -83,11 +84,12 @@ class LzEncoder {
|
|
|
83
84
|
*
|
|
84
85
|
* @returns number of bytes consumed; call again with the rest
|
|
85
86
|
*/
|
|
86
|
-
fillWindow(input, off,
|
|
87
|
+
fillWindow(input, off, lenIn) {
|
|
88
|
+
let len = lenIn;
|
|
87
89
|
if (this.readPos >= this.buf.length - this.keepSizeAfter) {
|
|
88
90
|
this.moveWindow();
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
len = Math.min(len, this.buf.length - this.writePos);
|
|
91
93
|
this.buf.set(input.subarray(off, off + len), this.writePos);
|
|
92
94
|
this.writePos += len;
|
|
93
95
|
if (this.writePos >= this.keepSizeAfter) {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Probability models and state machine shared by the LZMA encoder and decoder.
|
|
3
3
|
*
|
|
4
|
-
* Ported from XZ for Java (0BSD)
|
|
4
|
+
* Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lzma/LZMACoder.java`
|
|
5
|
+
* and `State.java`, by Lasse Collin and Igor Pavlov.
|
|
6
|
+
*
|
|
7
|
+
* The nested coder classes of the Java code (`LiteralCoder.LiteralSubcoder`,
|
|
8
|
+
* `LengthCoder`) are top-level classes here, because TypeScript has no inner
|
|
9
|
+
* classes; subclasses in the encoder and decoder files pass their outer
|
|
10
|
+
* coder explicitly where Java captures it implicitly.
|
|
5
11
|
*/
|
|
6
12
|
import { type Probs } from './range-coder';
|
|
7
13
|
export declare const POS_STATES_MAX: number;
|
|
@@ -22,8 +28,9 @@ export declare const LEN_MID: number;
|
|
|
22
28
|
export declare const LEN_HIGH: number;
|
|
23
29
|
export declare const LEN_SIZE: number;
|
|
24
30
|
export declare const DIST_STATES = 4;
|
|
31
|
+
export declare const DIST_SLOTS: number;
|
|
32
|
+
/** Bits of a distance slot: the depth of the slot bit trees. */
|
|
25
33
|
export declare const DIST_SLOT_BITS = 6;
|
|
26
|
-
export declare const DIST_SLOT_COUNT: number;
|
|
27
34
|
export declare const DIST_MODEL_START = 4;
|
|
28
35
|
export declare const DIST_MODEL_END = 14;
|
|
29
36
|
export declare const FULL_DISTANCES: number;
|
|
@@ -32,24 +39,39 @@ export declare const ALIGN_SIZE: number;
|
|
|
32
39
|
export declare const ALIGN_MASK: number;
|
|
33
40
|
/** Number of recent match distances ("reps") that can be reused cheaply. */
|
|
34
41
|
export declare const REPS = 4;
|
|
42
|
+
/** Distances are coded with different probabilities for lengths 2, 3, 4 and 5+. */
|
|
43
|
+
export declare function getDistState(len: number): number;
|
|
44
|
+
/** Number of probabilities of a coder with `lc` and `lp` literal bits. */
|
|
45
|
+
export declare function probsSize(lc: number, lp: number): number;
|
|
35
46
|
/**
|
|
36
47
|
* The coder state remembers the kinds of the most recent symbols
|
|
37
48
|
* (literal, match, long rep, short rep). It selects which probabilities
|
|
38
49
|
* are used for the next symbol.
|
|
39
50
|
*/
|
|
51
|
+
export declare class State {
|
|
52
|
+
static readonly STATES = 12;
|
|
53
|
+
private state;
|
|
54
|
+
constructor(other?: State);
|
|
55
|
+
reset(): void;
|
|
56
|
+
get(): number;
|
|
57
|
+
set(other: State): void;
|
|
58
|
+
updateLiteral(): void;
|
|
59
|
+
updateMatch(): void;
|
|
60
|
+
updateLongRep(): void;
|
|
61
|
+
updateShortRep(): void;
|
|
62
|
+
isLiteral(): boolean;
|
|
63
|
+
}
|
|
40
64
|
export declare const STATES = 12;
|
|
41
|
-
export declare const INITIAL_STATE = 0;
|
|
42
|
-
export declare function isLiteralState(state: number): boolean;
|
|
43
65
|
export declare function stateAfterLiteral(state: number): number;
|
|
44
66
|
export declare function stateAfterMatch(state: number): number;
|
|
45
67
|
export declare function stateAfterLongRep(state: number): number;
|
|
46
68
|
export declare function stateAfterShortRep(state: number): number;
|
|
47
|
-
|
|
48
|
-
export declare function getDistState(len: number): number;
|
|
69
|
+
export declare function isLiteralState(state: number): boolean;
|
|
49
70
|
/**
|
|
50
71
|
* Layout of the probability array. All probabilities of a coder live in one
|
|
51
|
-
* `Uint16Array`, like in the LZMA SDK and liblzma
|
|
52
|
-
* and the hot loops index a
|
|
72
|
+
* `Uint16Array`, like in the LZMA SDK and liblzma, instead of the
|
|
73
|
+
* Java code's per-model arrays: one allocation, and the hot loops index a
|
|
74
|
+
* single array.
|
|
53
75
|
*
|
|
54
76
|
* Bit trees of `2^n` leaves occupy `2^n` entries starting at their offset;
|
|
55
77
|
* index 0 of a tree is unused.
|
|
@@ -61,7 +83,7 @@ export declare const IS_REP1: number;
|
|
|
61
83
|
export declare const IS_REP2: number;
|
|
62
84
|
export declare const IS_REP0_LONG: number;
|
|
63
85
|
/** Bit trees of 6 bits per distance state. */
|
|
64
|
-
export declare const
|
|
86
|
+
export declare const DIST_SLOT_OFFSET: number;
|
|
65
87
|
/** Reverse bit trees for the low bits of distances in slots 4-13. */
|
|
66
88
|
export declare const DIST_SPECIAL: number;
|
|
67
89
|
/** Reverse bit tree for the lowest 4 bits of distances in slots 14+. */
|
|
@@ -77,17 +99,10 @@ export declare const LITERAL: number;
|
|
|
77
99
|
* trees of all slots fill `FULL_DISTANCES - DIST_MODEL_END` entries.
|
|
78
100
|
*/
|
|
79
101
|
export declare function distSpecialOffset(distSlot: number, base: number): number;
|
|
80
|
-
|
|
81
|
-
export declare function probsSize(lc: number, lp: number): number;
|
|
82
|
-
/**
|
|
83
|
-
* Probability models and coder state shared by the encoder and decoder.
|
|
84
|
-
*/
|
|
85
|
-
export declare class LzmaCoder {
|
|
102
|
+
export declare abstract class LzmaCoder {
|
|
86
103
|
readonly posMask: number;
|
|
87
|
-
private readonly lc;
|
|
88
|
-
private readonly literalPosMask;
|
|
89
104
|
readonly reps: Int32Array<ArrayBuffer>;
|
|
90
|
-
state:
|
|
105
|
+
readonly state: State;
|
|
91
106
|
readonly probs: Probs;
|
|
92
107
|
/**
|
|
93
108
|
* @param probs Probability array to reuse, of `probsSize(lc, lp)` entries.
|
|
@@ -95,13 +110,22 @@ export declare class LzmaCoder {
|
|
|
95
110
|
*/
|
|
96
111
|
constructor(lc: number, lp: number, pb: number, probs?: Probs);
|
|
97
112
|
reset(): void;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
}
|
|
114
|
+
export declare abstract class LiteralCoder {
|
|
115
|
+
private readonly lc;
|
|
116
|
+
private readonly literalPosMask;
|
|
117
|
+
constructor(lc: number, lp: number);
|
|
118
|
+
getSubcoderIndex(prevByte: number, pos: number): number;
|
|
119
|
+
}
|
|
120
|
+
export declare abstract class LiteralSubcoder {
|
|
121
|
+
readonly probs: Probs;
|
|
122
|
+
/** Offset of this subcoder's 0x300 probabilities in `probs`. */
|
|
123
|
+
readonly literalOffset: number;
|
|
124
|
+
constructor(probs: Probs, literalOffset: number);
|
|
125
|
+
}
|
|
126
|
+
export declare abstract class LengthCoder {
|
|
127
|
+
readonly probs: Probs;
|
|
128
|
+
/** Offset of this length coder in `probs`. */
|
|
129
|
+
readonly coder: number;
|
|
130
|
+
constructor(probs: Probs, coder: number);
|
|
107
131
|
}
|