zstdify 1.1.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -2
- package/dist/bitstream/bitReaderReverse.d.ts +6 -0
- package/dist/bitstream/bitReaderReverse.js +51 -1
- package/dist/bitstream/bitReaderReverse.js.map +1 -1
- package/dist/bitstream/index.d.ts +1 -0
- package/dist/bitstream/index.js +1 -0
- package/dist/bitstream/index.js.map +1 -1
- package/dist/bitstream/reverseBitWriter.d.ts +1 -0
- package/dist/bitstream/reverseBitWriter.js +66 -0
- package/dist/bitstream/reverseBitWriter.js.map +1 -0
- package/dist/compress.js +47 -7
- package/dist/compress.js.map +1 -1
- package/dist/decode/debugTrace.d.ts +31 -0
- package/dist/decode/debugTrace.js +2 -0
- package/dist/decode/debugTrace.js.map +1 -0
- package/dist/decode/decompressFrame.d.ts +3 -1
- package/dist/decode/decompressFrame.js +153 -59
- package/dist/decode/decompressFrame.js.map +1 -1
- package/dist/decode/fusedSequences.d.ts +9 -0
- package/dist/decode/fusedSequences.js +26 -0
- package/dist/decode/fusedSequences.js.map +1 -0
- package/dist/decode/literals.js +164 -111
- package/dist/decode/literals.js.map +1 -1
- package/dist/decode/reconstruct.d.ts +33 -1
- package/dist/decode/reconstruct.js +591 -24
- package/dist/decode/reconstruct.js.map +1 -1
- package/dist/decode/sequences.d.ts +19 -7
- package/dist/decode/sequences.js +225 -133
- package/dist/decode/sequences.js.map +1 -1
- package/dist/decompress.d.ts +10 -0
- package/dist/decompress.js +5 -3
- package/dist/decompress.js.map +1 -1
- package/dist/encode/blockWriter.js +8 -2
- package/dist/encode/blockWriter.js.map +1 -1
- package/dist/encode/compressedBlock.d.ts +27 -1
- package/dist/encode/compressedBlock.js +594 -339
- package/dist/encode/compressedBlock.js.map +1 -1
- package/dist/encode/fastMatcher.d.ts +7 -0
- package/dist/encode/fastMatcher.js +13 -0
- package/dist/encode/fastMatcher.js.map +1 -0
- package/dist/encode/greedySequences.d.ts +9 -6
- package/dist/encode/greedySequences.js +21 -77
- package/dist/encode/greedySequences.js.map +1 -1
- package/dist/encode/lazyMatcher.d.ts +7 -0
- package/dist/encode/lazyMatcher.js +13 -0
- package/dist/encode/lazyMatcher.js.map +1 -0
- package/dist/encode/literalsEncoder.d.ts +14 -0
- package/dist/encode/literalsEncoder.js +343 -0
- package/dist/encode/literalsEncoder.js.map +1 -0
- package/dist/encode/optimalParser.d.ts +7 -0
- package/dist/encode/optimalParser.js +13 -0
- package/dist/encode/optimalParser.js.map +1 -0
- package/dist/encode/sequencePlanner.d.ts +23 -0
- package/dist/encode/sequencePlanner.js +280 -0
- package/dist/encode/sequencePlanner.js.map +1 -0
- package/dist/entropy/fse.d.ts +13 -6
- package/dist/entropy/fse.js +176 -13
- package/dist/entropy/fse.js.map +1 -1
- package/dist/entropy/huffman.d.ts +7 -5
- package/dist/entropy/huffman.js +18 -7
- package/dist/entropy/huffman.js.map +1 -1
- package/dist/entropy/index.d.ts +2 -2
- package/dist/entropy/weights.js +20 -14
- package/dist/entropy/weights.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/decompress.js
CHANGED
|
@@ -12,6 +12,7 @@ export function decompress(input, options) {
|
|
|
12
12
|
}
|
|
13
13
|
const maxSize = options?.maxSize;
|
|
14
14
|
const dictionary = options?.dictionary;
|
|
15
|
+
const validateChecksum = options?.validateChecksum !== false;
|
|
15
16
|
const dictionaryBytes = dictionary instanceof Uint8Array ? dictionary : dictionary?.bytes;
|
|
16
17
|
const providedDictionaryId = dictionary instanceof Uint8Array ? null : (dictionary?.id ?? null);
|
|
17
18
|
const normalizedDictionary = dictionaryBytes && dictionaryBytes.length > 0
|
|
@@ -19,6 +20,7 @@ export function decompress(input, options) {
|
|
|
19
20
|
: null;
|
|
20
21
|
const dictionaryId = normalizedDictionary?.dictionaryId ?? providedDictionaryId;
|
|
21
22
|
const chunks = [];
|
|
23
|
+
let totalOutputSize = 0;
|
|
22
24
|
let offset = 0;
|
|
23
25
|
while (offset < input.length) {
|
|
24
26
|
if (offset + 4 > input.length) {
|
|
@@ -35,8 +37,9 @@ export function decompress(input, options) {
|
|
|
35
37
|
if (header.dictionaryId !== null && dictionaryId !== null && dictionaryId !== header.dictionaryId) {
|
|
36
38
|
throw new ZstdError('Dictionary ID mismatch', 'corruption_detected');
|
|
37
39
|
}
|
|
38
|
-
const { output, bytesConsumed } = decompressFrame(input, offset, header, normalizedDictionary, maxSize !== undefined ? maxSize -
|
|
40
|
+
const { output, bytesConsumed } = decompressFrame(input, offset, header, normalizedDictionary, maxSize !== undefined ? maxSize - totalOutputSize : undefined, validateChecksum, options?.reuseContext, options?.debugTrace);
|
|
39
41
|
chunks.push(output);
|
|
42
|
+
totalOutputSize += output.length;
|
|
40
43
|
offset += bytesConsumed;
|
|
41
44
|
}
|
|
42
45
|
if (chunks.length === 0)
|
|
@@ -47,8 +50,7 @@ export function decompress(input, options) {
|
|
|
47
50
|
throw new ZstdError('Unreachable', 'corruption_detected');
|
|
48
51
|
return c;
|
|
49
52
|
}
|
|
50
|
-
const
|
|
51
|
-
const result = new Uint8Array(total);
|
|
53
|
+
const result = new Uint8Array(totalOutputSize);
|
|
52
54
|
let pos = 0;
|
|
53
55
|
for (const chunk of chunks) {
|
|
54
56
|
result.set(chunk, pos);
|
package/dist/decompress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE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CAAC;QAClE,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC;IAC/C,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACvB,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACf"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Write raw and RLE blocks.
|
|
3
3
|
*/
|
|
4
|
+
let sharedHeader = null;
|
|
4
5
|
function writeU24LE(arr, offset, value) {
|
|
5
6
|
arr[offset] = value & 0xff;
|
|
6
7
|
arr[offset + 1] = (value >> 8) & 0xff;
|
|
7
8
|
arr[offset + 2] = (value >> 16) & 0xff;
|
|
8
9
|
}
|
|
10
|
+
function getHeader() {
|
|
11
|
+
if (!sharedHeader)
|
|
12
|
+
sharedHeader = new Uint8Array(3);
|
|
13
|
+
return sharedHeader;
|
|
14
|
+
}
|
|
9
15
|
export function writeRawBlock(data, offset, size, last) {
|
|
10
|
-
const header =
|
|
16
|
+
const header = getHeader();
|
|
11
17
|
const blockHeader = (last ? 1 : 0) | (0 << 1) | (size << 3);
|
|
12
18
|
writeU24LE(header, 0, blockHeader);
|
|
13
19
|
const result = new Uint8Array(3 + size);
|
|
@@ -16,7 +22,7 @@ export function writeRawBlock(data, offset, size, last) {
|
|
|
16
22
|
return result;
|
|
17
23
|
}
|
|
18
24
|
export function writeRLEBlock(byte, size, last) {
|
|
19
|
-
const header =
|
|
25
|
+
const header = getHeader();
|
|
20
26
|
const blockHeader = (last ? 1 : 0) | (1 << 1) | (size << 3);
|
|
21
27
|
writeU24LE(header, 0, blockHeader);
|
|
22
28
|
const result = new Uint8Array(4);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockWriter.js","sourceRoot":"","sources":["../../src/encode/blockWriter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,SAAS,UAAU,CAAC,GAAe,EAAE,MAAc,EAAE,KAAa,EAAQ;IACxE,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;IAC3B,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;AAAA,CACxC;AAED,MAAM,UAAU,aAAa,CAAC,IAAgB,EAAE,MAAc,EAAE,IAAY,EAAE,IAAa,EAAc;IACvG,MAAM,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"blockWriter.js","sourceRoot":"","sources":["../../src/encode/blockWriter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,IAAI,YAAY,GAAsB,IAAI,CAAC;AAE3C,SAAS,UAAU,CAAC,GAAe,EAAE,MAAc,EAAE,KAAa,EAAQ;IACxE,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;IAC3B,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;AAAA,CACxC;AAED,SAAS,SAAS,GAAe;IAC/B,IAAI,CAAC,YAAY;QAAE,YAAY,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,YAAY,CAAC;AAAA,CACrB;AAED,MAAM,UAAU,aAAa,CAAC,IAAgB,EAAE,MAAc,EAAE,IAAY,EAAE,IAAa,EAAc;IACvG,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC5D,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC;AAAA,CACf;AAED,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,IAAY,EAAE,IAAa,EAAc;IACnF,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC5D,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACtB,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACxB,OAAO,MAAM,CAAC;AAAA,CACf"}
|
|
@@ -1,3 +1,29 @@
|
|
|
1
1
|
import type { Sequence } from '../decode/reconstruct.js';
|
|
2
|
-
|
|
2
|
+
import { type FSEDecodeTable } from '../entropy/fse.js';
|
|
3
|
+
import { encodeReverseBitstream } from '../bitstream/reverseBitWriter.js';
|
|
4
|
+
import { buildGeneralCompressedLiteralsForBench, type LiteralEntropyTable } from './literalsEncoder.js';
|
|
5
|
+
interface SequenceTablesState {
|
|
6
|
+
llTable: FSEDecodeTable;
|
|
7
|
+
llTableLog: number;
|
|
8
|
+
ofTable: FSEDecodeTable;
|
|
9
|
+
ofTableLog: number;
|
|
10
|
+
mlTable: FSEDecodeTable;
|
|
11
|
+
mlTableLog: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SequenceEntropyContext {
|
|
14
|
+
prevTables: SequenceTablesState | null;
|
|
15
|
+
prevLiteralsTable?: LiteralEntropyTable | null;
|
|
16
|
+
}
|
|
17
|
+
declare function buildSequenceSection(sequences: readonly Sequence[], context?: SequenceEntropyContext): {
|
|
18
|
+
section: Uint8Array;
|
|
19
|
+
tables: SequenceTablesState;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function buildCompressedBlockPayload(literals: Uint8Array, sequences: Sequence[], context?: SequenceEntropyContext): Uint8Array | null;
|
|
3
22
|
export declare function writeCompressedBlock(payload: Uint8Array, last: boolean): Uint8Array;
|
|
23
|
+
export declare const __benchInternals: {
|
|
24
|
+
encodeReverseBitstream: typeof encodeReverseBitstream;
|
|
25
|
+
buildGeneralCompressedLiterals: typeof buildGeneralCompressedLiteralsForBench;
|
|
26
|
+
buildPredefinedSequenceSection: (sequences: readonly Sequence[]) => Uint8Array<ArrayBufferLike> | null;
|
|
27
|
+
buildSequenceSection: typeof buildSequenceSection;
|
|
28
|
+
};
|
|
29
|
+
export {};
|