zstd-wasm-vn 1.0.0 → 1.2.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 +138 -10
- package/bundler/zstd_wasm_vn.d.ts +40 -20
- package/bundler/zstd_wasm_vn_bg.js +134 -20
- package/bundler/zstd_wasm_vn_bg.wasm +0 -0
- package/bundler/zstd_wasm_vn_bg.wasm.d.ts +6 -1
- package/deno/zstd_wasm_vn.d.ts +40 -20
- package/deno/zstd_wasm_vn.js +134 -20
- package/deno/zstd_wasm_vn_bg.wasm +0 -0
- package/deno/zstd_wasm_vn_bg.wasm.d.ts +6 -1
- package/esm/package.json +4 -0
- package/esm/zstd_wasm_vn.d.ts +113 -0
- package/esm/zstd_wasm_vn.js +17 -0
- package/esm/zstd_wasm_vn_bg.js +438 -0
- package/esm/zstd_wasm_vn_bg.wasm +0 -0
- package/esm/zstd_wasm_vn_bg.wasm.d.ts +39 -0
- package/module/zstd_wasm_vn.d.ts +113 -0
- package/module/zstd_wasm_vn.js +442 -0
- package/module/zstd_wasm_vn_bg.wasm +0 -0
- package/module/zstd_wasm_vn_bg.wasm.d.ts +39 -0
- package/no-modules/zstd_wasm_vn.d.ts +168 -0
- package/no-modules/zstd_wasm_vn.js +554 -0
- package/no-modules/zstd_wasm_vn_bg.wasm +0 -0
- package/no-modules/zstd_wasm_vn_bg.wasm.d.ts +39 -0
- package/nodejs/zstd_wasm_vn.d.ts +40 -20
- package/nodejs/zstd_wasm_vn.js +134 -20
- package/nodejs/zstd_wasm_vn_bg.wasm +0 -0
- package/nodejs/zstd_wasm_vn_bg.wasm.d.ts +6 -1
- package/package.json +19 -1
- package/web/zstd_wasm_vn.d.ts +46 -21
- package/web/zstd_wasm_vn.js +134 -20
- package/web/zstd_wasm_vn_bg.wasm +0 -0
- package/web/zstd_wasm_vn_bg.wasm.d.ts +6 -1
package/README.md
CHANGED
|
@@ -1,21 +1,149 @@
|
|
|
1
1
|
# zstd-wasm-vn
|
|
2
2
|
[](https://www.npmjs.com/package/zstd-wasm-vn)
|
|
3
3
|
|
|
4
|
-
##
|
|
4
|
+
## Browser
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
### Bulk (One-shot)
|
|
7
|
+
|
|
8
|
+
For simple, full-buffer compression/decompression.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
import init, { Zstd } from 'zstd-wasm-vn/web';
|
|
12
|
+
|
|
13
|
+
await init();
|
|
14
|
+
|
|
15
|
+
const str = "Compresses data using Zstandard compression";
|
|
16
|
+
|
|
17
|
+
const data = new TextEncoder().encode(str);
|
|
18
|
+
const compressed = Zstd.compress(data, 6);
|
|
19
|
+
const decompressed = Zstd.decompress(compressed);
|
|
20
|
+
|
|
21
|
+
console.log("Original String: ", str);
|
|
22
|
+
console.log("Decompressed String: ", new TextDecoder().decode(decompressed));
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
### Streaming
|
|
26
|
+
|
|
27
|
+
For processing large files read from a drag-and-drop event or an HTTP fetch stream.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import init, { ZstdCompressor, ZstdDecompressor } from 'zstd-wasm-vn/web';
|
|
31
|
+
|
|
32
|
+
await init();
|
|
12
33
|
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
// --- Decompression Stream Example (Browser File Input) ---
|
|
35
|
+
// Assuming you have the full compressed Uint8Array (e.g., loaded from a file input)
|
|
36
|
+
async function streamDecompress(compressedData) {
|
|
37
|
+
const decompressor = new ZstdDecompressor(compressedData);
|
|
38
|
+
const CHUNK_SIZE = 1024 * 128; // Request 128KB chunks
|
|
39
|
+
|
|
40
|
+
const decompressedChunks = [];
|
|
41
|
+
|
|
42
|
+
while (true) {
|
|
43
|
+
// 1. Decompress a chunk
|
|
44
|
+
const chunk = decompressor.decompress_chunk(CHUNK_SIZE);
|
|
45
|
+
|
|
46
|
+
// 2. Stop condition
|
|
47
|
+
if (chunk.length === 0) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 3. Collect the chunk for processing
|
|
52
|
+
decompressedChunks.push(chunk);
|
|
53
|
+
|
|
54
|
+
// Optionally, yield or process the chunk here
|
|
55
|
+
// console.log(`Processed ${chunk.length} bytes`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Combine all chunks into a final array
|
|
59
|
+
const totalLength = decompressedChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
60
|
+
const finalData = new Uint8Array(totalLength);
|
|
61
|
+
let offset = 0;
|
|
62
|
+
for (const chunk of decompressedChunks) {
|
|
63
|
+
finalData.set(chunk, offset);
|
|
64
|
+
offset += chunk.length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`Total decompressed bytes: ${finalData.length}`);
|
|
68
|
+
return finalData;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Example usage with placeholder compressed data
|
|
72
|
+
// const compressedFileBytes = await fetch('data.zst').then(r => r.arrayBuffer()).then(b => new Uint8Array(b));
|
|
73
|
+
// streamDecompress(compressedFileBytes);
|
|
15
74
|
```
|
|
16
75
|
|
|
17
|
-
|
|
76
|
+
## Node.js
|
|
77
|
+
|
|
78
|
+
### Bulk (One-shot)
|
|
79
|
+
|
|
80
|
+
For simple, full-buffer compression/decompression.
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
const { randomBytes } = require('node:crypto');
|
|
84
|
+
const { Zstd } = require('zstd-wasm-vn/nodejs');
|
|
85
|
+
|
|
86
|
+
// Generate 32 bytes of random data
|
|
87
|
+
const data = randomBytes(32);
|
|
88
|
+
|
|
89
|
+
// Compress the entire buffer at level 6
|
|
90
|
+
const compressed = Zstd.compress(data, 6);
|
|
91
|
+
|
|
92
|
+
// Decompress the entire buffer
|
|
93
|
+
const decompressed = Zstd.decompress(compressed);
|
|
94
|
+
|
|
95
|
+
// Verify
|
|
96
|
+
console.log('Match:', data.equals(decompressed));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Streaming
|
|
100
|
+
|
|
101
|
+
For handling large files or continuous network data without loading the entire content into memory.
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const { ZstdCompressor, ZstdDecompressor } = require('zstd-wasm-vn/nodejs');
|
|
105
|
+
const { createReadStream, createWriteStream } = require('node:fs');
|
|
106
|
+
|
|
107
|
+
// --- Compression Stream Example ---
|
|
108
|
+
|
|
109
|
+
// 1. Create a stream compressor instance (level 3)
|
|
110
|
+
const compressor = new ZstdCompressor(3);
|
|
111
|
+
|
|
112
|
+
createReadStream('large_input.txt', { highWaterMark: 64 * 1024 }) // Read 64KB chunks
|
|
113
|
+
.on('data', (chunk) => {
|
|
114
|
+
// 2. Compress each chunk
|
|
115
|
+
compressor.compress_chunk(chunk);
|
|
116
|
+
})
|
|
117
|
+
.on('end', () => {
|
|
118
|
+
// 3. Finalize and get the full compressed output
|
|
119
|
+
const compressedData = compressor.finalize();
|
|
120
|
+
console.log(`Compressed size: ${compressedData.length} bytes`);
|
|
121
|
+
// Write the result to a file (optional)
|
|
122
|
+
// createWriteStream('output.zst').write(compressedData);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// --- Decompression Stream Example ---
|
|
126
|
+
|
|
127
|
+
// Assuming 'compressed_data' is a Buffer containing the Zstd file content
|
|
128
|
+
const compressedData = /* ... load compressed data Buffer here ... */;
|
|
129
|
+
const decompressor = new ZstdDecompressor(compressedData);
|
|
130
|
+
|
|
131
|
+
let totalDecompressedSize = 0;
|
|
132
|
+
const CHUNK_SIZE = 1024 * 64; // Request 64KB uncompressed chunks
|
|
133
|
+
|
|
134
|
+
while (true) {
|
|
135
|
+
// 1. Decompress a chunk
|
|
136
|
+
const chunk = decompressor.decompress_chunk(CHUNK_SIZE);
|
|
137
|
+
|
|
138
|
+
// 2. Stop condition (empty chunk means EOF)
|
|
139
|
+
if (chunk.length === 0) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 3. Process/write the uncompressed chunk
|
|
144
|
+
// createWriteStream('decompressed.txt').write(chunk);
|
|
145
|
+
totalDecompressedSize += chunk.length;
|
|
146
|
+
}
|
|
18
147
|
|
|
19
|
-
|
|
20
|
-
cd pkg && npm publish
|
|
148
|
+
console.log(`Total decompressed size: ${totalDecompressedSize} bytes`);
|
|
21
149
|
```
|
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Compresses data using Zstandard compression
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `data` - Input data to compress
|
|
9
|
+
* * `level` - Compression level (1-22, default 6). Higher = better compression but slower
|
|
10
|
+
*/
|
|
11
|
+
export function compress(data: Uint8Array, level?: number | null): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Compresses data using Zstandard compression with a dictionary
|
|
14
|
+
*
|
|
15
|
+
* # Arguments
|
|
16
|
+
*
|
|
17
|
+
* * `data` - Input data to compress
|
|
18
|
+
* * `dict` - The compression dictionary
|
|
19
|
+
* * `level` - Compression level (1-22, default 6). Higher = better compression but slower
|
|
20
|
+
*/
|
|
21
|
+
export function compress_with_dict(data: Uint8Array, dict: Uint8Array, level?: number | null): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Decompresses Zstandard compressed data
|
|
24
|
+
*
|
|
25
|
+
* # Arguments
|
|
26
|
+
*
|
|
27
|
+
* * `compressed_data` - Zstandard compressed data
|
|
28
|
+
*/
|
|
29
|
+
export function decompress(compressed_data: Uint8Array): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Decompresses Zstandard compressed data using a dictionary
|
|
32
|
+
*
|
|
33
|
+
* # Arguments
|
|
34
|
+
*
|
|
35
|
+
* * `data` - Zstandard compressed data
|
|
36
|
+
* * `dict` - The decompression dictionary (must match the compression dictionary)
|
|
37
|
+
*/
|
|
38
|
+
export function decompress_with_dict(data: Uint8Array, dict: Uint8Array): Uint8Array;
|
|
3
39
|
/**
|
|
4
40
|
* ZSTD compression and decompression for WebAssembly
|
|
5
41
|
*/
|
|
@@ -7,23 +43,10 @@ export class Zstd {
|
|
|
7
43
|
private constructor();
|
|
8
44
|
free(): void;
|
|
9
45
|
[Symbol.dispose](): void;
|
|
10
|
-
/**
|
|
11
|
-
* Compresses data using Zstandard compression
|
|
12
|
-
*
|
|
13
|
-
* # Arguments
|
|
14
|
-
*
|
|
15
|
-
* * `data` - Input data to compress
|
|
16
|
-
* * `level` - Compression level (1-22, default 3). Higher = better compression but slower
|
|
17
|
-
*/
|
|
18
46
|
static compress(data: Uint8Array, level?: number | null): Uint8Array;
|
|
19
|
-
|
|
20
|
-
* Decompresses Zstandard compressed data
|
|
21
|
-
*
|
|
22
|
-
* # Arguments
|
|
23
|
-
*
|
|
24
|
-
* * `compressed_data` - Zstandard compressed data
|
|
25
|
-
*/
|
|
47
|
+
static compress_with_dict(data: Uint8Array, dict: Uint8Array, level?: number | null): Uint8Array;
|
|
26
48
|
static decompress(compressed_data: Uint8Array): Uint8Array;
|
|
49
|
+
static decompress_with_dict(compressed_data: Uint8Array, dict: Uint8Array): Uint8Array;
|
|
27
50
|
/**
|
|
28
51
|
* Returns the recommended default compression level
|
|
29
52
|
*/
|
|
@@ -50,6 +73,7 @@ export class Zstd {
|
|
|
50
73
|
static spaceSavings(original_size: number, compressed_size: number): number;
|
|
51
74
|
}
|
|
52
75
|
/**
|
|
76
|
+
* ==================================== [Streaming] ====================================
|
|
53
77
|
* Streaming compression for large data
|
|
54
78
|
*/
|
|
55
79
|
export class ZstdCompressor {
|
|
@@ -67,10 +91,6 @@ export class ZstdCompressor {
|
|
|
67
91
|
* Finalizes compression and returns the compressed data
|
|
68
92
|
*/
|
|
69
93
|
finalize(): Uint8Array;
|
|
70
|
-
/**
|
|
71
|
-
* Gets the current compression level
|
|
72
|
-
*/
|
|
73
|
-
readonly level: number;
|
|
74
94
|
}
|
|
75
95
|
/**
|
|
76
96
|
* Streaming decompression for large data
|
|
@@ -87,7 +107,7 @@ export class ZstdDecompressor {
|
|
|
87
107
|
*/
|
|
88
108
|
decompress_chunk(max_output_size: number): Uint8Array;
|
|
89
109
|
/**
|
|
90
|
-
* Decompresses all remaining data
|
|
110
|
+
* Decompresses all remaining data and consumes the decoder.
|
|
91
111
|
*/
|
|
92
112
|
finalize(): Uint8Array;
|
|
93
113
|
}
|
|
@@ -57,6 +57,101 @@ function getArrayU8FromWasm0(ptr, len) {
|
|
|
57
57
|
ptr = ptr >>> 0;
|
|
58
58
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Compresses data using Zstandard compression
|
|
62
|
+
*
|
|
63
|
+
* # Arguments
|
|
64
|
+
*
|
|
65
|
+
* * `data` - Input data to compress
|
|
66
|
+
* * `level` - Compression level (1-22, default 6). Higher = better compression but slower
|
|
67
|
+
* @param {Uint8Array} data
|
|
68
|
+
* @param {number | null} [level]
|
|
69
|
+
* @returns {Uint8Array}
|
|
70
|
+
*/
|
|
71
|
+
export function compress(data, level) {
|
|
72
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
73
|
+
const len0 = WASM_VECTOR_LEN;
|
|
74
|
+
const ret = wasm.compress(ptr0, len0, isLikeNone(level) ? 0x100000001 : (level) >> 0);
|
|
75
|
+
if (ret[3]) {
|
|
76
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
77
|
+
}
|
|
78
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
79
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
80
|
+
return v2;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Compresses data using Zstandard compression with a dictionary
|
|
85
|
+
*
|
|
86
|
+
* # Arguments
|
|
87
|
+
*
|
|
88
|
+
* * `data` - Input data to compress
|
|
89
|
+
* * `dict` - The compression dictionary
|
|
90
|
+
* * `level` - Compression level (1-22, default 6). Higher = better compression but slower
|
|
91
|
+
* @param {Uint8Array} data
|
|
92
|
+
* @param {Uint8Array} dict
|
|
93
|
+
* @param {number | null} [level]
|
|
94
|
+
* @returns {Uint8Array}
|
|
95
|
+
*/
|
|
96
|
+
export function compress_with_dict(data, dict, level) {
|
|
97
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
98
|
+
const len0 = WASM_VECTOR_LEN;
|
|
99
|
+
const ptr1 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
100
|
+
const len1 = WASM_VECTOR_LEN;
|
|
101
|
+
const ret = wasm.compress_with_dict(ptr0, len0, ptr1, len1, isLikeNone(level) ? 0x100000001 : (level) >> 0);
|
|
102
|
+
if (ret[3]) {
|
|
103
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
104
|
+
}
|
|
105
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
106
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
107
|
+
return v3;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Decompresses Zstandard compressed data
|
|
112
|
+
*
|
|
113
|
+
* # Arguments
|
|
114
|
+
*
|
|
115
|
+
* * `compressed_data` - Zstandard compressed data
|
|
116
|
+
* @param {Uint8Array} compressed_data
|
|
117
|
+
* @returns {Uint8Array}
|
|
118
|
+
*/
|
|
119
|
+
export function decompress(compressed_data) {
|
|
120
|
+
const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
|
|
121
|
+
const len0 = WASM_VECTOR_LEN;
|
|
122
|
+
const ret = wasm.decompress(ptr0, len0);
|
|
123
|
+
if (ret[3]) {
|
|
124
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
125
|
+
}
|
|
126
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
127
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
128
|
+
return v2;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Decompresses Zstandard compressed data using a dictionary
|
|
133
|
+
*
|
|
134
|
+
* # Arguments
|
|
135
|
+
*
|
|
136
|
+
* * `data` - Zstandard compressed data
|
|
137
|
+
* * `dict` - The decompression dictionary (must match the compression dictionary)
|
|
138
|
+
* @param {Uint8Array} data
|
|
139
|
+
* @param {Uint8Array} dict
|
|
140
|
+
* @returns {Uint8Array}
|
|
141
|
+
*/
|
|
142
|
+
export function decompress_with_dict(data, dict) {
|
|
143
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
144
|
+
const len0 = WASM_VECTOR_LEN;
|
|
145
|
+
const ptr1 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
146
|
+
const len1 = WASM_VECTOR_LEN;
|
|
147
|
+
const ret = wasm.decompress_with_dict(ptr0, len0, ptr1, len1);
|
|
148
|
+
if (ret[3]) {
|
|
149
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
150
|
+
}
|
|
151
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
152
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
153
|
+
return v3;
|
|
154
|
+
}
|
|
60
155
|
|
|
61
156
|
const ZstdFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
62
157
|
? { register: () => {}, unregister: () => {} }
|
|
@@ -78,12 +173,6 @@ export class Zstd {
|
|
|
78
173
|
wasm.__wbg_zstd_free(ptr, 0);
|
|
79
174
|
}
|
|
80
175
|
/**
|
|
81
|
-
* Compresses data using Zstandard compression
|
|
82
|
-
*
|
|
83
|
-
* # Arguments
|
|
84
|
-
*
|
|
85
|
-
* * `data` - Input data to compress
|
|
86
|
-
* * `level` - Compression level (1-22, default 3). Higher = better compression but slower
|
|
87
176
|
* @param {Uint8Array} data
|
|
88
177
|
* @param {number | null} [level]
|
|
89
178
|
* @returns {Uint8Array}
|
|
@@ -100,11 +189,25 @@ export class Zstd {
|
|
|
100
189
|
return v2;
|
|
101
190
|
}
|
|
102
191
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
|
|
192
|
+
* @param {Uint8Array} data
|
|
193
|
+
* @param {Uint8Array} dict
|
|
194
|
+
* @param {number | null} [level]
|
|
195
|
+
* @returns {Uint8Array}
|
|
196
|
+
*/
|
|
197
|
+
static compress_with_dict(data, dict, level) {
|
|
198
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
199
|
+
const len0 = WASM_VECTOR_LEN;
|
|
200
|
+
const ptr1 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
201
|
+
const len1 = WASM_VECTOR_LEN;
|
|
202
|
+
const ret = wasm.zstd_compress_with_dict(ptr0, len0, ptr1, len1, isLikeNone(level) ? 0x100000001 : (level) >> 0);
|
|
203
|
+
if (ret[3]) {
|
|
204
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
205
|
+
}
|
|
206
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
207
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
208
|
+
return v3;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
108
211
|
* @param {Uint8Array} compressed_data
|
|
109
212
|
* @returns {Uint8Array}
|
|
110
213
|
*/
|
|
@@ -119,6 +222,24 @@ export class Zstd {
|
|
|
119
222
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
120
223
|
return v2;
|
|
121
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* @param {Uint8Array} compressed_data
|
|
227
|
+
* @param {Uint8Array} dict
|
|
228
|
+
* @returns {Uint8Array}
|
|
229
|
+
*/
|
|
230
|
+
static decompress_with_dict(compressed_data, dict) {
|
|
231
|
+
const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
|
|
232
|
+
const len0 = WASM_VECTOR_LEN;
|
|
233
|
+
const ptr1 = passArray8ToWasm0(dict, wasm.__wbindgen_malloc);
|
|
234
|
+
const len1 = WASM_VECTOR_LEN;
|
|
235
|
+
const ret = wasm.zstd_decompress_with_dict(ptr0, len0, ptr1, len1);
|
|
236
|
+
if (ret[3]) {
|
|
237
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
238
|
+
}
|
|
239
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
240
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
241
|
+
return v3;
|
|
242
|
+
}
|
|
122
243
|
/**
|
|
123
244
|
* Returns the recommended default compression level
|
|
124
245
|
* @returns {number}
|
|
@@ -179,6 +300,7 @@ const ZstdCompressorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
179
300
|
? { register: () => {}, unregister: () => {} }
|
|
180
301
|
: new FinalizationRegistry(ptr => wasm.__wbg_zstdcompressor_free(ptr >>> 0, 1));
|
|
181
302
|
/**
|
|
303
|
+
* ==================================== [Streaming] ====================================
|
|
182
304
|
* Streaming compression for large data
|
|
183
305
|
*/
|
|
184
306
|
export class ZstdCompressor {
|
|
@@ -232,14 +354,6 @@ export class ZstdCompressor {
|
|
|
232
354
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
233
355
|
return v1;
|
|
234
356
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Gets the current compression level
|
|
237
|
-
* @returns {number}
|
|
238
|
-
*/
|
|
239
|
-
get level() {
|
|
240
|
-
const ret = wasm.zstdcompressor_level(this.__wbg_ptr);
|
|
241
|
-
return ret;
|
|
242
|
-
}
|
|
243
357
|
}
|
|
244
358
|
if (Symbol.dispose) ZstdCompressor.prototype[Symbol.dispose] = ZstdCompressor.prototype.free;
|
|
245
359
|
|
|
@@ -292,7 +406,7 @@ export class ZstdDecompressor {
|
|
|
292
406
|
return v1;
|
|
293
407
|
}
|
|
294
408
|
/**
|
|
295
|
-
* Decompresses all remaining data
|
|
409
|
+
* Decompresses all remaining data and consumes the decoder.
|
|
296
410
|
* @returns {Uint8Array}
|
|
297
411
|
*/
|
|
298
412
|
finalize() {
|
|
Binary file
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const compress: (a: number, b: number, c: number) => [number, number, number, number];
|
|
5
|
+
export const compress_with_dict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
6
|
+
export const decompress: (a: number, b: number) => [number, number, number, number];
|
|
7
|
+
export const decompress_with_dict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
4
8
|
export const __wbg_zstd_free: (a: number, b: number) => void;
|
|
5
9
|
export const zstd_compress: (a: number, b: number, c: number) => [number, number, number, number];
|
|
10
|
+
export const zstd_compress_with_dict: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
6
11
|
export const zstd_decompress: (a: number, b: number) => [number, number, number, number];
|
|
12
|
+
export const zstd_decompress_with_dict: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
7
13
|
export const zstd_defaultCompressionLevel: () => number;
|
|
8
14
|
export const zstd_minCompressionLevel: () => number;
|
|
9
15
|
export const zstd_maxCompressionLevel: () => number;
|
|
@@ -14,7 +20,6 @@ export const __wbg_zstdcompressor_free: (a: number, b: number) => void;
|
|
|
14
20
|
export const zstdcompressor_new: (a: number) => [number, number, number];
|
|
15
21
|
export const zstdcompressor_compress_chunk: (a: number, b: number, c: number) => [number, number];
|
|
16
22
|
export const zstdcompressor_finalize: (a: number) => [number, number, number, number];
|
|
17
|
-
export const zstdcompressor_level: (a: number) => number;
|
|
18
23
|
export const __wbg_zstddecompressor_free: (a: number, b: number) => void;
|
|
19
24
|
export const zstddecompressor_new: (a: number, b: number) => [number, number, number];
|
|
20
25
|
export const zstddecompressor_decompress_chunk: (a: number, b: number) => [number, number, number, number];
|
package/deno/zstd_wasm_vn.d.ts
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Compresses data using Zstandard compression
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `data` - Input data to compress
|
|
9
|
+
* * `level` - Compression level (1-22, default 6). Higher = better compression but slower
|
|
10
|
+
*/
|
|
11
|
+
export function compress(data: Uint8Array, level?: number | null): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Compresses data using Zstandard compression with a dictionary
|
|
14
|
+
*
|
|
15
|
+
* # Arguments
|
|
16
|
+
*
|
|
17
|
+
* * `data` - Input data to compress
|
|
18
|
+
* * `dict` - The compression dictionary
|
|
19
|
+
* * `level` - Compression level (1-22, default 6). Higher = better compression but slower
|
|
20
|
+
*/
|
|
21
|
+
export function compress_with_dict(data: Uint8Array, dict: Uint8Array, level?: number | null): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Decompresses Zstandard compressed data
|
|
24
|
+
*
|
|
25
|
+
* # Arguments
|
|
26
|
+
*
|
|
27
|
+
* * `compressed_data` - Zstandard compressed data
|
|
28
|
+
*/
|
|
29
|
+
export function decompress(compressed_data: Uint8Array): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Decompresses Zstandard compressed data using a dictionary
|
|
32
|
+
*
|
|
33
|
+
* # Arguments
|
|
34
|
+
*
|
|
35
|
+
* * `data` - Zstandard compressed data
|
|
36
|
+
* * `dict` - The decompression dictionary (must match the compression dictionary)
|
|
37
|
+
*/
|
|
38
|
+
export function decompress_with_dict(data: Uint8Array, dict: Uint8Array): Uint8Array;
|
|
3
39
|
/**
|
|
4
40
|
* ZSTD compression and decompression for WebAssembly
|
|
5
41
|
*/
|
|
@@ -7,23 +43,10 @@ export class Zstd {
|
|
|
7
43
|
private constructor();
|
|
8
44
|
free(): void;
|
|
9
45
|
[Symbol.dispose](): void;
|
|
10
|
-
/**
|
|
11
|
-
* Compresses data using Zstandard compression
|
|
12
|
-
*
|
|
13
|
-
* # Arguments
|
|
14
|
-
*
|
|
15
|
-
* * `data` - Input data to compress
|
|
16
|
-
* * `level` - Compression level (1-22, default 3). Higher = better compression but slower
|
|
17
|
-
*/
|
|
18
46
|
static compress(data: Uint8Array, level?: number | null): Uint8Array;
|
|
19
|
-
|
|
20
|
-
* Decompresses Zstandard compressed data
|
|
21
|
-
*
|
|
22
|
-
* # Arguments
|
|
23
|
-
*
|
|
24
|
-
* * `compressed_data` - Zstandard compressed data
|
|
25
|
-
*/
|
|
47
|
+
static compress_with_dict(data: Uint8Array, dict: Uint8Array, level?: number | null): Uint8Array;
|
|
26
48
|
static decompress(compressed_data: Uint8Array): Uint8Array;
|
|
49
|
+
static decompress_with_dict(compressed_data: Uint8Array, dict: Uint8Array): Uint8Array;
|
|
27
50
|
/**
|
|
28
51
|
* Returns the recommended default compression level
|
|
29
52
|
*/
|
|
@@ -50,6 +73,7 @@ export class Zstd {
|
|
|
50
73
|
static spaceSavings(original_size: number, compressed_size: number): number;
|
|
51
74
|
}
|
|
52
75
|
/**
|
|
76
|
+
* ==================================== [Streaming] ====================================
|
|
53
77
|
* Streaming compression for large data
|
|
54
78
|
*/
|
|
55
79
|
export class ZstdCompressor {
|
|
@@ -67,10 +91,6 @@ export class ZstdCompressor {
|
|
|
67
91
|
* Finalizes compression and returns the compressed data
|
|
68
92
|
*/
|
|
69
93
|
finalize(): Uint8Array;
|
|
70
|
-
/**
|
|
71
|
-
* Gets the current compression level
|
|
72
|
-
*/
|
|
73
|
-
readonly level: number;
|
|
74
94
|
}
|
|
75
95
|
/**
|
|
76
96
|
* Streaming decompression for large data
|
|
@@ -87,7 +107,7 @@ export class ZstdDecompressor {
|
|
|
87
107
|
*/
|
|
88
108
|
decompress_chunk(max_output_size: number): Uint8Array;
|
|
89
109
|
/**
|
|
90
|
-
* Decompresses all remaining data
|
|
110
|
+
* Decompresses all remaining data and consumes the decoder.
|
|
91
111
|
*/
|
|
92
112
|
finalize(): Uint8Array;
|
|
93
113
|
}
|