@structured-world/structured-zstd 0.0.30 → 0.0.32
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 +22 -0
- package/index.d.ts +27 -0
- package/index.d.ts.map +1 -1
- package/index.js +13 -0
- package/index.js.map +1 -1
- package/index.ts +35 -0
- package/package.json +1 -1
- package/scalar/structured_zstd_wasm.d.ts +35 -0
- package/scalar/structured_zstd_wasm.js +77 -8
- package/scalar/structured_zstd_wasm_bg.wasm +0 -0
- package/scalar/structured_zstd_wasm_bg.wasm.d.ts +4 -0
- package/simd/structured_zstd_wasm.d.ts +35 -0
- package/simd/structured_zstd_wasm.js +77 -8
- package/simd/structured_zstd_wasm_bg.wasm +0 -0
- package/simd/structured_zstd_wasm_bg.wasm.d.ts +4 -0
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ const out = await compress(payload);
|
|
|
51
51
|
| `decompress` | `(data: Uint8Array) => Promise<Uint8Array>` | Rejects on a malformed/incomplete frame. |
|
|
52
52
|
| `compressUsingDict` | `(data: Uint8Array, dict: Uint8Array, level?: number) => Promise<Uint8Array>` | Dictionary compression (raw zstd dictionary, e.g. `zstd --train`). |
|
|
53
53
|
| `decompressUsingDict` | `(data: Uint8Array, dict: Uint8Array) => Promise<Uint8Array>` | `dict` must match the one used to compress. |
|
|
54
|
+
| `createCompressStream` | `(level?: number) => Promise<CompressStream>` | Incremental streaming encoder (see below); `level` defaults to `3`. |
|
|
54
55
|
| `createDecompressStream` | `() => Promise<DecompressStream>` | Incremental streaming decoder (see below). |
|
|
55
56
|
| `init` | `() => Promise<void>` | Optional pre-warm; idempotent. |
|
|
56
57
|
|
|
@@ -60,6 +61,27 @@ const framed = await compressUsingDict(record, dictionary, 19);
|
|
|
60
61
|
const back = await decompressUsingDict(framed, dictionary);
|
|
61
62
|
```
|
|
62
63
|
|
|
64
|
+
### Streaming compression
|
|
65
|
+
|
|
66
|
+
Compress a large or unbounded source incrementally — push plaintext chunks and
|
|
67
|
+
emit compressed blocks as the matcher window fills, so peak memory is
|
|
68
|
+
O(window), not O(input):
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { createCompressStream } from "@structured-world/structured-zstd";
|
|
72
|
+
|
|
73
|
+
const stream = await createCompressStream(19);
|
|
74
|
+
const out: Uint8Array[] = [];
|
|
75
|
+
for await (const chunk of source) out.push(stream.push(chunk));
|
|
76
|
+
out.push(stream.finish()); // final block + checksum, seals the frame
|
|
77
|
+
stream.free(); // release the wasm handle
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`push(chunk)` returns the compressed bytes complete so far (possibly empty
|
|
81
|
+
while the current block is still filling). The frame omits `Frame_Content_Size`
|
|
82
|
+
(unknown while streaming) yet decodes in any compliant zstd decoder, including
|
|
83
|
+
`decompress` / `createDecompressStream` here and the native C library.
|
|
84
|
+
|
|
63
85
|
### Streaming decompression
|
|
64
86
|
|
|
65
87
|
Decode a frame incrementally without buffering all of it — feed compressed
|
package/index.d.ts
CHANGED
|
@@ -29,6 +29,23 @@ export interface DecompressStream {
|
|
|
29
29
|
/** Release the underlying wasm handle. */
|
|
30
30
|
free(): void;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Incremental streaming compressor handle. Feed plaintext chunks with
|
|
34
|
+
* {@link CompressStream.push} and read complete compressed blocks as the
|
|
35
|
+
* 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
|
|
37
|
+
* is emitted block-by-block instead of buffered whole. The frame omits
|
|
38
|
+
* `Frame_Content_Size` (unknown while streaming) yet decodes in any compliant
|
|
39
|
+
* zstd decoder. Call {@link CompressStream.free} when done.
|
|
40
|
+
*/
|
|
41
|
+
export interface CompressStream {
|
|
42
|
+
/** Feed plaintext; returns compressed bytes complete so far (may be empty). */
|
|
43
|
+
push(chunk: Uint8Array): Uint8Array;
|
|
44
|
+
/** Seal the frame; returns the final block + checksum. */
|
|
45
|
+
finish(): Uint8Array;
|
|
46
|
+
/** Release the underlying wasm handle. */
|
|
47
|
+
free(): void;
|
|
48
|
+
}
|
|
32
49
|
/**
|
|
33
50
|
* Initialise the codec (select + instantiate the best payload) ahead of time.
|
|
34
51
|
* Idempotent and concurrency-safe; resolves once the module is ready.
|
|
@@ -65,4 +82,14 @@ export declare function decompressUsingDict(data: Uint8Array, dict: Uint8Array):
|
|
|
65
82
|
* buffered — the decoder window lives on the wasm side across chunks.
|
|
66
83
|
*/
|
|
67
84
|
export declare function createDecompressStream(): Promise<DecompressStream>;
|
|
85
|
+
/**
|
|
86
|
+
* Create an incremental streaming compressor at `level` (zstd scale: `1..=22`,
|
|
87
|
+
* negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). Push
|
|
88
|
+
* plaintext chunks and read compressed blocks as they complete, then
|
|
89
|
+
* `finish()`; `free()` when done. Peak memory is O(window), not O(input) — the
|
|
90
|
+
* frame is emitted block-by-block rather than buffered whole — and the result
|
|
91
|
+
* decodes in any compliant zstd decoder. Symmetric with
|
|
92
|
+
* {@link createDecompressStream}.
|
|
93
|
+
*/
|
|
94
|
+
export declare function createCompressStream(level?: number): Promise<CompressStream>;
|
|
68
95
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAmBH;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC;IACpC,0EAA0E;IAC1E,MAAM,IAAI,UAAU,CAAC;IACrB,0CAA0C;IAC1C,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,+EAA+E;IAC/E,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC;IACpC,0DAA0D;IAC1D,MAAM,IAAI,UAAU,CAAC;IACrB,0CAA0C;IAC1C,IAAI,IAAI,IAAI,CAAC;CACd;AA2CD;;;GAGG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAG1C;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,MAAsB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAGtE;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,MAAsB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAGxE;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,GAAE,MAAsB,GAC5B,OAAO,CAAC,cAAc,CAAC,CAGzB"}
|
package/index.js
CHANGED
|
@@ -106,4 +106,17 @@ export async function createDecompressStream() {
|
|
|
106
106
|
loading ??= load();
|
|
107
107
|
return new (await loading).ZstdDecompressStream();
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Create an incremental streaming compressor at `level` (zstd scale: `1..=22`,
|
|
111
|
+
* negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). Push
|
|
112
|
+
* plaintext chunks and read compressed blocks as they complete, then
|
|
113
|
+
* `finish()`; `free()` when done. Peak memory is O(window), not O(input) — the
|
|
114
|
+
* frame is emitted block-by-block rather than buffered whole — and the result
|
|
115
|
+
* decodes in any compliant zstd decoder. Symmetric with
|
|
116
|
+
* {@link createDecompressStream}.
|
|
117
|
+
*/
|
|
118
|
+
export async function createCompressStream(level = DEFAULT_LEVEL) {
|
|
119
|
+
loading ??= load();
|
|
120
|
+
return new (await loading).ZstdCompressStream(level);
|
|
121
|
+
}
|
|
109
122
|
//# 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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"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"}
|
package/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ interface Payload {
|
|
|
29
29
|
compressUsingDict: (data: Uint8Array, dict: Uint8Array, level: number) => Uint8Array;
|
|
30
30
|
decompressUsingDict: (data: Uint8Array, dict: Uint8Array) => Uint8Array;
|
|
31
31
|
ZstdDecompressStream: new () => DecompressStream;
|
|
32
|
+
ZstdCompressStream: new (level: number) => CompressStream;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -47,6 +48,24 @@ export interface DecompressStream {
|
|
|
47
48
|
free(): void;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Incremental streaming compressor handle. Feed plaintext chunks with
|
|
53
|
+
* {@link CompressStream.push} and read complete compressed blocks as the
|
|
54
|
+
* 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
|
|
56
|
+
* is emitted block-by-block instead of buffered whole. The frame omits
|
|
57
|
+
* `Frame_Content_Size` (unknown while streaming) yet decodes in any compliant
|
|
58
|
+
* zstd decoder. Call {@link CompressStream.free} when done.
|
|
59
|
+
*/
|
|
60
|
+
export interface CompressStream {
|
|
61
|
+
/** Feed plaintext; returns compressed bytes complete so far (may be empty). */
|
|
62
|
+
push(chunk: Uint8Array): Uint8Array;
|
|
63
|
+
/** Seal the frame; returns the final block + checksum. */
|
|
64
|
+
finish(): Uint8Array;
|
|
65
|
+
/** Release the underlying wasm handle. */
|
|
66
|
+
free(): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
50
69
|
/** Default compression level when the caller does not pass one. */
|
|
51
70
|
const DEFAULT_LEVEL = 3;
|
|
52
71
|
|
|
@@ -157,3 +176,19 @@ export async function createDecompressStream(): Promise<DecompressStream> {
|
|
|
157
176
|
loading ??= load();
|
|
158
177
|
return new (await loading).ZstdDecompressStream();
|
|
159
178
|
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Create an incremental streaming compressor at `level` (zstd scale: `1..=22`,
|
|
182
|
+
* negatives for the ultra-fast tier; defaults to {@link DEFAULT_LEVEL}). Push
|
|
183
|
+
* plaintext chunks and read compressed blocks as they complete, then
|
|
184
|
+
* `finish()`; `free()` when done. Peak memory is O(window), not O(input) — the
|
|
185
|
+
* frame is emitted block-by-block rather than buffered whole — and the result
|
|
186
|
+
* decodes in any compliant zstd decoder. Symmetric with
|
|
187
|
+
* {@link createDecompressStream}.
|
|
188
|
+
*/
|
|
189
|
+
export async function createCompressStream(
|
|
190
|
+
level: number = DEFAULT_LEVEL,
|
|
191
|
+
): Promise<CompressStream> {
|
|
192
|
+
loading ??= load();
|
|
193
|
+
return new (await loading).ZstdCompressStream(level);
|
|
194
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@structured-world/structured-zstd",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
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": {
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Incremental streaming compressor: feed plaintext chunks via
|
|
6
|
+
* [`ZstdCompressStream::push`] and receive complete compressed blocks as the
|
|
7
|
+
* matcher window fills, then [`ZstdCompressStream::finish`] to seal the frame
|
|
8
|
+
* (final block + content checksum). Peak working set is O(window), not
|
|
9
|
+
* O(input) — emitted blocks are flushed to the caller while only the matcher
|
|
10
|
+
* window is retained — so a large payload never has to be buffered whole. The
|
|
11
|
+
* produced frame omits `Frame_Content_Size` (the total is unknown while
|
|
12
|
+
* streaming) and decodes in any compliant zstd decoder. Mirrors
|
|
13
|
+
* [`ZstdDecompressStream`], making the wasm streaming API symmetric.
|
|
14
|
+
*/
|
|
15
|
+
export class ZstdCompressStream {
|
|
16
|
+
free(): void;
|
|
17
|
+
[Symbol.dispose](): void;
|
|
18
|
+
/**
|
|
19
|
+
* Seal the frame; returns the final block plus the content checksum. Throws
|
|
20
|
+
* if the stream was already finished.
|
|
21
|
+
*/
|
|
22
|
+
finish(): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Open a streaming compressor at `level` (zstd scale: `1..=22`, negatives
|
|
25
|
+
* for the ultra-fast tier).
|
|
26
|
+
*/
|
|
27
|
+
constructor(level: number);
|
|
28
|
+
/**
|
|
29
|
+
* Feed more plaintext; returns whatever compressed bytes are now complete
|
|
30
|
+
* (possibly empty while the current block is still filling).
|
|
31
|
+
*/
|
|
32
|
+
push(chunk: Uint8Array): Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
|
|
4
35
|
/**
|
|
5
36
|
* Incremental streaming decompressor: feed compressed chunks via
|
|
6
37
|
* [`ZstdDecompressStream::push`] and receive decompressed bytes as they
|
|
@@ -62,11 +93,15 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
62
93
|
|
|
63
94
|
export interface InitOutput {
|
|
64
95
|
readonly memory: WebAssembly.Memory;
|
|
96
|
+
readonly __wbg_zstdcompressstream_free: (a: number, b: number) => void;
|
|
65
97
|
readonly __wbg_zstddecompressstream_free: (a: number, b: number) => void;
|
|
66
98
|
readonly compress: (a: number, b: number, c: number) => [number, number];
|
|
67
99
|
readonly compressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
68
100
|
readonly decompress: (a: number, b: number) => [number, number, number, number];
|
|
69
101
|
readonly decompressUsingDict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
102
|
+
readonly zstdcompressstream_finish: (a: number) => [number, number, number, number];
|
|
103
|
+
readonly zstdcompressstream_new: (a: number) => number;
|
|
104
|
+
readonly zstdcompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
70
105
|
readonly zstddecompressstream_finish: (a: number) => [number, number, number, number];
|
|
71
106
|
readonly zstddecompressstream_new: () => number;
|
|
72
107
|
readonly zstddecompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
/* @ts-self-types="./structured_zstd_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Incremental streaming compressor: feed plaintext chunks via
|
|
5
|
+
* [`ZstdCompressStream::push`] and receive complete compressed blocks as the
|
|
6
|
+
* matcher window fills, then [`ZstdCompressStream::finish`] to seal the frame
|
|
7
|
+
* (final block + content checksum). Peak working set is O(window), not
|
|
8
|
+
* O(input) — emitted blocks are flushed to the caller while only the matcher
|
|
9
|
+
* window is retained — so a large payload never has to be buffered whole. The
|
|
10
|
+
* produced frame omits `Frame_Content_Size` (the total is unknown while
|
|
11
|
+
* streaming) and decodes in any compliant zstd decoder. Mirrors
|
|
12
|
+
* [`ZstdDecompressStream`], making the wasm streaming API symmetric.
|
|
13
|
+
*/
|
|
14
|
+
export class ZstdCompressStream {
|
|
15
|
+
__destroy_into_raw() {
|
|
16
|
+
const ptr = this.__wbg_ptr;
|
|
17
|
+
this.__wbg_ptr = 0;
|
|
18
|
+
ZstdCompressStreamFinalization.unregister(this);
|
|
19
|
+
return ptr;
|
|
20
|
+
}
|
|
21
|
+
free() {
|
|
22
|
+
const ptr = this.__destroy_into_raw();
|
|
23
|
+
wasm.__wbg_zstdcompressstream_free(ptr, 0);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Seal the frame; returns the final block plus the content checksum. Throws
|
|
27
|
+
* if the stream was already finished.
|
|
28
|
+
* @returns {Uint8Array}
|
|
29
|
+
*/
|
|
30
|
+
finish() {
|
|
31
|
+
const ret = wasm.zstdcompressstream_finish(this.__wbg_ptr);
|
|
32
|
+
if (ret[3]) {
|
|
33
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
34
|
+
}
|
|
35
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
36
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
37
|
+
return v1;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Open a streaming compressor at `level` (zstd scale: `1..=22`, negatives
|
|
41
|
+
* for the ultra-fast tier).
|
|
42
|
+
* @param {number} level
|
|
43
|
+
*/
|
|
44
|
+
constructor(level) {
|
|
45
|
+
const ret = wasm.zstdcompressstream_new(level);
|
|
46
|
+
this.__wbg_ptr = ret;
|
|
47
|
+
ZstdCompressStreamFinalization.register(this, this.__wbg_ptr, this);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Feed more plaintext; returns whatever compressed bytes are now complete
|
|
52
|
+
* (possibly empty while the current block is still filling).
|
|
53
|
+
* @param {Uint8Array} chunk
|
|
54
|
+
* @returns {Uint8Array}
|
|
55
|
+
*/
|
|
56
|
+
push(chunk) {
|
|
57
|
+
const ptr0 = passArray8ToWasm0(chunk, wasm.__wbindgen_malloc);
|
|
58
|
+
const len0 = WASM_VECTOR_LEN;
|
|
59
|
+
const ret = wasm.zstdcompressstream_push(this.__wbg_ptr, ptr0, len0);
|
|
60
|
+
if (ret[3]) {
|
|
61
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
62
|
+
}
|
|
63
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
64
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
65
|
+
return v2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (Symbol.dispose) ZstdCompressStream.prototype[Symbol.dispose] = ZstdCompressStream.prototype.free;
|
|
69
|
+
|
|
3
70
|
/**
|
|
4
71
|
* Incremental streaming decompressor: feed compressed chunks via
|
|
5
72
|
* [`ZstdDecompressStream::push`] and receive decompressed bytes as they
|
|
@@ -34,7 +101,7 @@ export class ZstdDecompressStream {
|
|
|
34
101
|
}
|
|
35
102
|
constructor() {
|
|
36
103
|
const ret = wasm.zstddecompressstream_new();
|
|
37
|
-
this.__wbg_ptr = ret
|
|
104
|
+
this.__wbg_ptr = ret;
|
|
38
105
|
ZstdDecompressStreamFinalization.register(this, this.__wbg_ptr, this);
|
|
39
106
|
return this;
|
|
40
107
|
}
|
|
@@ -144,15 +211,14 @@ export function decompressUsingDict(data, dict) {
|
|
|
144
211
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
145
212
|
return v3;
|
|
146
213
|
}
|
|
147
|
-
|
|
148
214
|
function __wbg_get_imports() {
|
|
149
215
|
const import0 = {
|
|
150
216
|
__proto__: null,
|
|
151
|
-
|
|
217
|
+
__wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
|
|
152
218
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
153
219
|
return ret;
|
|
154
220
|
},
|
|
155
|
-
|
|
221
|
+
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
156
222
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
157
223
|
},
|
|
158
224
|
__wbindgen_init_externref_table: function() {
|
|
@@ -171,9 +237,12 @@ function __wbg_get_imports() {
|
|
|
171
237
|
};
|
|
172
238
|
}
|
|
173
239
|
|
|
240
|
+
const ZstdCompressStreamFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
241
|
+
? { register: () => {}, unregister: () => {} }
|
|
242
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_zstdcompressstream_free(ptr, 1));
|
|
174
243
|
const ZstdDecompressStreamFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
175
244
|
? { register: () => {}, unregister: () => {} }
|
|
176
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_zstddecompressstream_free(ptr
|
|
245
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_zstddecompressstream_free(ptr, 1));
|
|
177
246
|
|
|
178
247
|
function getArrayU8FromWasm0(ptr, len) {
|
|
179
248
|
ptr = ptr >>> 0;
|
|
@@ -181,8 +250,7 @@ function getArrayU8FromWasm0(ptr, len) {
|
|
|
181
250
|
}
|
|
182
251
|
|
|
183
252
|
function getStringFromWasm0(ptr, len) {
|
|
184
|
-
|
|
185
|
-
return decodeText(ptr, len);
|
|
253
|
+
return decodeText(ptr >>> 0, len);
|
|
186
254
|
}
|
|
187
255
|
|
|
188
256
|
let cachedUint8ArrayMemory0 = null;
|
|
@@ -222,8 +290,9 @@ function decodeText(ptr, len) {
|
|
|
222
290
|
|
|
223
291
|
let WASM_VECTOR_LEN = 0;
|
|
224
292
|
|
|
225
|
-
let wasmModule, wasm;
|
|
293
|
+
let wasmModule, wasmInstance, wasm;
|
|
226
294
|
function __wbg_finalize_init(instance, module) {
|
|
295
|
+
wasmInstance = instance;
|
|
227
296
|
wasm = instance.exports;
|
|
228
297
|
wasmModule = module;
|
|
229
298
|
cachedUint8ArrayMemory0 = null;
|
|
Binary file
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_zstdcompressstream_free: (a: number, b: number) => void;
|
|
4
5
|
export const __wbg_zstddecompressstream_free: (a: number, b: number) => void;
|
|
5
6
|
export const compress: (a: number, b: number, c: number) => [number, number];
|
|
6
7
|
export const compressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
7
8
|
export const decompress: (a: number, b: number) => [number, number, number, number];
|
|
8
9
|
export const decompressUsingDict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
10
|
+
export const zstdcompressstream_finish: (a: number) => [number, number, number, number];
|
|
11
|
+
export const zstdcompressstream_new: (a: number) => number;
|
|
12
|
+
export const zstdcompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
9
13
|
export const zstddecompressstream_finish: (a: number) => [number, number, number, number];
|
|
10
14
|
export const zstddecompressstream_new: () => number;
|
|
11
15
|
export const zstddecompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Incremental streaming compressor: feed plaintext chunks via
|
|
6
|
+
* [`ZstdCompressStream::push`] and receive complete compressed blocks as the
|
|
7
|
+
* matcher window fills, then [`ZstdCompressStream::finish`] to seal the frame
|
|
8
|
+
* (final block + content checksum). Peak working set is O(window), not
|
|
9
|
+
* O(input) — emitted blocks are flushed to the caller while only the matcher
|
|
10
|
+
* window is retained — so a large payload never has to be buffered whole. The
|
|
11
|
+
* produced frame omits `Frame_Content_Size` (the total is unknown while
|
|
12
|
+
* streaming) and decodes in any compliant zstd decoder. Mirrors
|
|
13
|
+
* [`ZstdDecompressStream`], making the wasm streaming API symmetric.
|
|
14
|
+
*/
|
|
15
|
+
export class ZstdCompressStream {
|
|
16
|
+
free(): void;
|
|
17
|
+
[Symbol.dispose](): void;
|
|
18
|
+
/**
|
|
19
|
+
* Seal the frame; returns the final block plus the content checksum. Throws
|
|
20
|
+
* if the stream was already finished.
|
|
21
|
+
*/
|
|
22
|
+
finish(): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Open a streaming compressor at `level` (zstd scale: `1..=22`, negatives
|
|
25
|
+
* for the ultra-fast tier).
|
|
26
|
+
*/
|
|
27
|
+
constructor(level: number);
|
|
28
|
+
/**
|
|
29
|
+
* Feed more plaintext; returns whatever compressed bytes are now complete
|
|
30
|
+
* (possibly empty while the current block is still filling).
|
|
31
|
+
*/
|
|
32
|
+
push(chunk: Uint8Array): Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
|
|
4
35
|
/**
|
|
5
36
|
* Incremental streaming decompressor: feed compressed chunks via
|
|
6
37
|
* [`ZstdDecompressStream::push`] and receive decompressed bytes as they
|
|
@@ -62,11 +93,15 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
62
93
|
|
|
63
94
|
export interface InitOutput {
|
|
64
95
|
readonly memory: WebAssembly.Memory;
|
|
96
|
+
readonly __wbg_zstdcompressstream_free: (a: number, b: number) => void;
|
|
65
97
|
readonly __wbg_zstddecompressstream_free: (a: number, b: number) => void;
|
|
66
98
|
readonly compress: (a: number, b: number, c: number) => [number, number];
|
|
67
99
|
readonly compressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
68
100
|
readonly decompress: (a: number, b: number) => [number, number, number, number];
|
|
69
101
|
readonly decompressUsingDict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
102
|
+
readonly zstdcompressstream_finish: (a: number) => [number, number, number, number];
|
|
103
|
+
readonly zstdcompressstream_new: (a: number) => number;
|
|
104
|
+
readonly zstdcompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
70
105
|
readonly zstddecompressstream_finish: (a: number) => [number, number, number, number];
|
|
71
106
|
readonly zstddecompressstream_new: () => number;
|
|
72
107
|
readonly zstddecompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
/* @ts-self-types="./structured_zstd_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Incremental streaming compressor: feed plaintext chunks via
|
|
5
|
+
* [`ZstdCompressStream::push`] and receive complete compressed blocks as the
|
|
6
|
+
* matcher window fills, then [`ZstdCompressStream::finish`] to seal the frame
|
|
7
|
+
* (final block + content checksum). Peak working set is O(window), not
|
|
8
|
+
* O(input) — emitted blocks are flushed to the caller while only the matcher
|
|
9
|
+
* window is retained — so a large payload never has to be buffered whole. The
|
|
10
|
+
* produced frame omits `Frame_Content_Size` (the total is unknown while
|
|
11
|
+
* streaming) and decodes in any compliant zstd decoder. Mirrors
|
|
12
|
+
* [`ZstdDecompressStream`], making the wasm streaming API symmetric.
|
|
13
|
+
*/
|
|
14
|
+
export class ZstdCompressStream {
|
|
15
|
+
__destroy_into_raw() {
|
|
16
|
+
const ptr = this.__wbg_ptr;
|
|
17
|
+
this.__wbg_ptr = 0;
|
|
18
|
+
ZstdCompressStreamFinalization.unregister(this);
|
|
19
|
+
return ptr;
|
|
20
|
+
}
|
|
21
|
+
free() {
|
|
22
|
+
const ptr = this.__destroy_into_raw();
|
|
23
|
+
wasm.__wbg_zstdcompressstream_free(ptr, 0);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Seal the frame; returns the final block plus the content checksum. Throws
|
|
27
|
+
* if the stream was already finished.
|
|
28
|
+
* @returns {Uint8Array}
|
|
29
|
+
*/
|
|
30
|
+
finish() {
|
|
31
|
+
const ret = wasm.zstdcompressstream_finish(this.__wbg_ptr);
|
|
32
|
+
if (ret[3]) {
|
|
33
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
34
|
+
}
|
|
35
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
36
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
37
|
+
return v1;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Open a streaming compressor at `level` (zstd scale: `1..=22`, negatives
|
|
41
|
+
* for the ultra-fast tier).
|
|
42
|
+
* @param {number} level
|
|
43
|
+
*/
|
|
44
|
+
constructor(level) {
|
|
45
|
+
const ret = wasm.zstdcompressstream_new(level);
|
|
46
|
+
this.__wbg_ptr = ret;
|
|
47
|
+
ZstdCompressStreamFinalization.register(this, this.__wbg_ptr, this);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Feed more plaintext; returns whatever compressed bytes are now complete
|
|
52
|
+
* (possibly empty while the current block is still filling).
|
|
53
|
+
* @param {Uint8Array} chunk
|
|
54
|
+
* @returns {Uint8Array}
|
|
55
|
+
*/
|
|
56
|
+
push(chunk) {
|
|
57
|
+
const ptr0 = passArray8ToWasm0(chunk, wasm.__wbindgen_malloc);
|
|
58
|
+
const len0 = WASM_VECTOR_LEN;
|
|
59
|
+
const ret = wasm.zstdcompressstream_push(this.__wbg_ptr, ptr0, len0);
|
|
60
|
+
if (ret[3]) {
|
|
61
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
62
|
+
}
|
|
63
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
64
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
65
|
+
return v2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (Symbol.dispose) ZstdCompressStream.prototype[Symbol.dispose] = ZstdCompressStream.prototype.free;
|
|
69
|
+
|
|
3
70
|
/**
|
|
4
71
|
* Incremental streaming decompressor: feed compressed chunks via
|
|
5
72
|
* [`ZstdDecompressStream::push`] and receive decompressed bytes as they
|
|
@@ -34,7 +101,7 @@ export class ZstdDecompressStream {
|
|
|
34
101
|
}
|
|
35
102
|
constructor() {
|
|
36
103
|
const ret = wasm.zstddecompressstream_new();
|
|
37
|
-
this.__wbg_ptr = ret
|
|
104
|
+
this.__wbg_ptr = ret;
|
|
38
105
|
ZstdDecompressStreamFinalization.register(this, this.__wbg_ptr, this);
|
|
39
106
|
return this;
|
|
40
107
|
}
|
|
@@ -144,15 +211,14 @@ export function decompressUsingDict(data, dict) {
|
|
|
144
211
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
145
212
|
return v3;
|
|
146
213
|
}
|
|
147
|
-
|
|
148
214
|
function __wbg_get_imports() {
|
|
149
215
|
const import0 = {
|
|
150
216
|
__proto__: null,
|
|
151
|
-
|
|
217
|
+
__wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
|
|
152
218
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
153
219
|
return ret;
|
|
154
220
|
},
|
|
155
|
-
|
|
221
|
+
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
156
222
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
157
223
|
},
|
|
158
224
|
__wbindgen_init_externref_table: function() {
|
|
@@ -171,9 +237,12 @@ function __wbg_get_imports() {
|
|
|
171
237
|
};
|
|
172
238
|
}
|
|
173
239
|
|
|
240
|
+
const ZstdCompressStreamFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
241
|
+
? { register: () => {}, unregister: () => {} }
|
|
242
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_zstdcompressstream_free(ptr, 1));
|
|
174
243
|
const ZstdDecompressStreamFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
175
244
|
? { register: () => {}, unregister: () => {} }
|
|
176
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_zstddecompressstream_free(ptr
|
|
245
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_zstddecompressstream_free(ptr, 1));
|
|
177
246
|
|
|
178
247
|
function getArrayU8FromWasm0(ptr, len) {
|
|
179
248
|
ptr = ptr >>> 0;
|
|
@@ -181,8 +250,7 @@ function getArrayU8FromWasm0(ptr, len) {
|
|
|
181
250
|
}
|
|
182
251
|
|
|
183
252
|
function getStringFromWasm0(ptr, len) {
|
|
184
|
-
|
|
185
|
-
return decodeText(ptr, len);
|
|
253
|
+
return decodeText(ptr >>> 0, len);
|
|
186
254
|
}
|
|
187
255
|
|
|
188
256
|
let cachedUint8ArrayMemory0 = null;
|
|
@@ -222,8 +290,9 @@ function decodeText(ptr, len) {
|
|
|
222
290
|
|
|
223
291
|
let WASM_VECTOR_LEN = 0;
|
|
224
292
|
|
|
225
|
-
let wasmModule, wasm;
|
|
293
|
+
let wasmModule, wasmInstance, wasm;
|
|
226
294
|
function __wbg_finalize_init(instance, module) {
|
|
295
|
+
wasmInstance = instance;
|
|
227
296
|
wasm = instance.exports;
|
|
228
297
|
wasmModule = module;
|
|
229
298
|
cachedUint8ArrayMemory0 = null;
|
|
Binary file
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_zstdcompressstream_free: (a: number, b: number) => void;
|
|
4
5
|
export const __wbg_zstddecompressstream_free: (a: number, b: number) => void;
|
|
5
6
|
export const compress: (a: number, b: number, c: number) => [number, number];
|
|
6
7
|
export const compressUsingDict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
7
8
|
export const decompress: (a: number, b: number) => [number, number, number, number];
|
|
8
9
|
export const decompressUsingDict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
10
|
+
export const zstdcompressstream_finish: (a: number) => [number, number, number, number];
|
|
11
|
+
export const zstdcompressstream_new: (a: number) => number;
|
|
12
|
+
export const zstdcompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
9
13
|
export const zstddecompressstream_finish: (a: number) => [number, number, number, number];
|
|
10
14
|
export const zstddecompressstream_new: () => number;
|
|
11
15
|
export const zstddecompressstream_push: (a: number, b: number, c: number) => [number, number, number, number];
|