@small-ltsc/sdk 0.2.6 → 0.2.11

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Helper to dynamically import the wasm-pack generated module.
3
+ * Uses eval to completely bypass TypeScript module resolution.
4
+ */
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ export async function importWasmModule() {
7
+ // Using eval to bypass TypeScript's static module resolution
8
+ // The actual module is generated by wasm-pack at build time
9
+ // eslint-disable-next-line no-eval
10
+ return eval('import("./pkg/small_ltsc_core.js")');
11
+ }
12
+ //# sourceMappingURL=import-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-helper.js","sourceRoot":"","sources":["../../../src/wasm/import-helper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,6DAA6D;IAC7D,4DAA4D;IAC5D,mCAAmC;IACnC,OAAO,IAAI,CAAC,oCAAoC,CAAC,CAAC;AACpD,CAAC"}
@@ -1,84 +1,23 @@
1
1
  /**
2
- * WASM module loader with cross-platform support.
2
+ * WASM module loader - wraps wasm-pack generated web target output.
3
3
  *
4
- * Handles loading the WebAssembly module in browser, Node.js, and Deno environments.
4
+ * This loader uses the wasm-bindgen generated init() function which properly
5
+ * handles WASM loading across browser and Node.js environments.
5
6
  */
6
- // Global state
7
- let wasmModule = null;
8
- let wasmInstance = null;
7
+ // Track initialization state
8
+ let initialized = false;
9
9
  let initPromise = null;
10
+ let wasmExports = null;
10
11
  /**
11
12
  * Detect the current runtime environment.
12
13
  */
13
14
  function detectEnvironment() {
14
- if (typeof Deno !== 'undefined') {
15
- return 'deno';
16
- }
17
- if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
18
- return 'browser';
19
- }
20
15
  if (typeof process !== 'undefined' &&
21
16
  process.versions &&
22
17
  process.versions.node) {
23
18
  return 'node';
24
19
  }
25
- return 'browser'; // Default fallback
26
- }
27
- /**
28
- * Load WASM bytes based on environment.
29
- */
30
- async function loadWasmBytes() {
31
- const env = detectEnvironment();
32
- // Get the path to the WASM file
33
- // This will be populated during the build process
34
- const wasmPath = new URL('./small_ltsc_core_bg.wasm', import.meta.url);
35
- switch (env) {
36
- case 'browser': {
37
- const response = await fetch(wasmPath);
38
- if (!response.ok) {
39
- throw new Error(`Failed to fetch WASM: ${response.statusText}`);
40
- }
41
- return response.arrayBuffer();
42
- }
43
- case 'node': {
44
- // Dynamic import for Node.js fs module
45
- const { readFile } = await import('node:fs/promises');
46
- const { fileURLToPath } = await import('node:url');
47
- const path = fileURLToPath(wasmPath);
48
- const buffer = await readFile(path);
49
- return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
50
- }
51
- case 'deno': {
52
- // Deno can use fetch for local files
53
- const response = await fetch(wasmPath);
54
- if (!response.ok) {
55
- throw new Error(`Failed to fetch WASM: ${response.statusText}`);
56
- }
57
- return response.arrayBuffer();
58
- }
59
- default:
60
- throw new Error(`Unsupported environment: ${env}`);
61
- }
62
- }
63
- /**
64
- * Create import object for WASM instantiation.
65
- */
66
- function createImports() {
67
- return {
68
- env: {
69
- // Logging functions for debugging
70
- console_log: (ptr, len) => {
71
- // In production, this would decode the string from memory
72
- console.log('[WASM]', ptr, len);
73
- },
74
- },
75
- wbg: {
76
- // wasm-bindgen imports will be added here during build
77
- __wbindgen_throw: (ptr, len) => {
78
- throw new Error(`WASM error at ${ptr} len ${len}`);
79
- },
80
- },
81
- };
20
+ return 'browser';
82
21
  }
83
22
  /**
84
23
  * Initialize the WASM module.
@@ -89,42 +28,69 @@ function createImports() {
89
28
  * @throws Error if WASM loading fails
90
29
  */
91
30
  export async function initWasm() {
92
- if (wasmInstance) {
93
- return; // Already initialized
31
+ if (initialized) {
32
+ return;
94
33
  }
95
34
  if (initPromise) {
96
- return initPromise; // Initialization in progress
35
+ return initPromise;
97
36
  }
98
37
  initPromise = (async () => {
99
38
  try {
100
- const wasmBytes = await loadWasmBytes();
101
- wasmModule = await WebAssembly.compile(wasmBytes);
102
- const imports = createImports();
103
- const instance = await WebAssembly.instantiate(wasmModule, imports);
104
- wasmInstance = instance.exports;
39
+ const env = detectEnvironment();
40
+ // Dynamically import the wasm-pack generated module
41
+ const { importWasmModule } = await import('./import-helper.js');
42
+ const wasmModule = await importWasmModule();
43
+ if (env === 'node') {
44
+ // In Node.js, we need to provide the WASM file path/bytes
45
+ const { readFile } = await import('node:fs/promises');
46
+ const { fileURLToPath } = await import('node:url');
47
+ const wasmPath = new URL('./pkg/small_ltsc_core_bg.wasm', import.meta.url);
48
+ const path = fileURLToPath(wasmPath);
49
+ const buffer = await readFile(path);
50
+ await wasmModule.default(buffer);
51
+ }
52
+ else {
53
+ // In browser, wasm-pack's init() handles loading via import.meta.url
54
+ await wasmModule.default();
55
+ }
56
+ // Store exports for getWasm()
57
+ wasmExports = {
58
+ compress: wasmModule.compress,
59
+ decompress: wasmModule.decompress,
60
+ discover_patterns: wasmModule.discover_patterns,
61
+ version: wasmModule.version,
62
+ StreamingCompressor: wasmModule.StreamingCompressor,
63
+ };
64
+ initialized = true;
105
65
  }
106
66
  catch (error) {
107
- initPromise = null; // Allow retry on failure
67
+ initPromise = null;
108
68
  throw error;
109
69
  }
110
70
  })();
111
71
  return initPromise;
112
72
  }
113
73
  /**
114
- * Initialize from pre-compiled WASM module.
115
- *
116
- * Useful for environments where the WASM is bundled differently.
74
+ * Initialize from pre-compiled WASM module or Response.
117
75
  *
118
- * @param module - Pre-compiled WebAssembly.Module
76
+ * @param module - Pre-compiled WebAssembly.Module, Response, or bytes
119
77
  */
120
78
  export async function initWasmFromModule(module) {
121
- if (wasmInstance) {
79
+ if (initialized) {
122
80
  return;
123
81
  }
124
- wasmModule = module;
125
- const imports = createImports();
126
- const instance = await WebAssembly.instantiate(module, imports);
127
- wasmInstance = instance.exports;
82
+ // Dynamically import the wasm-pack generated module
83
+ const { importWasmModule } = await import('./import-helper.js');
84
+ const wasmModule = await importWasmModule();
85
+ await wasmModule.default(module);
86
+ wasmExports = {
87
+ compress: wasmModule.compress,
88
+ decompress: wasmModule.decompress,
89
+ discover_patterns: wasmModule.discover_patterns,
90
+ version: wasmModule.version,
91
+ StreamingCompressor: wasmModule.StreamingCompressor,
92
+ };
93
+ initialized = true;
128
94
  }
129
95
  /**
130
96
  * Initialize from WASM bytes.
@@ -132,16 +98,7 @@ export async function initWasmFromModule(module) {
132
98
  * @param bytes - WASM binary as ArrayBuffer or Uint8Array
133
99
  */
134
100
  export async function initWasmFromBytes(bytes) {
135
- if (wasmInstance) {
136
- return;
137
- }
138
- const buffer = bytes instanceof Uint8Array
139
- ? new Uint8Array(bytes).buffer
140
- : bytes;
141
- wasmModule = await WebAssembly.compile(buffer);
142
- const imports = createImports();
143
- const instance = await WebAssembly.instantiate(wasmModule, imports);
144
- wasmInstance = instance.exports;
101
+ return initWasmFromModule(bytes);
145
102
  }
146
103
  /**
147
104
  * Get the initialized WASM exports.
@@ -149,24 +106,24 @@ export async function initWasmFromBytes(bytes) {
149
106
  * @throws Error if WASM is not initialized
150
107
  */
151
108
  export function getWasm() {
152
- if (!wasmInstance) {
109
+ if (!initialized || !wasmExports) {
153
110
  throw new Error('WASM not initialized. Call initWasm() first and await its completion.');
154
111
  }
155
- return wasmInstance;
112
+ return wasmExports;
156
113
  }
157
114
  /**
158
115
  * Check if WASM is initialized.
159
116
  */
160
117
  export function isWasmInitialized() {
161
- return wasmInstance !== null;
118
+ return initialized;
162
119
  }
163
120
  /**
164
121
  * Reset the WASM instance (mainly for testing).
165
122
  */
166
123
  export function resetWasm() {
167
- wasmInstance = null;
168
- wasmModule = null;
124
+ initialized = false;
169
125
  initPromise = null;
126
+ wasmExports = null;
170
127
  }
171
128
  /**
172
129
  * Get WASM module version.
@@ -175,5 +132,4 @@ export function getWasmVersion() {
175
132
  const wasm = getWasm();
176
133
  return wasm.version();
177
134
  }
178
- // Types are already exported at their interface declarations above
179
135
  //# sourceMappingURL=loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/wasm/loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqCH,eAAe;AACf,IAAI,UAAU,GAA8B,IAAI,CAAC;AACjD,IAAI,YAAY,GAAuB,IAAI,CAAC;AAC5C,IAAI,WAAW,GAAyB,IAAI,CAAC;AAE7C;;GAEG;AACH,SAAS,iBAAiB;IACxB,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC5E,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IACE,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,CAAC,QAAQ;QAChB,OAAO,CAAC,QAAQ,CAAC,IAAI,EACrB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,mBAAmB;AACvC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa;IAC1B,MAAM,GAAG,GAAG,iBAAiB,EAAE,CAAC;IAEhC,gCAAgC;IAChC,kDAAkD;IAClD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,2BAA2B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEvE,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YAClE,CAAC;YACD,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;QAChC,CAAC;QAED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AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,WAAW,GAAG,KAAK,CAAC;IACpB,WAAW,GAAG,IAAI,CAAC;IACnB,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,333 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Configuration for compression.
6
+ */
7
+ export class CompressionConfig {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ constructor();
11
+ meta_token_prefix: string;
12
+ meta_token_suffix: string;
13
+ selection_mode: string;
14
+ /**
15
+ * Beam width for beam search
16
+ */
17
+ beam_width: number;
18
+ /**
19
+ * Dictionary end delimiter token ID
20
+ */
21
+ dict_end_token: number;
22
+ /**
23
+ * Whether to include length tokens in dictionary
24
+ */
25
+ dict_length_enabled: boolean;
26
+ /**
27
+ * Dictionary start delimiter token ID
28
+ */
29
+ dict_start_token: number;
30
+ /**
31
+ * Enable hierarchical compression
32
+ */
33
+ hierarchical_enabled: boolean;
34
+ /**
35
+ * Maximum hierarchical compression depth
36
+ */
37
+ hierarchical_max_depth: number;
38
+ /**
39
+ * Maximum pattern length to consider
40
+ */
41
+ max_subsequence_length: number;
42
+ /**
43
+ * Size of meta-token pool
44
+ */
45
+ meta_token_pool_size: number;
46
+ /**
47
+ * Minimum pattern length to consider
48
+ */
49
+ min_subsequence_length: number;
50
+ /**
51
+ * Enable round-trip verification
52
+ */
53
+ verify: boolean;
54
+ }
55
+
56
+ /**
57
+ * Metrics from a compression operation.
58
+ */
59
+ export class CompressionMetrics {
60
+ private constructor();
61
+ free(): void;
62
+ [Symbol.dispose](): void;
63
+ /**
64
+ * Number of candidates discovered
65
+ */
66
+ candidates_discovered: number;
67
+ /**
68
+ * Number of candidates selected
69
+ */
70
+ candidates_selected: number;
71
+ /**
72
+ * Time spent in pattern discovery (ms)
73
+ */
74
+ discovery_time_ms: number;
75
+ /**
76
+ * Peak memory usage (bytes, approximate)
77
+ */
78
+ peak_memory_bytes: number;
79
+ /**
80
+ * Time spent in selection (ms)
81
+ */
82
+ selection_time_ms: number;
83
+ /**
84
+ * Time spent in serialization (ms)
85
+ */
86
+ serialization_time_ms: number;
87
+ /**
88
+ * Total compression time (ms)
89
+ */
90
+ total_time_ms: number;
91
+ }
92
+
93
+ /**
94
+ * Result of compression operation.
95
+ */
96
+ export class CompressionResult {
97
+ private constructor();
98
+ free(): void;
99
+ [Symbol.dispose](): void;
100
+ /**
101
+ * Get the body tokens as a JS array.
102
+ */
103
+ getBodyTokens(): Uint32Array;
104
+ /**
105
+ * Get the dictionary tokens as a JS array.
106
+ */
107
+ getDictionaryTokens(): Uint32Array;
108
+ /**
109
+ * Get the original tokens as a JS array.
110
+ */
111
+ getOriginalTokens(): Uint32Array;
112
+ /**
113
+ * Get the serialized tokens as a JS array.
114
+ */
115
+ getSerializedTokens(): Uint32Array;
116
+ /**
117
+ * Get the static dictionary ID if used.
118
+ */
119
+ getStaticDictionaryId(): string | undefined;
120
+ /**
121
+ * Get the compression ratio (compressed/original).
122
+ */
123
+ readonly compression_ratio: number;
124
+ /**
125
+ * Get tokens saved by compression.
126
+ */
127
+ readonly tokens_saved: bigint;
128
+ /**
129
+ * Compressed sequence length
130
+ */
131
+ compressed_length: number;
132
+ /**
133
+ * Original sequence length
134
+ */
135
+ original_length: number;
136
+ }
137
+
138
+ /**
139
+ * Streaming compressor for large inputs.
140
+ */
141
+ export class StreamingCompressor {
142
+ free(): void;
143
+ [Symbol.dispose](): void;
144
+ /**
145
+ * Add a chunk of tokens.
146
+ */
147
+ add_chunk(tokens: Uint32Array): void;
148
+ /**
149
+ * Finish streaming and produce compressed result.
150
+ */
151
+ finish(): CompressionResult;
152
+ /**
153
+ * Get approximate memory usage.
154
+ */
155
+ memory_usage(): number;
156
+ /**
157
+ * Create a new streaming compressor.
158
+ */
159
+ constructor(config: any);
160
+ }
161
+
162
+ /**
163
+ * WASM-specific configuration for memory and performance tuning.
164
+ */
165
+ export class WasmConfig {
166
+ free(): void;
167
+ [Symbol.dispose](): void;
168
+ constructor();
169
+ /**
170
+ * Chunk size for streaming processing (default: 32768)
171
+ */
172
+ chunk_size: number;
173
+ /**
174
+ * Maximum memory usage in MB (default: 256)
175
+ */
176
+ max_memory_mb: number;
177
+ /**
178
+ * Enable streaming for inputs above threshold (default: 50000)
179
+ */
180
+ streaming_threshold: number;
181
+ }
182
+
183
+ /**
184
+ * Compress a token sequence.
185
+ *
186
+ * # Arguments
187
+ *
188
+ * * `tokens` - The token sequence to compress (Uint32Array from JS)
189
+ * * `config` - Optional configuration (JsValue representing JsCompressionConfig)
190
+ *
191
+ * # Returns
192
+ *
193
+ * A CompressionResult containing the compressed tokens and metadata.
194
+ */
195
+ export function compress(tokens: Uint32Array, config: any): CompressionResult;
196
+
197
+ /**
198
+ * Decompress a compressed token sequence.
199
+ *
200
+ * # Arguments
201
+ *
202
+ * * `tokens` - The compressed token sequence
203
+ * * `config` - Optional configuration
204
+ *
205
+ * # Returns
206
+ *
207
+ * The original token sequence.
208
+ */
209
+ export function decompress(tokens: Uint32Array, config: any): Uint32Array;
210
+
211
+ /**
212
+ * Discover patterns without compressing.
213
+ *
214
+ * Useful for analysis and building static dictionaries.
215
+ */
216
+ export function discover_patterns(tokens: Uint32Array, min_length: number, max_length: number): any;
217
+
218
+ /**
219
+ * Initialize panic hook for better error messages in WASM.
220
+ */
221
+ export function init(): void;
222
+
223
+ /**
224
+ * Get version information.
225
+ */
226
+ export function version(): string;
227
+
228
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
229
+
230
+ export interface InitOutput {
231
+ readonly memory: WebAssembly.Memory;
232
+ readonly __wbg_compressionconfig_free: (a: number, b: number) => void;
233
+ readonly __wbg_compressionmetrics_free: (a: number, b: number) => void;
234
+ readonly __wbg_compressionresult_free: (a: number, b: number) => void;
235
+ readonly __wbg_get_compressionconfig_beam_width: (a: number) => number;
236
+ readonly __wbg_get_compressionconfig_dict_end_token: (a: number) => number;
237
+ readonly __wbg_get_compressionconfig_dict_length_enabled: (a: number) => number;
238
+ readonly __wbg_get_compressionconfig_dict_start_token: (a: number) => number;
239
+ readonly __wbg_get_compressionconfig_hierarchical_enabled: (a: number) => number;
240
+ readonly __wbg_get_compressionconfig_hierarchical_max_depth: (a: number) => number;
241
+ readonly __wbg_get_compressionconfig_max_subsequence_length: (a: number) => number;
242
+ readonly __wbg_get_compressionconfig_meta_token_pool_size: (a: number) => number;
243
+ readonly __wbg_get_compressionconfig_min_subsequence_length: (a: number) => number;
244
+ readonly __wbg_get_compressionconfig_verify: (a: number) => number;
245
+ readonly __wbg_get_compressionmetrics_candidates_discovered: (a: number) => number;
246
+ readonly __wbg_get_compressionmetrics_discovery_time_ms: (a: number) => number;
247
+ readonly __wbg_get_compressionmetrics_peak_memory_bytes: (a: number) => number;
248
+ readonly __wbg_get_compressionmetrics_selection_time_ms: (a: number) => number;
249
+ readonly __wbg_get_compressionmetrics_serialization_time_ms: (a: number) => number;
250
+ readonly __wbg_get_compressionmetrics_total_time_ms: (a: number) => number;
251
+ readonly __wbg_get_wasmconfig_chunk_size: (a: number) => number;
252
+ readonly __wbg_get_wasmconfig_max_memory_mb: (a: number) => number;
253
+ readonly __wbg_get_wasmconfig_streaming_threshold: (a: number) => number;
254
+ readonly __wbg_set_compressionconfig_beam_width: (a: number, b: number) => void;
255
+ readonly __wbg_set_compressionconfig_dict_end_token: (a: number, b: number) => void;
256
+ readonly __wbg_set_compressionconfig_dict_length_enabled: (a: number, b: number) => void;
257
+ readonly __wbg_set_compressionconfig_dict_start_token: (a: number, b: number) => void;
258
+ readonly __wbg_set_compressionconfig_hierarchical_enabled: (a: number, b: number) => void;
259
+ readonly __wbg_set_compressionconfig_hierarchical_max_depth: (a: number, b: number) => void;
260
+ readonly __wbg_set_compressionconfig_max_subsequence_length: (a: number, b: number) => void;
261
+ readonly __wbg_set_compressionconfig_meta_token_pool_size: (a: number, b: number) => void;
262
+ readonly __wbg_set_compressionconfig_min_subsequence_length: (a: number, b: number) => void;
263
+ readonly __wbg_set_compressionconfig_verify: (a: number, b: number) => void;
264
+ readonly __wbg_set_compressionmetrics_candidates_discovered: (a: number, b: number) => void;
265
+ readonly __wbg_set_compressionmetrics_discovery_time_ms: (a: number, b: number) => void;
266
+ readonly __wbg_set_compressionmetrics_peak_memory_bytes: (a: number, b: number) => void;
267
+ readonly __wbg_set_compressionmetrics_selection_time_ms: (a: number, b: number) => void;
268
+ readonly __wbg_set_compressionmetrics_serialization_time_ms: (a: number, b: number) => void;
269
+ readonly __wbg_set_compressionmetrics_total_time_ms: (a: number, b: number) => void;
270
+ readonly __wbg_set_wasmconfig_chunk_size: (a: number, b: number) => void;
271
+ readonly __wbg_set_wasmconfig_max_memory_mb: (a: number, b: number) => void;
272
+ readonly __wbg_set_wasmconfig_streaming_threshold: (a: number, b: number) => void;
273
+ readonly __wbg_streamingcompressor_free: (a: number, b: number) => void;
274
+ readonly __wbg_wasmconfig_free: (a: number, b: number) => void;
275
+ readonly compress: (a: number, b: number, c: any) => [number, number, number];
276
+ readonly compressionconfig_meta_token_prefix: (a: number) => [number, number];
277
+ readonly compressionconfig_meta_token_suffix: (a: number) => [number, number];
278
+ readonly compressionconfig_new: () => number;
279
+ readonly compressionconfig_selection_mode: (a: number) => [number, number];
280
+ readonly compressionconfig_set_meta_token_prefix: (a: number, b: number, c: number) => void;
281
+ readonly compressionconfig_set_meta_token_suffix: (a: number, b: number, c: number) => void;
282
+ readonly compressionconfig_set_selection_mode: (a: number, b: number, c: number) => void;
283
+ readonly compressionresult_compression_ratio: (a: number) => number;
284
+ readonly compressionresult_getBodyTokens: (a: number) => [number, number];
285
+ readonly compressionresult_getDictionaryTokens: (a: number) => [number, number];
286
+ readonly compressionresult_getOriginalTokens: (a: number) => [number, number];
287
+ readonly compressionresult_getSerializedTokens: (a: number) => [number, number];
288
+ readonly compressionresult_getStaticDictionaryId: (a: number) => [number, number];
289
+ readonly compressionresult_tokens_saved: (a: number) => bigint;
290
+ readonly decompress: (a: number, b: number, c: any) => [number, number, number, number];
291
+ readonly discover_patterns: (a: number, b: number, c: number, d: number) => [number, number, number];
292
+ readonly streamingcompressor_add_chunk: (a: number, b: number, c: number) => void;
293
+ readonly streamingcompressor_finish: (a: number) => [number, number, number];
294
+ readonly streamingcompressor_memory_usage: (a: number) => number;
295
+ readonly streamingcompressor_new: (a: any) => [number, number, number];
296
+ readonly version: () => [number, number];
297
+ readonly wasmconfig_new: () => number;
298
+ readonly init: () => void;
299
+ readonly __wbg_set_compressionmetrics_candidates_selected: (a: number, b: number) => void;
300
+ readonly __wbg_set_compressionresult_compressed_length: (a: number, b: number) => void;
301
+ readonly __wbg_set_compressionresult_original_length: (a: number, b: number) => void;
302
+ readonly __wbg_get_compressionmetrics_candidates_selected: (a: number) => number;
303
+ readonly __wbg_get_compressionresult_compressed_length: (a: number) => number;
304
+ readonly __wbg_get_compressionresult_original_length: (a: number) => number;
305
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
306
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
307
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
308
+ readonly __wbindgen_externrefs: WebAssembly.Table;
309
+ readonly __externref_table_dealloc: (a: number) => void;
310
+ readonly __wbindgen_start: () => void;
311
+ }
312
+
313
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
314
+
315
+ /**
316
+ * Instantiates the given `module`, which can either be bytes or
317
+ * a precompiled `WebAssembly.Module`.
318
+ *
319
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
320
+ *
321
+ * @returns {InitOutput}
322
+ */
323
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
324
+
325
+ /**
326
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
327
+ * for everything else, calls `WebAssembly.instantiate` directly.
328
+ *
329
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
330
+ *
331
+ * @returns {Promise<InitOutput>}
332
+ */
333
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;