@loaders.gl/compression 4.2.0-alpha.5 → 4.2.0-beta.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/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 +762 -119
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +117 -96
- 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 +14 -14
- 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 +9 -5
- package/dist/lib/gzip-compression.d.ts.map +1 -1
- package/dist/lib/gzip-compression.js +7 -4
- 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 +15 -9
- 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 +14 -11
- package/dist/lib/no-compression.d.ts.map +1 -1
- package/dist/lib/no-compression.js +8 -4
- package/dist/lib/snappy-compression.d.ts.map +1 -1
- package/dist/lib/snappy-compression.js +8 -4
- 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 +34 -13
- 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 +6 -6
- 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,7 +1,13 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// BROTLI
|
|
2
6
|
import type {CompressionOptions} from './compression';
|
|
3
7
|
import {Compression} from './compression';
|
|
4
8
|
import {isBrowser, toArrayBuffer} from '@loaders.gl/loader-utils';
|
|
9
|
+
import {registerJSModules, getJSModule, getJSModuleOrNull} from '@loaders.gl/loader-utils';
|
|
10
|
+
|
|
5
11
|
import type brotliNamespace from 'brotli';
|
|
6
12
|
// import brotli from 'brotli'; // https://bundlephobia.com/package/brotli
|
|
7
13
|
import {BrotliDecode} from '../brotli/decode';
|
|
@@ -25,7 +31,7 @@ const DEFAULT_BROTLI_OPTIONS = {
|
|
|
25
31
|
}
|
|
26
32
|
};
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
type Brotli = typeof brotliNamespace;
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
37
|
* brotli compression / decompression
|
|
@@ -40,18 +46,15 @@ export class BrotliCompression extends Compression {
|
|
|
40
46
|
constructor(options: BrotliCompressionOptions) {
|
|
41
47
|
super(options);
|
|
42
48
|
this.options = options;
|
|
49
|
+
registerJSModules(options?.modules);
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
* brotli is an injectable dependency due to big size
|
|
47
54
|
* @param options
|
|
48
55
|
*/
|
|
49
|
-
async preload(): Promise<void> {
|
|
50
|
-
|
|
51
|
-
if (!brotli) {
|
|
52
|
-
// eslint-disable-next-line no-console
|
|
53
|
-
console.warn(`${this.name} library not installed`);
|
|
54
|
-
}
|
|
56
|
+
async preload(modules: Record<string, any> = {}): Promise<void> {
|
|
57
|
+
registerJSModules(modules);
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
async compress(input: ArrayBuffer): Promise<ArrayBuffer> {
|
|
@@ -72,10 +75,7 @@ export class BrotliCompression extends Compression {
|
|
|
72
75
|
const brotliOptions = {...DEFAULT_BROTLI_OPTIONS.brotli, ...this.options?.brotli};
|
|
73
76
|
const inputArray = new Uint8Array(input);
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
throw new Error('brotli compression: brotli module not installed');
|
|
77
|
-
}
|
|
78
|
-
|
|
78
|
+
const brotli = getJSModule<Brotli>('brotli', this.name);
|
|
79
79
|
// @ts-ignore brotli types state that only Buffers are accepted...
|
|
80
80
|
const outputArray = brotli.compress(inputArray, brotliOptions);
|
|
81
81
|
return outputArray.buffer;
|
|
@@ -100,6 +100,7 @@ export class BrotliCompression extends Compression {
|
|
|
100
100
|
const brotliOptions = {...DEFAULT_BROTLI_OPTIONS.brotli, ...this.options?.brotli};
|
|
101
101
|
const inputArray = new Uint8Array(input);
|
|
102
102
|
|
|
103
|
+
const brotli = getJSModuleOrNull<Brotli>('brotli');
|
|
103
104
|
if (brotli) {
|
|
104
105
|
// @ts-ignore brotli types state that only Buffers are accepted...
|
|
105
106
|
const outputArray = brotli.decompress(inputArray, brotliOptions);
|
package/src/lib/compression.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// Compression interface
|
|
2
6
|
import {concatenateArrayBuffersAsync} from '@loaders.gl/loader-utils';
|
|
7
|
+
import {registerJSModules} from '@loaders.gl/loader-utils';
|
|
3
8
|
|
|
4
9
|
/** Compression options */
|
|
5
10
|
export type CompressionOptions = {
|
|
@@ -20,7 +25,8 @@ export abstract class Compression {
|
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/** Preloads any dynamic libraries. May enable sync functions */
|
|
23
|
-
async preload(): Promise<void> {
|
|
28
|
+
async preload(modules: Record<string, any> = {}): Promise<void> {
|
|
29
|
+
registerJSModules(modules);
|
|
24
30
|
return;
|
|
25
31
|
}
|
|
26
32
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
1
5
|
// Copyright (c) 2012 Pierre Curto
|
|
2
6
|
|
|
3
7
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -23,13 +27,13 @@
|
|
|
23
27
|
|
|
24
28
|
// LZ4
|
|
25
29
|
import {toArrayBuffer} from '@loaders.gl/loader-utils';
|
|
30
|
+
import {registerJSModules, getJSModule} from '@loaders.gl/loader-utils';
|
|
26
31
|
import type {CompressionOptions} from './compression';
|
|
27
32
|
import {Compression} from './compression';
|
|
33
|
+
|
|
28
34
|
// import lz4js from 'lz4js'; // https://bundlephobia.com/package/lz4
|
|
29
35
|
const LZ4_MAGIC_NUMBER = 0x184d2204;
|
|
30
36
|
|
|
31
|
-
let lz4js;
|
|
32
|
-
|
|
33
37
|
/**
|
|
34
38
|
* LZ4 compression / decompression
|
|
35
39
|
*/
|
|
@@ -44,13 +48,15 @@ export class LZ4Compression extends Compression {
|
|
|
44
48
|
super(options);
|
|
45
49
|
this.options = options;
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
registerJSModules(options?.modules);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async preload(modules: Record<string, any> = {}): Promise<void> {
|
|
55
|
+
registerJSModules(modules);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
compressSync(input: ArrayBuffer): ArrayBuffer {
|
|
59
|
+
const lz4js = getJSModule('lz4js', this.name);
|
|
54
60
|
const inputArray = new Uint8Array(input);
|
|
55
61
|
return lz4js.compress(inputArray).buffer;
|
|
56
62
|
}
|
|
@@ -62,6 +68,7 @@ export class LZ4Compression extends Compression {
|
|
|
62
68
|
* If data provided without magic number we will parse it as block
|
|
63
69
|
*/
|
|
64
70
|
decompressSync(data: ArrayBuffer, maxSize?: number): ArrayBuffer {
|
|
71
|
+
const lz4js = getJSModule('lz4js', this.name);
|
|
65
72
|
try {
|
|
66
73
|
const isMagicNumberExists = this.checkMagicNumber(data);
|
|
67
74
|
const inputArray = new Uint8Array(data);
|
|
@@ -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