@structured-world/structured-zstd 0.0.32 → 0.0.34
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/index.d.ts +83 -10
- package/index.d.ts.map +1 -1
- package/index.js +74 -13
- package/index.js.map +1 -1
- package/index.ts +133 -18
- package/package.json +1 -1
- package/scalar/structured_zstd_wasm.d.ts +90 -16
- package/scalar/structured_zstd_wasm.js +142 -18
- package/scalar/structured_zstd_wasm_bg.wasm +0 -0
- package/scalar/structured_zstd_wasm_bg.wasm.d.ts +10 -6
- package/simd/structured_zstd_wasm.d.ts +90 -16
- package/simd/structured_zstd_wasm.js +142 -18
- package/simd/structured_zstd_wasm_bg.wasm +0 -0
- package/simd/structured_zstd_wasm_bg.wasm.d.ts +10 -6
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* How the decoder treats a frame's optional content checksum. Mirrors the
|
|
6
|
+
* core `structured_zstd::decoding::ContentChecksum`.
|
|
7
|
+
*/
|
|
8
|
+
export enum ContentChecksum {
|
|
9
|
+
/**
|
|
10
|
+
* Skip the XXH64 pass entirely (fastest; no verification).
|
|
11
|
+
*/
|
|
12
|
+
None = 0,
|
|
13
|
+
/**
|
|
14
|
+
* Compute the checksum and expose it via accessors; does not error on a mismatch.
|
|
15
|
+
*/
|
|
16
|
+
EmitOnly = 1,
|
|
17
|
+
/**
|
|
18
|
+
* Compute and verify; a mismatch throws on decode.
|
|
19
|
+
*/
|
|
20
|
+
Verify = 2,
|
|
21
|
+
}
|
|
22
|
+
|
|
4
23
|
/**
|
|
5
24
|
* Incremental streaming compressor: feed plaintext chunks via
|
|
6
25
|
* [`ZstdCompressStream::push`] and receive complete compressed blocks as the
|
|
7
26
|
* matcher window fills, then [`ZstdCompressStream::finish`] to seal the frame
|
|
8
|
-
* (final block
|
|
27
|
+
* (final block, plus the XXH64 trailer only when `checksum` was enabled).
|
|
28
|
+
* Peak working set is O(window), not
|
|
9
29
|
* O(input) — emitted blocks are flushed to the caller while only the matcher
|
|
10
30
|
* window is retained — so a large payload never has to be buffered whole. The
|
|
11
31
|
* produced frame omits `Frame_Content_Size` (the total is unknown while
|
|
@@ -22,14 +42,26 @@ export class ZstdCompressStream {
|
|
|
22
42
|
finish(): Uint8Array;
|
|
23
43
|
/**
|
|
24
44
|
* Open a streaming compressor at `level` (zstd scale: `1..=22`, negatives
|
|
25
|
-
* for the ultra-fast tier).
|
|
45
|
+
* for the ultra-fast tier). `checksum` is optional (default `false`,
|
|
46
|
+
* matching libzstd's `ZSTD_c_checksumFlag = 0`): pass `true` to seal the
|
|
47
|
+
* frame with a trailing content checksum.
|
|
26
48
|
*/
|
|
27
|
-
constructor(level: number);
|
|
49
|
+
constructor(level: number, checksum?: boolean | null);
|
|
28
50
|
/**
|
|
29
51
|
* Feed more plaintext; returns whatever compressed bytes are now complete
|
|
30
52
|
* (possibly empty while the current block is still filling).
|
|
31
53
|
*/
|
|
32
54
|
push(chunk: Uint8Array): Uint8Array;
|
|
55
|
+
/**
|
|
56
|
+
* Open a streaming compressor at `level` seeded with a raw zstd dictionary
|
|
57
|
+
* blob (e.g. from `zstd --train`), mirroring `ZSTD_CCtx_loadDictionary` on
|
|
58
|
+
* a streaming context: the dictionary primes the matcher and seeds the
|
|
59
|
+
* first block's entropy + repeat offsets, and its ID is written into the
|
|
60
|
+
* frame header. Decode the produced frames with [`ZstdDecompressStream`]
|
|
61
|
+
* opened via its matching `withDictionary` constructor (or the one-shot
|
|
62
|
+
* `decompressUsingDict`). Throws if the dictionary is invalid.
|
|
63
|
+
*/
|
|
64
|
+
static withDictionary(level: number, dict: Uint8Array, checksum?: boolean | null): ZstdCompressStream;
|
|
33
65
|
}
|
|
34
66
|
|
|
35
67
|
/**
|
|
@@ -42,17 +74,44 @@ export class ZstdCompressStream {
|
|
|
42
74
|
export class ZstdDecompressStream {
|
|
43
75
|
free(): void;
|
|
44
76
|
[Symbol.dispose](): void;
|
|
77
|
+
/**
|
|
78
|
+
* The XXH64 digest the decoder computed over the output (low 32 bits), or
|
|
79
|
+
* `undefined` when the mode is `None` or the frame carried no checksum.
|
|
80
|
+
* Meaningful after [`Self::finish`]; lets callers verify manually under
|
|
81
|
+
* `EmitOnly` without enabling the throwing `Verify` mode.
|
|
82
|
+
*/
|
|
83
|
+
calculatedChecksum(): number | undefined;
|
|
45
84
|
/**
|
|
46
85
|
* Signal end of input; returns the final decompressed bytes. Throws if the
|
|
47
|
-
* stream ended before the frame completed
|
|
86
|
+
* stream ended before the frame completed, or (in `Verify` mode) if the
|
|
87
|
+
* content checksum does not match.
|
|
48
88
|
*/
|
|
49
89
|
finish(): Uint8Array;
|
|
50
|
-
|
|
90
|
+
/**
|
|
91
|
+
* `checksum` is optional (default `None` — skip the XXH64 pass, matching
|
|
92
|
+
* the one-shot `decompress` default) and applies to the whole stream, so
|
|
93
|
+
* set it here rather than mid-stream: `Verify` validates the content
|
|
94
|
+
* checksum at [`Self::finish`], `EmitOnly` computes it without erroring.
|
|
95
|
+
*/
|
|
96
|
+
constructor(checksum?: ContentChecksum | null);
|
|
51
97
|
/**
|
|
52
98
|
* Feed more compressed bytes; returns whatever decompressed output is now
|
|
53
99
|
* available (possibly empty while a block is still incomplete).
|
|
54
100
|
*/
|
|
55
101
|
push(chunk: Uint8Array): Uint8Array;
|
|
102
|
+
/**
|
|
103
|
+
* The content checksum stored in the frame's 4-byte trailer, or
|
|
104
|
+
* `undefined` if the frame carried none. Meaningful after [`Self::finish`].
|
|
105
|
+
*/
|
|
106
|
+
storedChecksum(): number | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Open a streaming decompressor primed with a raw zstd dictionary blob
|
|
109
|
+
* (`ZSTD_DCtx_loadDictionary`): `dict` must be the same dictionary the
|
|
110
|
+
* frame was compressed with (e.g. via [`ZstdCompressStream`]'s
|
|
111
|
+
* `withDictionary`). `checksum` behaves as in [`Self::new`]. Throws if the
|
|
112
|
+
* dictionary is malformed.
|
|
113
|
+
*/
|
|
114
|
+
static withDictionary(dict: Uint8Array, checksum?: ContentChecksum | null): ZstdDecompressStream;
|
|
56
115
|
}
|
|
57
116
|
|
|
58
117
|
/**
|
|
@@ -61,8 +120,12 @@ export class ZstdDecompressStream {
|
|
|
61
120
|
* `level` follows the zstd scale: `1..=22` (higher = smaller/slower) and
|
|
62
121
|
* negative levels (`-7..=-1`) for the ultra-fast tier. The returned frame
|
|
63
122
|
* decodes in any compliant zstd decoder, including the native C library.
|
|
123
|
+
*
|
|
124
|
+
* `checksum` is optional (default `false`, matching libzstd's
|
|
125
|
+
* `ZSTD_c_checksumFlag = 0`): pass `true` to append the trailing XXH64 content
|
|
126
|
+
* checksum.
|
|
64
127
|
*/
|
|
65
|
-
export function compress(data: Uint8Array, level: number): Uint8Array;
|
|
128
|
+
export function compress(data: Uint8Array, level: number, checksum?: boolean | null): Uint8Array;
|
|
66
129
|
|
|
67
130
|
/**
|
|
68
131
|
* Compress `data` against a raw Zstandard dictionary at compression `level`.
|
|
@@ -70,15 +133,22 @@ export function compress(data: Uint8Array, level: number): Uint8Array;
|
|
|
70
133
|
* Mirrors C `ZSTD_compress_usingDict`: the dictionary primes the encoder so
|
|
71
134
|
* small, similar payloads compress far better. The dictionary is the raw
|
|
72
135
|
* zstd dictionary blob (e.g. from `zstd --train`). Throws if it is invalid.
|
|
136
|
+
*
|
|
137
|
+
* `checksum` is optional (default `false`, matching libzstd's
|
|
138
|
+
* `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64 trailer.
|
|
73
139
|
*/
|
|
74
|
-
export function compressUsingDict(data: Uint8Array, dict: Uint8Array, level: number): Uint8Array;
|
|
140
|
+
export function compressUsingDict(data: Uint8Array, dict: Uint8Array, level: number, checksum?: boolean | null): Uint8Array;
|
|
75
141
|
|
|
76
142
|
/**
|
|
77
143
|
* Decompress a complete Zstandard frame back into its original bytes.
|
|
78
144
|
*
|
|
79
|
-
* Throws a JavaScript `Error` if the input is not a valid, complete frame
|
|
145
|
+
* Throws a JavaScript `Error` if the input is not a valid, complete frame,
|
|
146
|
+
* or (when `checksum` is `Verify`) if the content checksum does not match.
|
|
147
|
+
* `checksum` is optional (default `None` — skip the XXH64 pass for speed);
|
|
148
|
+
* pass `ContentChecksum.Verify` to validate, or `EmitOnly` to compute without
|
|
149
|
+
* erroring on mismatch.
|
|
80
150
|
*/
|
|
81
|
-
export function decompress(data: Uint8Array): Uint8Array;
|
|
151
|
+
export function decompress(data: Uint8Array, checksum?: ContentChecksum | null): Uint8Array;
|
|
82
152
|
|
|
83
153
|
/**
|
|
84
154
|
* Decompress a dictionary-encoded Zstandard frame.
|
|
@@ -87,7 +157,7 @@ export function decompress(data: Uint8Array): Uint8Array;
|
|
|
87
157
|
* dictionary the frame was compressed with. Throws on a malformed frame or a
|
|
88
158
|
* dictionary mismatch.
|
|
89
159
|
*/
|
|
90
|
-
export function decompressUsingDict(data: Uint8Array, dict: Uint8Array): Uint8Array;
|
|
160
|
+
export function decompressUsingDict(data: Uint8Array, dict: Uint8Array, checksum?: ContentChecksum | null): Uint8Array;
|
|
91
161
|
|
|
92
162
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
93
163
|
|
|
@@ -95,16 +165,20 @@ export interface InitOutput {
|
|
|
95
165
|
readonly memory: WebAssembly.Memory;
|
|
96
166
|
readonly __wbg_zstdcompressstream_free: (a: number, b: number) => void;
|
|
97
167
|
readonly __wbg_zstddecompressstream_free: (a: number, b: number) => void;
|
|
98
|
-
readonly compress: (a: number, b: number, c: number) => [number, number];
|
|
99
|
-
readonly compressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
100
|
-
readonly decompress: (a: number, b: number) => [number, number, number, number];
|
|
101
|
-
readonly decompressUsingDict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
168
|
+
readonly compress: (a: number, b: number, c: number, d: number) => [number, number];
|
|
169
|
+
readonly compressUsingDict: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
170
|
+
readonly decompress: (a: number, b: number, c: number) => [number, number, number, number];
|
|
171
|
+
readonly decompressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
102
172
|
readonly zstdcompressstream_finish: (a: number) => [number, number, number, number];
|
|
103
|
-
readonly zstdcompressstream_new: (a: number) => number;
|
|
173
|
+
readonly zstdcompressstream_new: (a: number, b: number) => number;
|
|
104
174
|
readonly zstdcompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
175
|
+
readonly zstdcompressstream_withDictionary: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
176
|
+
readonly zstddecompressstream_calculatedChecksum: (a: number) => number;
|
|
105
177
|
readonly zstddecompressstream_finish: (a: number) => [number, number, number, number];
|
|
106
|
-
readonly zstddecompressstream_new: () => number;
|
|
178
|
+
readonly zstddecompressstream_new: (a: number) => number;
|
|
107
179
|
readonly zstddecompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
180
|
+
readonly zstddecompressstream_storedChecksum: (a: number) => number;
|
|
181
|
+
readonly zstddecompressstream_withDictionary: (a: number, b: number, c: number) => [number, number, number];
|
|
108
182
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
109
183
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
110
184
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
/* @ts-self-types="./structured_zstd_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* How the decoder treats a frame's optional content checksum. Mirrors the
|
|
5
|
+
* core `structured_zstd::decoding::ContentChecksum`.
|
|
6
|
+
* @enum {0 | 1 | 2}
|
|
7
|
+
*/
|
|
8
|
+
export const ContentChecksum = Object.freeze({
|
|
9
|
+
/**
|
|
10
|
+
* Skip the XXH64 pass entirely (fastest; no verification).
|
|
11
|
+
*/
|
|
12
|
+
None: 0, "0": "None",
|
|
13
|
+
/**
|
|
14
|
+
* Compute the checksum and expose it via accessors; does not error on a mismatch.
|
|
15
|
+
*/
|
|
16
|
+
EmitOnly: 1, "1": "EmitOnly",
|
|
17
|
+
/**
|
|
18
|
+
* Compute and verify; a mismatch throws on decode.
|
|
19
|
+
*/
|
|
20
|
+
Verify: 2, "2": "Verify",
|
|
21
|
+
});
|
|
22
|
+
|
|
3
23
|
/**
|
|
4
24
|
* Incremental streaming compressor: feed plaintext chunks via
|
|
5
25
|
* [`ZstdCompressStream::push`] and receive complete compressed blocks as the
|
|
6
26
|
* matcher window fills, then [`ZstdCompressStream::finish`] to seal the frame
|
|
7
|
-
* (final block
|
|
27
|
+
* (final block, plus the XXH64 trailer only when `checksum` was enabled).
|
|
28
|
+
* Peak working set is O(window), not
|
|
8
29
|
* O(input) — emitted blocks are flushed to the caller while only the matcher
|
|
9
30
|
* window is retained — so a large payload never has to be buffered whole. The
|
|
10
31
|
* produced frame omits `Frame_Content_Size` (the total is unknown while
|
|
@@ -12,6 +33,12 @@
|
|
|
12
33
|
* [`ZstdDecompressStream`], making the wasm streaming API symmetric.
|
|
13
34
|
*/
|
|
14
35
|
export class ZstdCompressStream {
|
|
36
|
+
static __wrap(ptr) {
|
|
37
|
+
const obj = Object.create(ZstdCompressStream.prototype);
|
|
38
|
+
obj.__wbg_ptr = ptr;
|
|
39
|
+
ZstdCompressStreamFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
15
42
|
__destroy_into_raw() {
|
|
16
43
|
const ptr = this.__wbg_ptr;
|
|
17
44
|
this.__wbg_ptr = 0;
|
|
@@ -38,11 +65,14 @@ export class ZstdCompressStream {
|
|
|
38
65
|
}
|
|
39
66
|
/**
|
|
40
67
|
* Open a streaming compressor at `level` (zstd scale: `1..=22`, negatives
|
|
41
|
-
* for the ultra-fast tier).
|
|
68
|
+
* for the ultra-fast tier). `checksum` is optional (default `false`,
|
|
69
|
+
* matching libzstd's `ZSTD_c_checksumFlag = 0`): pass `true` to seal the
|
|
70
|
+
* frame with a trailing content checksum.
|
|
42
71
|
* @param {number} level
|
|
72
|
+
* @param {boolean | null} [checksum]
|
|
43
73
|
*/
|
|
44
|
-
constructor(level) {
|
|
45
|
-
const ret = wasm.zstdcompressstream_new(level);
|
|
74
|
+
constructor(level, checksum) {
|
|
75
|
+
const ret = wasm.zstdcompressstream_new(level, isLikeNone(checksum) ? 0xFFFFFF : checksum ? 1 : 0);
|
|
46
76
|
this.__wbg_ptr = ret;
|
|
47
77
|
ZstdCompressStreamFinalization.register(this, this.__wbg_ptr, this);
|
|
48
78
|
return this;
|
|
@@ -64,6 +94,28 @@ export class ZstdCompressStream {
|
|
|
64
94
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
65
95
|
return v2;
|
|
66
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Open a streaming compressor at `level` seeded with a raw zstd dictionary
|
|
99
|
+
* blob (e.g. from `zstd --train`), mirroring `ZSTD_CCtx_loadDictionary` on
|
|
100
|
+
* a streaming context: the dictionary primes the matcher and seeds the
|
|
101
|
+
* first block's entropy + repeat offsets, and its ID is written into the
|
|
102
|
+
* frame header. Decode the produced frames with [`ZstdDecompressStream`]
|
|
103
|
+
* opened via its matching `withDictionary` constructor (or the one-shot
|
|
104
|
+
* `decompressUsingDict`). Throws if the dictionary is invalid.
|
|
105
|
+
* @param {number} level
|
|
106
|
+
* @param {Uint8Array} dict
|
|
107
|
+
* @param {boolean | null} [checksum]
|
|
108
|
+
* @returns {ZstdCompressStream}
|
|
109
|
+
*/
|
|
110
|
+
static withDictionary(level, dict, checksum) {
|
|
111
|
+
const ptr0 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
112
|
+
const len0 = WASM_VECTOR_LEN;
|
|
113
|
+
const ret = wasm.zstdcompressstream_withDictionary(level, ptr0, len0, isLikeNone(checksum) ? 0xFFFFFF : checksum ? 1 : 0);
|
|
114
|
+
if (ret[2]) {
|
|
115
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
116
|
+
}
|
|
117
|
+
return ZstdCompressStream.__wrap(ret[0]);
|
|
118
|
+
}
|
|
67
119
|
}
|
|
68
120
|
if (Symbol.dispose) ZstdCompressStream.prototype[Symbol.dispose] = ZstdCompressStream.prototype.free;
|
|
69
121
|
|
|
@@ -75,6 +127,12 @@ if (Symbol.dispose) ZstdCompressStream.prototype[Symbol.dispose] = ZstdCompressS
|
|
|
75
127
|
* buffered — a surface the common npm wasm zstd packages do not offer.
|
|
76
128
|
*/
|
|
77
129
|
export class ZstdDecompressStream {
|
|
130
|
+
static __wrap(ptr) {
|
|
131
|
+
const obj = Object.create(ZstdDecompressStream.prototype);
|
|
132
|
+
obj.__wbg_ptr = ptr;
|
|
133
|
+
ZstdDecompressStreamFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
134
|
+
return obj;
|
|
135
|
+
}
|
|
78
136
|
__destroy_into_raw() {
|
|
79
137
|
const ptr = this.__wbg_ptr;
|
|
80
138
|
this.__wbg_ptr = 0;
|
|
@@ -85,9 +143,21 @@ export class ZstdDecompressStream {
|
|
|
85
143
|
const ptr = this.__destroy_into_raw();
|
|
86
144
|
wasm.__wbg_zstddecompressstream_free(ptr, 0);
|
|
87
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* The XXH64 digest the decoder computed over the output (low 32 bits), or
|
|
148
|
+
* `undefined` when the mode is `None` or the frame carried no checksum.
|
|
149
|
+
* Meaningful after [`Self::finish`]; lets callers verify manually under
|
|
150
|
+
* `EmitOnly` without enabling the throwing `Verify` mode.
|
|
151
|
+
* @returns {number | undefined}
|
|
152
|
+
*/
|
|
153
|
+
calculatedChecksum() {
|
|
154
|
+
const ret = wasm.zstddecompressstream_calculatedChecksum(this.__wbg_ptr);
|
|
155
|
+
return ret === Number.MAX_SAFE_INTEGER ? undefined : ret;
|
|
156
|
+
}
|
|
88
157
|
/**
|
|
89
158
|
* Signal end of input; returns the final decompressed bytes. Throws if the
|
|
90
|
-
* stream ended before the frame completed
|
|
159
|
+
* stream ended before the frame completed, or (in `Verify` mode) if the
|
|
160
|
+
* content checksum does not match.
|
|
91
161
|
* @returns {Uint8Array}
|
|
92
162
|
*/
|
|
93
163
|
finish() {
|
|
@@ -99,8 +169,15 @@ export class ZstdDecompressStream {
|
|
|
99
169
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
100
170
|
return v1;
|
|
101
171
|
}
|
|
102
|
-
|
|
103
|
-
|
|
172
|
+
/**
|
|
173
|
+
* `checksum` is optional (default `None` — skip the XXH64 pass, matching
|
|
174
|
+
* the one-shot `decompress` default) and applies to the whole stream, so
|
|
175
|
+
* set it here rather than mid-stream: `Verify` validates the content
|
|
176
|
+
* checksum at [`Self::finish`], `EmitOnly` computes it without erroring.
|
|
177
|
+
* @param {ContentChecksum | null} [checksum]
|
|
178
|
+
*/
|
|
179
|
+
constructor(checksum) {
|
|
180
|
+
const ret = wasm.zstddecompressstream_new(isLikeNone(checksum) ? 3 : checksum);
|
|
104
181
|
this.__wbg_ptr = ret;
|
|
105
182
|
ZstdDecompressStreamFinalization.register(this, this.__wbg_ptr, this);
|
|
106
183
|
return this;
|
|
@@ -122,6 +199,34 @@ export class ZstdDecompressStream {
|
|
|
122
199
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
123
200
|
return v2;
|
|
124
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* The content checksum stored in the frame's 4-byte trailer, or
|
|
204
|
+
* `undefined` if the frame carried none. Meaningful after [`Self::finish`].
|
|
205
|
+
* @returns {number | undefined}
|
|
206
|
+
*/
|
|
207
|
+
storedChecksum() {
|
|
208
|
+
const ret = wasm.zstddecompressstream_storedChecksum(this.__wbg_ptr);
|
|
209
|
+
return ret === Number.MAX_SAFE_INTEGER ? undefined : ret;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Open a streaming decompressor primed with a raw zstd dictionary blob
|
|
213
|
+
* (`ZSTD_DCtx_loadDictionary`): `dict` must be the same dictionary the
|
|
214
|
+
* frame was compressed with (e.g. via [`ZstdCompressStream`]'s
|
|
215
|
+
* `withDictionary`). `checksum` behaves as in [`Self::new`]. Throws if the
|
|
216
|
+
* dictionary is malformed.
|
|
217
|
+
* @param {Uint8Array} dict
|
|
218
|
+
* @param {ContentChecksum | null} [checksum]
|
|
219
|
+
* @returns {ZstdDecompressStream}
|
|
220
|
+
*/
|
|
221
|
+
static withDictionary(dict, checksum) {
|
|
222
|
+
const ptr0 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
223
|
+
const len0 = WASM_VECTOR_LEN;
|
|
224
|
+
const ret = wasm.zstddecompressstream_withDictionary(ptr0, len0, isLikeNone(checksum) ? 3 : checksum);
|
|
225
|
+
if (ret[2]) {
|
|
226
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
227
|
+
}
|
|
228
|
+
return ZstdDecompressStream.__wrap(ret[0]);
|
|
229
|
+
}
|
|
125
230
|
}
|
|
126
231
|
if (Symbol.dispose) ZstdDecompressStream.prototype[Symbol.dispose] = ZstdDecompressStream.prototype.free;
|
|
127
232
|
|
|
@@ -131,14 +236,19 @@ if (Symbol.dispose) ZstdDecompressStream.prototype[Symbol.dispose] = ZstdDecompr
|
|
|
131
236
|
* `level` follows the zstd scale: `1..=22` (higher = smaller/slower) and
|
|
132
237
|
* negative levels (`-7..=-1`) for the ultra-fast tier. The returned frame
|
|
133
238
|
* decodes in any compliant zstd decoder, including the native C library.
|
|
239
|
+
*
|
|
240
|
+
* `checksum` is optional (default `false`, matching libzstd's
|
|
241
|
+
* `ZSTD_c_checksumFlag = 0`): pass `true` to append the trailing XXH64 content
|
|
242
|
+
* checksum.
|
|
134
243
|
* @param {Uint8Array} data
|
|
135
244
|
* @param {number} level
|
|
245
|
+
* @param {boolean | null} [checksum]
|
|
136
246
|
* @returns {Uint8Array}
|
|
137
247
|
*/
|
|
138
|
-
export function compress(data, level) {
|
|
248
|
+
export function compress(data, level, checksum) {
|
|
139
249
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
140
250
|
const len0 = WASM_VECTOR_LEN;
|
|
141
|
-
const ret = wasm.compress(ptr0, len0, level);
|
|
251
|
+
const ret = wasm.compress(ptr0, len0, level, isLikeNone(checksum) ? 0xFFFFFF : checksum ? 1 : 0);
|
|
142
252
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
143
253
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
144
254
|
return v2;
|
|
@@ -150,17 +260,21 @@ export function compress(data, level) {
|
|
|
150
260
|
* Mirrors C `ZSTD_compress_usingDict`: the dictionary primes the encoder so
|
|
151
261
|
* small, similar payloads compress far better. The dictionary is the raw
|
|
152
262
|
* zstd dictionary blob (e.g. from `zstd --train`). Throws if it is invalid.
|
|
263
|
+
*
|
|
264
|
+
* `checksum` is optional (default `false`, matching libzstd's
|
|
265
|
+
* `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64 trailer.
|
|
153
266
|
* @param {Uint8Array} data
|
|
154
267
|
* @param {Uint8Array} dict
|
|
155
268
|
* @param {number} level
|
|
269
|
+
* @param {boolean | null} [checksum]
|
|
156
270
|
* @returns {Uint8Array}
|
|
157
271
|
*/
|
|
158
|
-
export function compressUsingDict(data, dict, level) {
|
|
272
|
+
export function compressUsingDict(data, dict, level, checksum) {
|
|
159
273
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
160
274
|
const len0 = WASM_VECTOR_LEN;
|
|
161
275
|
const ptr1 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
162
276
|
const len1 = WASM_VECTOR_LEN;
|
|
163
|
-
const ret = wasm.compressUsingDict(ptr0, len0, ptr1, len1, level);
|
|
277
|
+
const ret = wasm.compressUsingDict(ptr0, len0, ptr1, len1, level, isLikeNone(checksum) ? 0xFFFFFF : checksum ? 1 : 0);
|
|
164
278
|
if (ret[3]) {
|
|
165
279
|
throw takeFromExternrefTable0(ret[2]);
|
|
166
280
|
}
|
|
@@ -172,14 +286,19 @@ export function compressUsingDict(data, dict, level) {
|
|
|
172
286
|
/**
|
|
173
287
|
* Decompress a complete Zstandard frame back into its original bytes.
|
|
174
288
|
*
|
|
175
|
-
* Throws a JavaScript `Error` if the input is not a valid, complete frame
|
|
289
|
+
* Throws a JavaScript `Error` if the input is not a valid, complete frame,
|
|
290
|
+
* or (when `checksum` is `Verify`) if the content checksum does not match.
|
|
291
|
+
* `checksum` is optional (default `None` — skip the XXH64 pass for speed);
|
|
292
|
+
* pass `ContentChecksum.Verify` to validate, or `EmitOnly` to compute without
|
|
293
|
+
* erroring on mismatch.
|
|
176
294
|
* @param {Uint8Array} data
|
|
295
|
+
* @param {ContentChecksum | null} [checksum]
|
|
177
296
|
* @returns {Uint8Array}
|
|
178
297
|
*/
|
|
179
|
-
export function decompress(data) {
|
|
298
|
+
export function decompress(data, checksum) {
|
|
180
299
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
181
300
|
const len0 = WASM_VECTOR_LEN;
|
|
182
|
-
const ret = wasm.decompress(ptr0, len0);
|
|
301
|
+
const ret = wasm.decompress(ptr0, len0, isLikeNone(checksum) ? 3 : checksum);
|
|
183
302
|
if (ret[3]) {
|
|
184
303
|
throw takeFromExternrefTable0(ret[2]);
|
|
185
304
|
}
|
|
@@ -196,14 +315,15 @@ export function decompress(data) {
|
|
|
196
315
|
* dictionary mismatch.
|
|
197
316
|
* @param {Uint8Array} data
|
|
198
317
|
* @param {Uint8Array} dict
|
|
318
|
+
* @param {ContentChecksum | null} [checksum]
|
|
199
319
|
* @returns {Uint8Array}
|
|
200
320
|
*/
|
|
201
|
-
export function decompressUsingDict(data, dict) {
|
|
321
|
+
export function decompressUsingDict(data, dict, checksum) {
|
|
202
322
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
203
323
|
const len0 = WASM_VECTOR_LEN;
|
|
204
324
|
const ptr1 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
205
325
|
const len1 = WASM_VECTOR_LEN;
|
|
206
|
-
const ret = wasm.decompressUsingDict(ptr0, len0, ptr1, len1);
|
|
326
|
+
const ret = wasm.decompressUsingDict(ptr0, len0, ptr1, len1, isLikeNone(checksum) ? 3 : checksum);
|
|
207
327
|
if (ret[3]) {
|
|
208
328
|
throw takeFromExternrefTable0(ret[2]);
|
|
209
329
|
}
|
|
@@ -214,11 +334,11 @@ export function decompressUsingDict(data, dict) {
|
|
|
214
334
|
function __wbg_get_imports() {
|
|
215
335
|
const import0 = {
|
|
216
336
|
__proto__: null,
|
|
217
|
-
|
|
337
|
+
__wbg_Error_9dc85fe1bc224456: function(arg0, arg1) {
|
|
218
338
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
219
339
|
return ret;
|
|
220
340
|
},
|
|
221
|
-
|
|
341
|
+
__wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
|
|
222
342
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
223
343
|
},
|
|
224
344
|
__wbindgen_init_externref_table: function() {
|
|
@@ -261,6 +381,10 @@ function getUint8ArrayMemory0() {
|
|
|
261
381
|
return cachedUint8ArrayMemory0;
|
|
262
382
|
}
|
|
263
383
|
|
|
384
|
+
function isLikeNone(x) {
|
|
385
|
+
return x === undefined || x === null;
|
|
386
|
+
}
|
|
387
|
+
|
|
264
388
|
function passArray8ToWasm0(arg, malloc) {
|
|
265
389
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
266
390
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
Binary file
|
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_zstdcompressstream_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_zstddecompressstream_free: (a: number, b: number) => void;
|
|
6
|
-
export const compress: (a: number, b: number, c: number) => [number, number];
|
|
7
|
-
export const compressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
8
|
-
export const decompress: (a: number, b: number) => [number, number, number, number];
|
|
9
|
-
export const decompressUsingDict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
6
|
+
export const compress: (a: number, b: number, c: number, d: number) => [number, number];
|
|
7
|
+
export const compressUsingDict: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
8
|
+
export const decompress: (a: number, b: number, c: number) => [number, number, number, number];
|
|
9
|
+
export const decompressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
10
10
|
export const zstdcompressstream_finish: (a: number) => [number, number, number, number];
|
|
11
|
-
export const zstdcompressstream_new: (a: number) => number;
|
|
11
|
+
export const zstdcompressstream_new: (a: number, b: number) => number;
|
|
12
12
|
export const zstdcompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
13
|
+
export const zstdcompressstream_withDictionary: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
14
|
+
export const zstddecompressstream_calculatedChecksum: (a: number) => number;
|
|
13
15
|
export const zstddecompressstream_finish: (a: number) => [number, number, number, number];
|
|
14
|
-
export const zstddecompressstream_new: () => number;
|
|
16
|
+
export const zstddecompressstream_new: (a: number) => number;
|
|
15
17
|
export const zstddecompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
18
|
+
export const zstddecompressstream_storedChecksum: (a: number) => number;
|
|
19
|
+
export const zstddecompressstream_withDictionary: (a: number, b: number, c: number) => [number, number, number];
|
|
16
20
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
17
21
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
18
22
|
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|