@loaders.gl/compression 4.2.0-alpha.6 → 4.2.0-beta.2
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/dist/compress-on-worker.d.ts.map +1 -1
- package/dist/compress-on-worker.js +4 -1
- package/dist/compression-worker.js +2 -2
- package/dist/compression-worker.js.map +4 -4
- package/dist/dist.dev.js +663 -50
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +76 -63
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/lib/brotli-compression.d.ts +1 -1
- package/dist/lib/brotli-compression.d.ts.map +1 -1
- package/dist/lib/brotli-compression.js +9 -10
- package/dist/lib/compression.d.ts +1 -1
- package/dist/lib/compression.d.ts.map +1 -1
- package/dist/lib/compression.js +6 -1
- package/dist/lib/deflate-compression.d.ts.map +1 -1
- package/dist/lib/deflate-compression.js +3 -0
- package/dist/lib/gzip-compression.d.ts.map +1 -1
- package/dist/lib/gzip-compression.js +3 -0
- package/dist/lib/lz4-compression.d.ts +1 -0
- package/dist/lib/lz4-compression.d.ts.map +1 -1
- package/dist/lib/lz4-compression.js +10 -5
- package/dist/lib/lzo-compression.d.ts +1 -1
- package/dist/lib/lzo-compression.d.ts.map +1 -1
- package/dist/lib/lzo-compression.js +9 -7
- package/dist/lib/no-compression.d.ts.map +1 -1
- package/dist/lib/no-compression.js +3 -0
- package/dist/lib/snappy-compression.d.ts.map +1 -1
- package/dist/lib/snappy-compression.js +3 -0
- package/dist/lib/zstd-compression.d.ts +2 -1
- package/dist/lib/zstd-compression.d.ts.map +1 -1
- package/dist/lib/zstd-compression.js +29 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -0
- package/dist/workers/compression-worker-node.d.ts.map +1 -1
- package/dist/workers/compression-worker-node.js +3 -0
- package/dist/workers/compression-worker.js +3 -0
- package/package.json +4 -4
- package/src/compress-on-worker.ts +4 -0
- package/src/index.ts +4 -0
- package/src/lib/brotli-compression.ts +12 -11
- package/src/lib/compression.ts +7 -1
- package/src/lib/deflate-compression.ts +4 -0
- package/src/lib/gzip-compression.ts +4 -0
- package/src/lib/lz4-compression.ts +13 -6
- package/src/lib/lzo-compression.ts +10 -9
- package/src/lib/no-compression.ts +4 -0
- package/src/lib/snappy-compression.ts +4 -0
- package/src/lib/zstd-compression.ts +35 -10
- package/src/types.ts +4 -0
- package/src/workers/compression-worker-node.ts +4 -0
- package/src/workers/compression-worker.ts +4 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// LZO
|
|
2
6
|
// import {loadLibrary} from '@loaders.gl/worker-utils';
|
|
3
|
-
import {toBuffer} from '@loaders.gl/loader-utils';
|
|
7
|
+
import {registerJSModules, getJSModule, toBuffer} from '@loaders.gl/loader-utils';
|
|
4
8
|
|
|
5
9
|
import type {CompressionOptions} from './compression';
|
|
6
10
|
import {Compression} from './compression';
|
|
@@ -12,8 +16,6 @@ import {Compression} from './compression';
|
|
|
12
16
|
// const LZO_WASM_JS_URL = './node_modules/lzo-wasm/lzo-wasm.js';
|
|
13
17
|
// const LZO_WASM_WASM_URL = './node_modules/lzo-wasm/lzo-wasm.wasm';
|
|
14
18
|
|
|
15
|
-
let lzo;
|
|
16
|
-
|
|
17
19
|
/**
|
|
18
20
|
* Lempel-Ziv-Oberheimer compression / decompression
|
|
19
21
|
*/
|
|
@@ -31,20 +33,18 @@ export class LZOCompression extends Compression {
|
|
|
31
33
|
constructor(options: CompressionOptions) {
|
|
32
34
|
super(options);
|
|
33
35
|
this.options = options;
|
|
34
|
-
|
|
35
|
-
lzo = lzo || this.options?.modules?.lzo;
|
|
36
|
-
if (!lzo) {
|
|
37
|
-
throw new Error(this.name);
|
|
38
|
-
}
|
|
36
|
+
registerJSModules(options?.modules);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
async preload() {
|
|
39
|
+
async preload(modules: Record<string, any> = {}): Promise<void> {
|
|
40
|
+
registerJSModules(modules);
|
|
42
41
|
// await loadLibrary(LZO_WASM_JS_URL);
|
|
43
42
|
// await loadLibrary(LZO_WASM_WASM_URL);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
async compress(input: ArrayBuffer): Promise<ArrayBuffer> {
|
|
47
46
|
await this.preload();
|
|
47
|
+
const lzo = getJSModule('lzo', this.name);
|
|
48
48
|
// const inputArray = new Uint8Array(input);
|
|
49
49
|
const inputBuffer = toBuffer(input);
|
|
50
50
|
return lzo.compress(inputBuffer).buffer;
|
|
@@ -53,6 +53,7 @@ export class LZOCompression extends Compression {
|
|
|
53
53
|
async decompress(input: ArrayBuffer): Promise<ArrayBuffer> {
|
|
54
54
|
try {
|
|
55
55
|
await this.preload();
|
|
56
|
+
const lzo = getJSModule('lzo', this.name);
|
|
56
57
|
// const inputArray = new Uint8Array(input);
|
|
57
58
|
const inputBuffer = toBuffer(input);
|
|
58
59
|
return lzo.decompress(inputBuffer).buffer;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// ZSTD
|
|
2
6
|
import type {CompressionOptions} from './compression';
|
|
3
7
|
import {Compression} from './compression';
|
|
8
|
+
import {registerJSModules} from '@loaders.gl/loader-utils';
|
|
9
|
+
import {checkJSModule, getJSModule, getJSModuleOrNull} from '@loaders.gl/loader-utils';
|
|
10
|
+
|
|
4
11
|
// import {ZstdCodec} from 'zstd-codec'; // https://bundlephobia.com/package/zstd-codec
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
const CHUNK_SIZE = 1000000; // Tested value
|
|
14
|
+
|
|
15
|
+
let zstdPromise: Promise<any>;
|
|
7
16
|
let zstd;
|
|
8
17
|
|
|
9
18
|
/**
|
|
@@ -23,31 +32,47 @@ export class ZstdCompression extends Compression {
|
|
|
23
32
|
constructor(options: CompressionOptions) {
|
|
24
33
|
super(options);
|
|
25
34
|
this.options = options;
|
|
26
|
-
|
|
27
|
-
ZstdCodec = this.options?.modules?.['zstd-codec'];
|
|
28
|
-
if (!ZstdCodec) {
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.warn(`${this.name} library not installed`);
|
|
31
|
-
}
|
|
35
|
+
registerJSModules(options?.modules);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
async preload(): Promise<void> {
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
async preload(modules: Record<string, any> = {}): Promise<void> {
|
|
39
|
+
registerJSModules(modules);
|
|
40
|
+
checkJSModule('zstd-codec', this.name);
|
|
41
|
+
const ZstdCodec = getJSModuleOrNull('zstd-codec');
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
43
|
+
if (!zstdPromise && ZstdCodec) {
|
|
44
|
+
zstdPromise = new Promise((resolve) => ZstdCodec.run((zstd) => resolve(zstd)));
|
|
45
|
+
zstd = await zstdPromise;
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
compressSync(input: ArrayBuffer): ArrayBuffer {
|
|
50
|
+
getJSModule('zstd-codec', this.name);
|
|
41
51
|
const simpleZstd = new zstd.Simple();
|
|
42
52
|
const inputArray = new Uint8Array(input);
|
|
43
53
|
return simpleZstd.compress(inputArray).buffer;
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
decompressSync(input: ArrayBuffer): ArrayBuffer {
|
|
57
|
+
getJSModule('zstd-codec', this.name);
|
|
47
58
|
const simpleZstd = new zstd.Simple();
|
|
48
59
|
// var ddict = new zstd.Dict.Decompression(dictData);
|
|
49
60
|
// var jsonBytes = simpleZstd.decompressUsingDict(jsonZstData, ddict);
|
|
50
61
|
const inputArray = new Uint8Array(input);
|
|
51
62
|
return simpleZstd.decompress(inputArray).buffer;
|
|
52
63
|
}
|
|
64
|
+
|
|
65
|
+
async decompress(input: ArrayBuffer, size?: number): Promise<ArrayBuffer> {
|
|
66
|
+
await this.preload();
|
|
67
|
+
const simpleZstd = new zstd.Streaming();
|
|
68
|
+
const inputArray = new Uint8Array(input);
|
|
69
|
+
|
|
70
|
+
const chunks: ArrayBuffer[] = [];
|
|
71
|
+
for (let i = 0; i <= inputArray.length; i += CHUNK_SIZE) {
|
|
72
|
+
chunks.push(inputArray.subarray(i, i + CHUNK_SIZE));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const decompressResult = await simpleZstd.decompressChunks(chunks);
|
|
76
|
+
return decompressResult.buffer;
|
|
77
|
+
}
|
|
53
78
|
}
|
package/src/types.ts
CHANGED