@structured-world/structured-zstd 0.0.33 → 0.0.35

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 CHANGED
@@ -14,6 +14,18 @@
14
14
  * The codec is initialised lazily on first use; call {@link init} explicitly
15
15
  * to pre-warm it (e.g. before a latency-sensitive path).
16
16
  */
17
+ /**
18
+ * How the decoder treats a frame's optional XXH64 content checksum. Numeric
19
+ * values match the wasm-bindgen `ContentChecksum` enum.
20
+ */
21
+ export declare enum ContentChecksum {
22
+ /** Skip the XXH64 pass entirely (fastest; no verification). */
23
+ None = 0,
24
+ /** Compute the checksum and expose it via accessors; does not error on a mismatch. */
25
+ EmitOnly = 1,
26
+ /** Compute and verify; a mismatch rejects the decode. */
27
+ Verify = 2
28
+ }
17
29
  /**
18
30
  * Incremental streaming decompressor handle. Feed compressed chunks with
19
31
  * {@link DecompressStream.push} and read decompressed output as it becomes
@@ -24,8 +36,22 @@
24
36
  export interface DecompressStream {
25
37
  /** Feed compressed bytes; returns decompressed output available so far. */
26
38
  push(chunk: Uint8Array): Uint8Array;
27
- /** Signal end of input; returns the final bytes. Throws if incomplete. */
39
+ /**
40
+ * Signal end of input; returns the final bytes. Throws if incomplete, or
41
+ * (in {@link ContentChecksum.Verify} mode) if the content checksum is wrong.
42
+ */
28
43
  finish(): Uint8Array;
44
+ /**
45
+ * Content checksum stored in the frame trailer, or `undefined` if none.
46
+ * Meaningful after {@link DecompressStream.finish}.
47
+ */
48
+ storedChecksum(): number | undefined;
49
+ /**
50
+ * XXH64 digest computed over the output (low 32 bits), or `undefined` under
51
+ * {@link ContentChecksum.None} or when the frame carried no checksum. Lets
52
+ * callers verify manually under {@link ContentChecksum.EmitOnly}.
53
+ */
54
+ calculatedChecksum(): number | undefined;
29
55
  /** Release the underlying wasm handle. */
30
56
  free(): void;
31
57
  }
@@ -33,7 +59,8 @@ export interface DecompressStream {
33
59
  * Incremental streaming compressor handle. Feed plaintext chunks with
34
60
  * {@link CompressStream.push} and read complete compressed blocks as the
35
61
  * matcher window fills; call {@link CompressStream.finish} to seal the frame
36
- * (final block + checksum). Peak memory is O(window), not O(input) the frame
62
+ * (final block, plus the 4-byte XXH64 trailer only if the stream was created
63
+ * with `checksum` enabled). Peak memory is O(window), not O(input) — the frame
37
64
  * is emitted block-by-block instead of buffered whole. The frame omits
38
65
  * `Frame_Content_Size` (unknown while streaming) yet decodes in any compliant
39
66
  * zstd decoder. Call {@link CompressStream.free} when done.
@@ -41,7 +68,11 @@ export interface DecompressStream {
41
68
  export interface CompressStream {
42
69
  /** Feed plaintext; returns compressed bytes complete so far (may be empty). */
43
70
  push(chunk: Uint8Array): Uint8Array;
44
- /** Seal the frame; returns the final block + checksum. */
71
+ /**
72
+ * Seal the frame; returns the final block, followed by the 4-byte XXH64
73
+ * content-checksum trailer only when the stream was created with `checksum`
74
+ * enabled (otherwise just the final block, no trailer).
75
+ */
45
76
  finish(): Uint8Array;
46
77
  /** Release the underlying wasm handle. */
47
78
  free(): void;
@@ -55,33 +86,51 @@ export declare function init(): Promise<void>;
55
86
  * Compress `data` into a Zstandard frame at `level` (zstd scale: `1..=22`,
56
87
  * negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). The
57
88
  * frame decodes in any compliant zstd decoder, including the native C library.
89
+ *
90
+ * @param checksum Defaults to `false` (no trailing checksum, matching
91
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64
92
+ * content checksum.
58
93
  */
59
- export declare function compress(data: Uint8Array, level?: number): Promise<Uint8Array>;
94
+ export declare function compress(data: Uint8Array, level?: number, checksum?: boolean): Promise<Uint8Array>;
60
95
  /**
61
96
  * Decompress a complete Zstandard frame. Rejects if the input is not a valid,
62
- * complete frame.
97
+ * complete frame, or — when `checksum` is {@link ContentChecksum.Verify} — if
98
+ * the content checksum does not match. Defaults to
99
+ * {@link ContentChecksum.None} (the XXH64 pass is skipped for speed); pass
100
+ * {@link ContentChecksum.Verify} to validate.
63
101
  */
64
- export declare function decompress(data: Uint8Array): Promise<Uint8Array>;
102
+ export declare function decompress(data: Uint8Array, checksum?: ContentChecksum): Promise<Uint8Array>;
65
103
  /**
66
104
  * Compress `data` against a raw Zstandard `dict` (e.g. from `zstd --train`) at
67
105
  * `level` (defaults to {@link DEFAULT_LEVEL}). Mirrors C
68
106
  * `ZSTD_compress_usingDict` — small, similar payloads compress far better.
69
107
  * Rejects if the dictionary is invalid.
108
+ *
109
+ * @param checksum Defaults to `false` (no trailing checksum, matching
110
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64
111
+ * content checksum.
70
112
  */
71
- export declare function compressUsingDict(data: Uint8Array, dict: Uint8Array, level?: number): Promise<Uint8Array>;
113
+ export declare function compressUsingDict(data: Uint8Array, dict: Uint8Array, level?: number, checksum?: boolean): Promise<Uint8Array>;
72
114
  /**
73
115
  * Decompress a dictionary-encoded frame. `dict` must be the same raw
74
116
  * dictionary used to compress it. Mirrors C `ZSTD_decompress_usingDict`.
75
117
  * Rejects on a malformed frame or dictionary mismatch.
118
+ *
119
+ * @param checksum Defaults to {@link ContentChecksum.None} (skip the XXH64
120
+ * pass); {@link ContentChecksum.Verify} rejects on a checksum mismatch.
76
121
  */
77
- export declare function decompressUsingDict(data: Uint8Array, dict: Uint8Array): Promise<Uint8Array>;
122
+ export declare function decompressUsingDict(data: Uint8Array, dict: Uint8Array, checksum?: ContentChecksum): Promise<Uint8Array>;
78
123
  /**
79
124
  * Create an incremental streaming decompressor. Push compressed chunks and
80
125
  * read decompressed output as it arrives, then `finish()`; `free()` when done.
81
126
  * Unlike the common npm wasm zstd packages, the frame need not be fully
82
127
  * buffered — the decoder window lives on the wasm side across chunks.
128
+ *
129
+ * @param checksum Applies to the whole stream (set at construction). Defaults
130
+ * to {@link ContentChecksum.None}; {@link ContentChecksum.Verify} validates the
131
+ * content checksum at `finish()`.
83
132
  */
84
- export declare function createDecompressStream(): Promise<DecompressStream>;
133
+ export declare function createDecompressStream(checksum?: ContentChecksum): Promise<DecompressStream>;
85
134
  /**
86
135
  * Create an incremental streaming compressor at `level` (zstd scale: `1..=22`,
87
136
  * negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). Push
@@ -90,6 +139,30 @@ export declare function createDecompressStream(): Promise<DecompressStream>;
90
139
  * frame is emitted block-by-block rather than buffered whole — and the result
91
140
  * decodes in any compliant zstd decoder. Symmetric with
92
141
  * {@link createDecompressStream}.
142
+ *
143
+ * @param checksum Defaults to `false` (no trailing checksum, matching
144
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to seal the frame with a
145
+ * trailing XXH64 content checksum.
146
+ */
147
+ export declare function createCompressStream(level?: number, checksum?: boolean): Promise<CompressStream>;
148
+ /**
149
+ * Create an incremental streaming compressor seeded with a raw zstd `dict`
150
+ * (e.g. from `zstd --train`), at `level`. Mirrors `ZSTD_CCtx_loadDictionary` on
151
+ * a streaming context: the dictionary primes the matcher and the first block's
152
+ * entropy, so small / similar payloads compress far better. Decode the produced
153
+ * frames with {@link createDecompressStreamWithDictionary} (same `dict`) or the
154
+ * one-shot {@link decompressUsingDict}. Rejects if the dictionary is invalid.
155
+ *
156
+ * @param checksum Defaults to `false`; pass `true` for a trailing XXH64 checksum.
157
+ */
158
+ export declare function createCompressStreamWithDictionary(dict: Uint8Array, level?: number, checksum?: boolean): Promise<CompressStream>;
159
+ /**
160
+ * Create an incremental streaming decompressor primed with a raw zstd `dict`.
161
+ * `dict` must be the same dictionary the frame was compressed with (e.g. via
162
+ * {@link createCompressStreamWithDictionary}). Mirrors
163
+ * `ZSTD_DCtx_loadDictionary`. Rejects if the dictionary is malformed.
164
+ *
165
+ * @param checksum Applies to the whole stream; see {@link createDecompressStream}.
93
166
  */
94
- export declare function createCompressStream(level?: number): Promise<CompressStream>;
167
+ export declare function createDecompressStreamWithDictionary(dict: Uint8Array, checksum?: ContentChecksum): Promise<DecompressStream>;
95
168
  //# sourceMappingURL=index.d.ts.map
package/index.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AU,EAChB,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,MAAsB,EAC7B,QAAQ,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,QAAQ,CAAC,EAAE,eAAe,GACzB,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,CAAC,EAAE,eAAe,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAG3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,GAAE,MAAsB,EAC7B,QAAQ,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,cAAc,CAAC,CAGzB;AAED;;;;;;;;;GASG;AACH,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,MAAsB,EAC7B,QAAQ,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,cAAc,CAAC,CAGzB;AAED;;;;;;;GAOG;AACH,wBAAsB,oCAAoC,CACxD,IAAI,EAAE,UAAU,EAChB,QAAQ,CAAC,EAAE,eAAe,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAG3B"}
package/index.js CHANGED
@@ -15,6 +15,19 @@
15
15
  * to pre-warm it (e.g. before a latency-sensitive path).
16
16
  */
17
17
  import { simd } from "wasm-feature-detect";
18
+ /**
19
+ * How the decoder treats a frame's optional XXH64 content checksum. Numeric
20
+ * values match the wasm-bindgen `ContentChecksum` enum.
21
+ */
22
+ export var ContentChecksum;
23
+ (function (ContentChecksum) {
24
+ /** Skip the XXH64 pass entirely (fastest; no verification). */
25
+ ContentChecksum[ContentChecksum["None"] = 0] = "None";
26
+ /** Compute the checksum and expose it via accessors; does not error on a mismatch. */
27
+ ContentChecksum[ContentChecksum["EmitOnly"] = 1] = "EmitOnly";
28
+ /** Compute and verify; a mismatch rejects the decode. */
29
+ ContentChecksum[ContentChecksum["Verify"] = 2] = "Verify";
30
+ })(ContentChecksum || (ContentChecksum = {}));
18
31
  /** Default compression level when the caller does not pass one. */
19
32
  const DEFAULT_LEVEL = 3;
20
33
  let loaded;
@@ -64,47 +77,65 @@ export async function init() {
64
77
  * Compress `data` into a Zstandard frame at `level` (zstd scale: `1..=22`,
65
78
  * negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). The
66
79
  * frame decodes in any compliant zstd decoder, including the native C library.
80
+ *
81
+ * @param checksum Defaults to `false` (no trailing checksum, matching
82
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64
83
+ * content checksum.
67
84
  */
68
- export async function compress(data, level = DEFAULT_LEVEL) {
85
+ export async function compress(data, level = DEFAULT_LEVEL, checksum) {
69
86
  loading ??= load();
70
- return (await loading).compress(data, level);
87
+ return (await loading).compress(data, level, checksum);
71
88
  }
72
89
  /**
73
90
  * Decompress a complete Zstandard frame. Rejects if the input is not a valid,
74
- * complete frame.
91
+ * complete frame, or — when `checksum` is {@link ContentChecksum.Verify} — if
92
+ * the content checksum does not match. Defaults to
93
+ * {@link ContentChecksum.None} (the XXH64 pass is skipped for speed); pass
94
+ * {@link ContentChecksum.Verify} to validate.
75
95
  */
76
- export async function decompress(data) {
96
+ export async function decompress(data, checksum) {
77
97
  loading ??= load();
78
- return (await loading).decompress(data);
98
+ return (await loading).decompress(data, checksum);
79
99
  }
80
100
  /**
81
101
  * Compress `data` against a raw Zstandard `dict` (e.g. from `zstd --train`) at
82
102
  * `level` (defaults to {@link DEFAULT_LEVEL}). Mirrors C
83
103
  * `ZSTD_compress_usingDict` — small, similar payloads compress far better.
84
104
  * Rejects if the dictionary is invalid.
105
+ *
106
+ * @param checksum Defaults to `false` (no trailing checksum, matching
107
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64
108
+ * content checksum.
85
109
  */
86
- export async function compressUsingDict(data, dict, level = DEFAULT_LEVEL) {
110
+ export async function compressUsingDict(data, dict, level = DEFAULT_LEVEL, checksum) {
87
111
  loading ??= load();
88
- return (await loading).compressUsingDict(data, dict, level);
112
+ return (await loading).compressUsingDict(data, dict, level, checksum);
89
113
  }
90
114
  /**
91
115
  * Decompress a dictionary-encoded frame. `dict` must be the same raw
92
116
  * dictionary used to compress it. Mirrors C `ZSTD_decompress_usingDict`.
93
117
  * Rejects on a malformed frame or dictionary mismatch.
118
+ *
119
+ * @param checksum Defaults to {@link ContentChecksum.None} (skip the XXH64
120
+ * pass); {@link ContentChecksum.Verify} rejects on a checksum mismatch.
94
121
  */
95
- export async function decompressUsingDict(data, dict) {
122
+ export async function decompressUsingDict(data, dict, checksum) {
96
123
  loading ??= load();
97
- return (await loading).decompressUsingDict(data, dict);
124
+ return (await loading).decompressUsingDict(data, dict, checksum);
98
125
  }
99
126
  /**
100
127
  * Create an incremental streaming decompressor. Push compressed chunks and
101
128
  * read decompressed output as it arrives, then `finish()`; `free()` when done.
102
129
  * Unlike the common npm wasm zstd packages, the frame need not be fully
103
130
  * buffered — the decoder window lives on the wasm side across chunks.
131
+ *
132
+ * @param checksum Applies to the whole stream (set at construction). Defaults
133
+ * to {@link ContentChecksum.None}; {@link ContentChecksum.Verify} validates the
134
+ * content checksum at `finish()`.
104
135
  */
105
- export async function createDecompressStream() {
136
+ export async function createDecompressStream(checksum) {
106
137
  loading ??= load();
107
- return new (await loading).ZstdDecompressStream();
138
+ return new (await loading).ZstdDecompressStream(checksum);
108
139
  }
109
140
  /**
110
141
  * Create an incremental streaming compressor at `level` (zstd scale: `1..=22`,
@@ -114,9 +145,39 @@ export async function createDecompressStream() {
114
145
  * frame is emitted block-by-block rather than buffered whole — and the result
115
146
  * decodes in any compliant zstd decoder. Symmetric with
116
147
  * {@link createDecompressStream}.
148
+ *
149
+ * @param checksum Defaults to `false` (no trailing checksum, matching
150
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to seal the frame with a
151
+ * trailing XXH64 content checksum.
152
+ */
153
+ export async function createCompressStream(level = DEFAULT_LEVEL, checksum) {
154
+ loading ??= load();
155
+ return new (await loading).ZstdCompressStream(level, checksum);
156
+ }
157
+ /**
158
+ * Create an incremental streaming compressor seeded with a raw zstd `dict`
159
+ * (e.g. from `zstd --train`), at `level`. Mirrors `ZSTD_CCtx_loadDictionary` on
160
+ * a streaming context: the dictionary primes the matcher and the first block's
161
+ * entropy, so small / similar payloads compress far better. Decode the produced
162
+ * frames with {@link createDecompressStreamWithDictionary} (same `dict`) or the
163
+ * one-shot {@link decompressUsingDict}. Rejects if the dictionary is invalid.
164
+ *
165
+ * @param checksum Defaults to `false`; pass `true` for a trailing XXH64 checksum.
166
+ */
167
+ export async function createCompressStreamWithDictionary(dict, level = DEFAULT_LEVEL, checksum) {
168
+ loading ??= load();
169
+ return (await loading).ZstdCompressStream.withDictionary(level, dict, checksum);
170
+ }
171
+ /**
172
+ * Create an incremental streaming decompressor primed with a raw zstd `dict`.
173
+ * `dict` must be the same dictionary the frame was compressed with (e.g. via
174
+ * {@link createCompressStreamWithDictionary}). Mirrors
175
+ * `ZSTD_DCtx_loadDictionary`. Rejects if the dictionary is malformed.
176
+ *
177
+ * @param checksum Applies to the whole stream; see {@link createDecompressStream}.
117
178
  */
118
- export async function createCompressStream(level = DEFAULT_LEVEL) {
179
+ export async function createDecompressStreamWithDictionary(dict, checksum) {
119
180
  loading ??= load();
120
- return new (await loading).ZstdCompressStream(level);
181
+ return (await loading).ZstdDecompressStream.withDictionary(dict, checksum);
121
182
  }
122
183
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAmD3C,mEAAmE;AACnE,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,IAAI,MAA2B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AO,CAAC,MAAM,OAAO,CAAC,CAAC,oBAAoB,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7E,CAAC"}
package/index.ts CHANGED
@@ -17,6 +17,19 @@
17
17
 
18
18
  import { simd } from "wasm-feature-detect";
19
19
 
20
+ /**
21
+ * How the decoder treats a frame's optional XXH64 content checksum. Numeric
22
+ * values match the wasm-bindgen `ContentChecksum` enum.
23
+ */
24
+ export enum ContentChecksum {
25
+ /** Skip the XXH64 pass entirely (fastest; no verification). */
26
+ None = 0,
27
+ /** Compute the checksum and expose it via accessors; does not error on a mismatch. */
28
+ EmitOnly = 1,
29
+ /** Compute and verify; a mismatch rejects the decode. */
30
+ Verify = 2,
31
+ }
32
+
20
33
  /** Shape of a wasm-pack `web`-target payload glue module (simd or scalar). */
21
34
  interface Payload {
22
35
  /** Async wasm initialiser. Accepts wasm bytes / a URL, or nothing (browser). */
@@ -24,12 +37,29 @@ interface Payload {
24
37
  // (bytes / URL / Response / Module), and Node's `fs.readFile` returns
25
38
  // `Buffer<ArrayBufferLike>`, wider than the DOM `BufferSource` in the .d.ts.
26
39
  default: (moduleOrPath?: unknown) => Promise<unknown>;
27
- compress: (data: Uint8Array, level: number) => Uint8Array;
28
- decompress: (data: Uint8Array) => Uint8Array;
29
- compressUsingDict: (data: Uint8Array, dict: Uint8Array, level: number) => Uint8Array;
30
- decompressUsingDict: (data: Uint8Array, dict: Uint8Array) => Uint8Array;
31
- ZstdDecompressStream: new () => DecompressStream;
32
- ZstdCompressStream: new (level: number) => CompressStream;
40
+ compress: (data: Uint8Array, level: number, checksum?: boolean) => Uint8Array;
41
+ decompress: (data: Uint8Array, checksum?: ContentChecksum) => Uint8Array;
42
+ compressUsingDict: (
43
+ data: Uint8Array,
44
+ dict: Uint8Array,
45
+ level: number,
46
+ checksum?: boolean,
47
+ ) => Uint8Array;
48
+ decompressUsingDict: (
49
+ data: Uint8Array,
50
+ dict: Uint8Array,
51
+ checksum?: ContentChecksum,
52
+ ) => Uint8Array;
53
+ ZstdDecompressStream: (new (checksum?: ContentChecksum) => DecompressStream) & {
54
+ withDictionary: (dict: Uint8Array, checksum?: ContentChecksum) => DecompressStream;
55
+ };
56
+ ZstdCompressStream: (new (level: number, checksum?: boolean) => CompressStream) & {
57
+ withDictionary: (
58
+ level: number,
59
+ dict: Uint8Array,
60
+ checksum?: boolean,
61
+ ) => CompressStream;
62
+ };
33
63
  }
34
64
 
35
65
  /**
@@ -42,8 +72,22 @@ interface Payload {
42
72
  export interface DecompressStream {
43
73
  /** Feed compressed bytes; returns decompressed output available so far. */
44
74
  push(chunk: Uint8Array): Uint8Array;
45
- /** Signal end of input; returns the final bytes. Throws if incomplete. */
75
+ /**
76
+ * Signal end of input; returns the final bytes. Throws if incomplete, or
77
+ * (in {@link ContentChecksum.Verify} mode) if the content checksum is wrong.
78
+ */
46
79
  finish(): Uint8Array;
80
+ /**
81
+ * Content checksum stored in the frame trailer, or `undefined` if none.
82
+ * Meaningful after {@link DecompressStream.finish}.
83
+ */
84
+ storedChecksum(): number | undefined;
85
+ /**
86
+ * XXH64 digest computed over the output (low 32 bits), or `undefined` under
87
+ * {@link ContentChecksum.None} or when the frame carried no checksum. Lets
88
+ * callers verify manually under {@link ContentChecksum.EmitOnly}.
89
+ */
90
+ calculatedChecksum(): number | undefined;
47
91
  /** Release the underlying wasm handle. */
48
92
  free(): void;
49
93
  }
@@ -52,7 +96,8 @@ export interface DecompressStream {
52
96
  * Incremental streaming compressor handle. Feed plaintext chunks with
53
97
  * {@link CompressStream.push} and read complete compressed blocks as the
54
98
  * matcher window fills; call {@link CompressStream.finish} to seal the frame
55
- * (final block + checksum). Peak memory is O(window), not O(input) the frame
99
+ * (final block, plus the 4-byte XXH64 trailer only if the stream was created
100
+ * with `checksum` enabled). Peak memory is O(window), not O(input) — the frame
56
101
  * is emitted block-by-block instead of buffered whole. The frame omits
57
102
  * `Frame_Content_Size` (unknown while streaming) yet decodes in any compliant
58
103
  * zstd decoder. Call {@link CompressStream.free} when done.
@@ -60,7 +105,11 @@ export interface DecompressStream {
60
105
  export interface CompressStream {
61
106
  /** Feed plaintext; returns compressed bytes complete so far (may be empty). */
62
107
  push(chunk: Uint8Array): Uint8Array;
63
- /** Seal the frame; returns the final block + checksum. */
108
+ /**
109
+ * Seal the frame; returns the final block, followed by the 4-byte XXH64
110
+ * content-checksum trailer only when the stream was created with `checksum`
111
+ * enabled (otherwise just the final block, no trailer).
112
+ */
64
113
  finish(): Uint8Array;
65
114
  /** Release the underlying wasm handle. */
66
115
  free(): void;
@@ -120,22 +169,33 @@ export async function init(): Promise<void> {
120
169
  * Compress `data` into a Zstandard frame at `level` (zstd scale: `1..=22`,
121
170
  * negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). The
122
171
  * frame decodes in any compliant zstd decoder, including the native C library.
172
+ *
173
+ * @param checksum Defaults to `false` (no trailing checksum, matching
174
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64
175
+ * content checksum.
123
176
  */
124
177
  export async function compress(
125
178
  data: Uint8Array,
126
179
  level: number = DEFAULT_LEVEL,
180
+ checksum?: boolean,
127
181
  ): Promise<Uint8Array> {
128
182
  loading ??= load();
129
- return (await loading).compress(data, level);
183
+ return (await loading).compress(data, level, checksum);
130
184
  }
131
185
 
132
186
  /**
133
187
  * Decompress a complete Zstandard frame. Rejects if the input is not a valid,
134
- * complete frame.
188
+ * complete frame, or — when `checksum` is {@link ContentChecksum.Verify} — if
189
+ * the content checksum does not match. Defaults to
190
+ * {@link ContentChecksum.None} (the XXH64 pass is skipped for speed); pass
191
+ * {@link ContentChecksum.Verify} to validate.
135
192
  */
136
- export async function decompress(data: Uint8Array): Promise<Uint8Array> {
193
+ export async function decompress(
194
+ data: Uint8Array,
195
+ checksum?: ContentChecksum,
196
+ ): Promise<Uint8Array> {
137
197
  loading ??= load();
138
- return (await loading).decompress(data);
198
+ return (await loading).decompress(data, checksum);
139
199
  }
140
200
 
141
201
  /**
@@ -143,27 +203,36 @@ export async function decompress(data: Uint8Array): Promise<Uint8Array> {
143
203
  * `level` (defaults to {@link DEFAULT_LEVEL}). Mirrors C
144
204
  * `ZSTD_compress_usingDict` — small, similar payloads compress far better.
145
205
  * Rejects if the dictionary is invalid.
206
+ *
207
+ * @param checksum Defaults to `false` (no trailing checksum, matching
208
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to append the XXH64
209
+ * content checksum.
146
210
  */
147
211
  export async function compressUsingDict(
148
212
  data: Uint8Array,
149
213
  dict: Uint8Array,
150
214
  level: number = DEFAULT_LEVEL,
215
+ checksum?: boolean,
151
216
  ): Promise<Uint8Array> {
152
217
  loading ??= load();
153
- return (await loading).compressUsingDict(data, dict, level);
218
+ return (await loading).compressUsingDict(data, dict, level, checksum);
154
219
  }
155
220
 
156
221
  /**
157
222
  * Decompress a dictionary-encoded frame. `dict` must be the same raw
158
223
  * dictionary used to compress it. Mirrors C `ZSTD_decompress_usingDict`.
159
224
  * Rejects on a malformed frame or dictionary mismatch.
225
+ *
226
+ * @param checksum Defaults to {@link ContentChecksum.None} (skip the XXH64
227
+ * pass); {@link ContentChecksum.Verify} rejects on a checksum mismatch.
160
228
  */
161
229
  export async function decompressUsingDict(
162
230
  data: Uint8Array,
163
231
  dict: Uint8Array,
232
+ checksum?: ContentChecksum,
164
233
  ): Promise<Uint8Array> {
165
234
  loading ??= load();
166
- return (await loading).decompressUsingDict(data, dict);
235
+ return (await loading).decompressUsingDict(data, dict, checksum);
167
236
  }
168
237
 
169
238
  /**
@@ -171,10 +240,16 @@ export async function decompressUsingDict(
171
240
  * read decompressed output as it arrives, then `finish()`; `free()` when done.
172
241
  * Unlike the common npm wasm zstd packages, the frame need not be fully
173
242
  * buffered — the decoder window lives on the wasm side across chunks.
243
+ *
244
+ * @param checksum Applies to the whole stream (set at construction). Defaults
245
+ * to {@link ContentChecksum.None}; {@link ContentChecksum.Verify} validates the
246
+ * content checksum at `finish()`.
174
247
  */
175
- export async function createDecompressStream(): Promise<DecompressStream> {
248
+ export async function createDecompressStream(
249
+ checksum?: ContentChecksum,
250
+ ): Promise<DecompressStream> {
176
251
  loading ??= load();
177
- return new (await loading).ZstdDecompressStream();
252
+ return new (await loading).ZstdDecompressStream(checksum);
178
253
  }
179
254
 
180
255
  /**
@@ -185,10 +260,50 @@ export async function createDecompressStream(): Promise<DecompressStream> {
185
260
  * frame is emitted block-by-block rather than buffered whole — and the result
186
261
  * decodes in any compliant zstd decoder. Symmetric with
187
262
  * {@link createDecompressStream}.
263
+ *
264
+ * @param checksum Defaults to `false` (no trailing checksum, matching
265
+ * libzstd's `ZSTD_c_checksumFlag = 0`); pass `true` to seal the frame with a
266
+ * trailing XXH64 content checksum.
188
267
  */
189
268
  export async function createCompressStream(
190
269
  level: number = DEFAULT_LEVEL,
270
+ checksum?: boolean,
191
271
  ): Promise<CompressStream> {
192
272
  loading ??= load();
193
- return new (await loading).ZstdCompressStream(level);
273
+ return new (await loading).ZstdCompressStream(level, checksum);
274
+ }
275
+
276
+ /**
277
+ * Create an incremental streaming compressor seeded with a raw zstd `dict`
278
+ * (e.g. from `zstd --train`), at `level`. Mirrors `ZSTD_CCtx_loadDictionary` on
279
+ * a streaming context: the dictionary primes the matcher and the first block's
280
+ * entropy, so small / similar payloads compress far better. Decode the produced
281
+ * frames with {@link createDecompressStreamWithDictionary} (same `dict`) or the
282
+ * one-shot {@link decompressUsingDict}. Rejects if the dictionary is invalid.
283
+ *
284
+ * @param checksum Defaults to `false`; pass `true` for a trailing XXH64 checksum.
285
+ */
286
+ export async function createCompressStreamWithDictionary(
287
+ dict: Uint8Array,
288
+ level: number = DEFAULT_LEVEL,
289
+ checksum?: boolean,
290
+ ): Promise<CompressStream> {
291
+ loading ??= load();
292
+ return (await loading).ZstdCompressStream.withDictionary(level, dict, checksum);
293
+ }
294
+
295
+ /**
296
+ * Create an incremental streaming decompressor primed with a raw zstd `dict`.
297
+ * `dict` must be the same dictionary the frame was compressed with (e.g. via
298
+ * {@link createCompressStreamWithDictionary}). Mirrors
299
+ * `ZSTD_DCtx_loadDictionary`. Rejects if the dictionary is malformed.
300
+ *
301
+ * @param checksum Applies to the whole stream; see {@link createDecompressStream}.
302
+ */
303
+ export async function createDecompressStreamWithDictionary(
304
+ dict: Uint8Array,
305
+ checksum?: ContentChecksum,
306
+ ): Promise<DecompressStream> {
307
+ loading ??= load();
308
+ return (await loading).ZstdDecompressStream.withDictionary(dict, checksum);
194
309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@structured-world/structured-zstd",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "Pure-Rust Zstandard (zstd) codec compiled to WebAssembly — compress and decompress in the browser, Node.js and Deno, with automatic SIMD (simd128) acceleration and a scalar fallback. No native addons, no FFI.",
5
5
  "type": "module",
6
6
  "exports": {