@hpcc-js/wasm-zstd 1.11.1 → 1.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/wasm-zstd",
3
- "version": "1.11.1",
3
+ "version": "1.12.1",
4
4
  "description": "hpcc-js - WASM zstd",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,7 +38,7 @@
38
38
  "update-major": "npx -y npm-check-updates -u"
39
39
  },
40
40
  "devDependencies": {
41
- "@hpcc-js/esbuild-plugins": "1.8.1",
41
+ "@hpcc-js/esbuild-plugins": "1.8.3",
42
42
  "@hpcc-js/wasm-util": "1.0.0"
43
43
  },
44
44
  "keywords": [
@@ -57,5 +57,5 @@
57
57
  },
58
58
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
59
59
  "license": "Apache-2.0",
60
- "gitHead": "9d18bfd8d74b23e6b79bb07a05115b2412e3a9c9"
60
+ "gitHead": "0199646cd7680d07e1619e593dc189c47bc25c1a"
61
61
  }
package/src/zstd.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import load, { reset } from "../../../build/packages/zstd/zstdlib.wasm";
3
3
  import type { MainModule, zstd } from "../types/zstdlib.js";
4
4
  import { MainModuleEx } from "@hpcc-js/wasm-util";
5
+
5
6
  type ZstdExports = MainModule["zstd"];
6
7
 
7
8
  // Ref: http://facebook.github.io/zstd/zstd_manual.html
@@ -26,12 +27,14 @@ let g_zstd: Promise<Zstd> | undefined;
26
27
  * const decompressed_data = zstd.decompress(compressed_data);
27
28
  * ```
28
29
  */
29
- export class Zstd extends MainModuleEx<MainModule> {
30
+ export class Zstd {
31
+
32
+ private _mainModule: MainModuleEx<MainModule>;
30
33
  private _zstdClass: ZstdExports;
31
34
  private _zstd: zstd;
32
35
 
33
36
  private constructor(_module: MainModule) {
34
- super(_module);
37
+ this._mainModule = new MainModuleEx(_module);
35
38
  this._zstdClass = _module.zstd;
36
39
  this._zstd = new this._zstdClass();
37
40
  }
@@ -97,19 +100,19 @@ export class Zstd extends MainModuleEx<MainModule> {
97
100
  * :::
98
101
  */
99
102
  compress(data: Uint8Array, compressionLevel: number = this.defaultCLevel()): Uint8Array {
100
- const uncompressed = this.dataToHeap(data);
103
+ const uncompressed = this._mainModule.dataToHeap(data);
101
104
 
102
105
  const compressedSize = this._zstdClass.compressBound(data.length);
103
- const compressed = this.malloc(compressedSize);
106
+ const compressed = this._mainModule.malloc(compressedSize);
104
107
  compressed.size = this._zstdClass.compress(compressed.ptr, compressedSize, uncompressed.ptr, uncompressed.size, compressionLevel);
105
108
  /* istanbul ignore if */
106
109
  if (this._zstdClass.isError(compressed.size)) {
107
110
  console.error(this._zstdClass.getErrorName(compressed.size));
108
111
  }
109
- const retVal = this.heapToUint8Array(compressed);
112
+ const retVal = this._mainModule.heapToUint8Array(compressed);
110
113
 
111
- this.free(compressed);
112
- this.free(uncompressed);
114
+ this._mainModule.free(compressed);
115
+ this._mainModule.free(uncompressed);
113
116
  return retVal;
114
117
  }
115
118
 
@@ -120,7 +123,7 @@ export class Zstd extends MainModuleEx<MainModule> {
120
123
  * @returns Compressed chunk data
121
124
  */
122
125
  compressChunk(data: Uint8Array): Uint8Array {
123
- const uncompressed = this.dataToHeap(data);
126
+ const uncompressed = this._mainModule.dataToHeap(data);
124
127
  // For streaming compression, we need enough space for:
125
128
  // 1. The compressed data (compressBound gives worst case)
126
129
  // 2. Additional overhead for frame headers and internal buffering
@@ -128,22 +131,22 @@ export class Zstd extends MainModuleEx<MainModule> {
128
131
  const boundSize = this._zstdClass.compressBound(data.length);
129
132
  const streamOutSize = this._zstdClass.CStreamOutSize();
130
133
  const compressedSize = boundSize + streamOutSize;
131
- const compressed = this.malloc(compressedSize);
134
+ const compressed = this._mainModule.malloc(compressedSize);
132
135
 
133
136
  compressed.size = this._zstd.compressChunk(compressed.ptr, compressedSize, uncompressed.ptr, uncompressed.size);
134
137
 
135
138
  // Check for errors before trying to use the size
136
139
  if (this._zstdClass.isError(compressed.size)) {
137
140
  const errorName = this._zstdClass.getErrorName(compressed.size);
138
- this.free(compressed);
139
- this.free(uncompressed);
141
+ this._mainModule.free(compressed);
142
+ this._mainModule.free(uncompressed);
140
143
  throw new Error(`compressChunk failed: ${errorName} (data.length=${data.length}, compressedSize=${compressedSize})`);
141
144
  }
142
145
 
143
- const retVal = this.heapToUint8Array(compressed);
146
+ const retVal = this._mainModule.heapToUint8Array(compressed);
144
147
 
145
- this.free(compressed);
146
- this.free(uncompressed);
148
+ this._mainModule.free(compressed);
149
+ this._mainModule.free(uncompressed);
147
150
  return retVal;
148
151
  }
149
152
 
@@ -153,20 +156,20 @@ export class Zstd extends MainModuleEx<MainModule> {
153
156
  */
154
157
  compressEnd(): Uint8Array {
155
158
  const compressedSize = this._zstdClass.CStreamOutSize(); // Recommended buffer size for output
156
- const compressed = this.malloc(compressedSize);
159
+ const compressed = this._mainModule.malloc(compressedSize);
157
160
 
158
161
  compressed.size = this._zstd.compressEnd(compressed.ptr, compressedSize);
159
162
 
160
163
  // Check for errors before trying to use the size
161
164
  if (this._zstdClass.isError(compressed.size)) {
162
165
  const errorName = this._zstdClass.getErrorName(compressed.size);
163
- this.free(compressed);
166
+ this._mainModule.free(compressed);
164
167
  throw new Error(`compressEnd failed: ${errorName} (compressedSize=${compressedSize})`);
165
168
  }
166
169
 
167
- const retVal = this.heapToUint8Array(compressed);
170
+ const retVal = this._mainModule.heapToUint8Array(compressed);
168
171
 
169
- this.free(compressed);
172
+ this._mainModule.free(compressed);
170
173
  return retVal;
171
174
  }
172
175
 
@@ -175,7 +178,7 @@ export class Zstd extends MainModuleEx<MainModule> {
175
178
  * @returns Uncompressed data.
176
179
  */
177
180
  decompress(compressedData: Uint8Array): Uint8Array {
178
- const compressed = this.dataToHeap(compressedData);
181
+ const compressed = this._mainModule.dataToHeap(compressedData);
179
182
  let uncompressedSize = this._zstdClass.getFrameContentSize(compressed.ptr, compressed.size);
180
183
 
181
184
  // Check if size is unknown (happens with streaming compression)
@@ -186,7 +189,7 @@ export class Zstd extends MainModuleEx<MainModule> {
186
189
  /* istanbul ignore if */
187
190
  if (this._zstdClass.isError(uncompressedSize)) {
188
191
  const errorName = this._zstdClass.getErrorName(uncompressedSize);
189
- this.free(compressed);
192
+ this._mainModule.free(compressed);
190
193
  throw new Error(`Failed to get frame content size: ${errorName}`);
191
194
  }
192
195
 
@@ -198,20 +201,20 @@ export class Zstd extends MainModuleEx<MainModule> {
198
201
  uncompressedSize = Math.max(compressed.size * 20, 1024 * 1024); // At least 1MB or 20x compressed
199
202
  }
200
203
 
201
- const uncompressed = this.malloc(uncompressedSize);
204
+ const uncompressed = this._mainModule.malloc(uncompressedSize);
202
205
 
203
206
  uncompressed.size = this._zstdClass.decompress(uncompressed.ptr, uncompressedSize, compressed.ptr, compressed.size);
204
207
  /* istanbul ignore if */
205
208
  if (this._zstdClass.isError(uncompressed.size)) {
206
209
  const errorName = this._zstdClass.getErrorName(uncompressed.size);
207
- this.free(uncompressed);
208
- this.free(compressed);
210
+ this._mainModule.free(uncompressed);
211
+ this._mainModule.free(compressed);
209
212
  throw new Error(`Decompression failed: ${errorName}`);
210
213
  }
211
- const retVal = this.heapToUint8Array(uncompressed);
214
+ const retVal = this._mainModule.heapToUint8Array(uncompressed);
212
215
 
213
- this.free(uncompressed);
214
- this.free(compressed);
216
+ this._mainModule.free(uncompressed);
217
+ this._mainModule.free(compressed);
215
218
  return retVal;
216
219
  }
217
220
 
@@ -223,14 +226,14 @@ export class Zstd extends MainModuleEx<MainModule> {
223
226
  * @returns Decompressed chunk data
224
227
  */
225
228
  decompressChunk(compressedData: Uint8Array, outputSize: number): Uint8Array {
226
- const compressed = this.dataToHeap(compressedData);
227
- const uncompressed = this.malloc(outputSize);
229
+ const compressed = this._mainModule.dataToHeap(compressedData);
230
+ const uncompressed = this._mainModule.malloc(outputSize);
228
231
 
229
232
  uncompressed.size = this._zstd.decompressChunk(uncompressed.ptr, outputSize, compressed.ptr, compressed.size);
230
- const retVal = this.heapToUint8Array(uncompressed);
233
+ const retVal = this._mainModule.heapToUint8Array(uncompressed);
231
234
 
232
- this.free(uncompressed);
233
- this.free(compressed);
235
+ this._mainModule.free(uncompressed);
236
+ this._mainModule.free(compressed);
234
237
  return retVal;
235
238
  }
236
239
 
package/types/zstd.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { MainModule } from "../types/zstdlib.js";
2
- import { MainModuleEx } from "@hpcc-js/wasm-util";
3
1
  /**
4
2
  * The Zstandard WASM library, provides a simplified wrapper around the Zstandard c++ library.
5
3
  *
@@ -17,7 +15,8 @@ import { MainModuleEx } from "@hpcc-js/wasm-util";
17
15
  * const decompressed_data = zstd.decompress(compressed_data);
18
16
  * ```
19
17
  */
20
- export declare class Zstd extends MainModuleEx<MainModule> {
18
+ export declare class Zstd {
19
+ private _mainModule;
21
20
  private _zstdClass;
22
21
  private _zstd;
23
22
  private constructor();