@cloudpss/compress 0.4.12 → 0.4.14
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/benchmark.js +81 -51
- package/dist/gzip/index-browser.d.ts +4 -4
- package/dist/gzip/index-browser.js +9 -9
- package/dist/gzip/index.d.ts +4 -4
- package/dist/gzip/index.js +21 -21
- package/dist/gzip/index.js.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.js +58 -58
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/gzip/index.ts +2 -2
- package/src/index.ts +1 -1
- package/yarn-error.log +4520 -0
- package/dist/zstd/index-browser.d.ts +0 -2
- package/dist/zstd/index-browser.js +0 -3
- package/dist/zstd/index-browser.js.map +0 -1
- package/dist/zstd/index.d.ts +0 -4
- package/dist/zstd/index.js +0 -14
- package/dist/zstd/index.js.map +0 -1
- package/dist/zstd/wasm/compress.d.ts +0 -2
- package/dist/zstd/wasm/compress.js +0 -28
- package/dist/zstd/wasm/compress.js.map +0 -1
- package/dist/zstd/wasm/decompress.d.ts +0 -6
- package/dist/zstd/wasm/decompress.js +0 -30
- package/dist/zstd/wasm/decompress.js.map +0 -1
- package/dist/zstd/wasm/module.d.ts +0 -2
- package/dist/zstd/wasm/module.js +0 -4
- package/dist/zstd/wasm/module.js.map +0 -1
- package/src/zstd/index-browser.ts +0 -2
- package/src/zstd/index.ts +0 -15
- package/src/zstd/wasm/compress.ts +0 -27
- package/src/zstd/wasm/decompress.ts +0 -37
- package/src/zstd/wasm/module.ts +0 -5
- package/wasm/zstd.g.d.ts +0 -16
- package/wasm/zstd.g.js +0 -29
package/benchmark.js
CHANGED
|
@@ -1,62 +1,92 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import prettyBytes from 'pretty-bytes';
|
|
2
3
|
import wasmFlate from 'wasm-flate';
|
|
3
4
|
import zlib from 'zlib';
|
|
4
|
-
import
|
|
5
|
-
import * as myZstd from './dist/zstd/index-browser.js';
|
|
5
|
+
import bokuwebZstd from '@bokuweb/zstd-wasm';
|
|
6
6
|
import cppzst from '@xingrz/cppzst';
|
|
7
|
+
import * as myZstdWasm from '@cloudpss/zstd/wasm';
|
|
8
|
+
import * as myZstdNapi from '@cloudpss/zstd';
|
|
7
9
|
import pako from 'pako';
|
|
8
|
-
import brotli from 'brotli-wasm';
|
|
9
10
|
import files from '../../benchmark-files/index.js';
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
14
|
+
const brotli = createRequire(import.meta.url)('brotli-wasm');
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
(
|
|
16
|
-
|
|
16
|
+
const t = (/** @type {number} */ time) => time.toFixed(2) + 'ms';
|
|
17
|
+
const pb = (/** @type {number} */ size) => prettyBytes(size, { binary: true });
|
|
18
|
+
|
|
19
|
+
await bokuwebZstd.init();
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
/** 生成测试 */
|
|
22
|
+
function createTest(
|
|
23
|
+
/** @type {string} */ name,
|
|
24
|
+
/** @type {(value: Uint8Array) => Uint8Array} */ compressor,
|
|
25
|
+
/** @type {(value: Uint8Array) => Uint8Array} */ decompressor,
|
|
26
|
+
) {
|
|
27
|
+
/** 测试函数 */
|
|
28
|
+
function fn(/** @type {Buffer} */ data) {
|
|
29
|
+
let start = performance.now();
|
|
30
|
+
const compressed = compressor(data);
|
|
31
|
+
const compressTime = performance.now() - start;
|
|
32
|
+
start = performance.now();
|
|
33
|
+
const decompressed = decompressor(compressed);
|
|
34
|
+
const decompressTime = performance.now() - start;
|
|
35
|
+
console.assert(data.equals(decompressed), name, `unmatched`);
|
|
36
|
+
return { compressed, compressTime, decompressTime };
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
Object.defineProperty(fn, 'name', { value: name });
|
|
39
|
+
return fn;
|
|
40
|
+
}
|
|
41
|
+
const tests = [
|
|
42
|
+
createTest('gzip -d (wasm)', wasmFlate.gzip_encode_raw, wasmFlate.gzip_decode_raw),
|
|
43
|
+
createTest('gzip -d (node)', zlib.gzipSync, zlib.gunzipSync),
|
|
44
|
+
createTest('gzip -d (pako)', pako.gzip, pako.ungzip),
|
|
45
|
+
createTest('zstd -3 (Oz,wasm)', (buf) => bokuwebZstd.compress(buf, 3), bokuwebZstd.decompress),
|
|
46
|
+
createTest('zstd -3 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 3), myZstdWasm.decompress),
|
|
47
|
+
createTest('zstd -4 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 4), myZstdWasm.decompress),
|
|
48
|
+
createTest('zstd -4 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 4 }), cppzst.decompressSync),
|
|
49
|
+
createTest('zstd -4 (napi)', (buf) => myZstdNapi.compress(buf, 4), myZstdNapi.decompress),
|
|
50
|
+
createTest('zstd -10 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 10), myZstdWasm.decompress),
|
|
51
|
+
createTest('zstd -10 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 10 }), cppzst.decompressSync),
|
|
52
|
+
createTest('zstd -10 (napi)', (buf) => myZstdNapi.compress(buf, 10), myZstdNapi.decompress),
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument
|
|
54
|
+
createTest('br -1 (wasm)', (buf) => brotli.compress(buf, { quality: 1 }), brotli.decompress),
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument
|
|
56
|
+
createTest('br -3 (wasm)', (buf) => brotli.compress(buf, { quality: 3 }), brotli.decompress),
|
|
57
|
+
createTest(
|
|
58
|
+
'br -3 (node)',
|
|
59
|
+
(buf) =>
|
|
60
|
+
zlib.brotliCompressSync(buf, {
|
|
61
|
+
params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 3 },
|
|
62
|
+
}),
|
|
63
|
+
zlib.brotliDecompressSync,
|
|
64
|
+
),
|
|
65
|
+
createTest(
|
|
66
|
+
`br -5 (node)`,
|
|
67
|
+
(buf) =>
|
|
68
|
+
zlib.brotliCompressSync(buf, {
|
|
69
|
+
params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 5 },
|
|
70
|
+
}),
|
|
71
|
+
zlib.brotliDecompressSync,
|
|
72
|
+
),
|
|
73
|
+
createTest(
|
|
74
|
+
`br -8 (node)`,
|
|
75
|
+
(buf) =>
|
|
76
|
+
zlib.brotliCompressSync(buf, {
|
|
77
|
+
params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 8 },
|
|
78
|
+
}),
|
|
79
|
+
zlib.brotliDecompressSync,
|
|
80
|
+
),
|
|
81
|
+
];
|
|
82
|
+
for await (const { file, data } of files()) {
|
|
83
|
+
console.log(`File: ${file} \tRaw: ${pb(data.length)}`);
|
|
84
|
+
for (const test of tests) {
|
|
85
|
+
const result = test(data);
|
|
86
|
+
const compressed = result.compressed.length;
|
|
87
|
+
const ratio = (data.length / result.compressed.length).toFixed(2);
|
|
88
|
+
console.log(
|
|
89
|
+
` ${test.name}: \t${ratio}(${pb(compressed)}) \t${t(result.compressTime)} \t${t(result.decompressTime)}`,
|
|
90
|
+
);
|
|
61
91
|
}
|
|
62
|
-
}
|
|
92
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** 压缩 */
|
|
2
|
-
export declare function compress(data: Uint8Array): Uint8Array;
|
|
3
|
-
/** 解压 */
|
|
4
|
-
export declare function decompress(data: Uint8Array): Uint8Array;
|
|
1
|
+
/** 压缩 */
|
|
2
|
+
export declare function compress(data: Uint8Array): Uint8Array;
|
|
3
|
+
/** 解压 */
|
|
4
|
+
export declare function decompress(data: Uint8Array): Uint8Array;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { gzip, ungzip } from 'pako';
|
|
2
|
-
/** 压缩 */
|
|
3
|
-
export function compress(data) {
|
|
4
|
-
return gzip(data);
|
|
5
|
-
}
|
|
6
|
-
/** 解压 */
|
|
7
|
-
export function decompress(data) {
|
|
8
|
-
return ungzip(data);
|
|
9
|
-
}
|
|
1
|
+
import { gzip, ungzip } from 'pako';
|
|
2
|
+
/** 压缩 */
|
|
3
|
+
export function compress(data) {
|
|
4
|
+
return gzip(data);
|
|
5
|
+
}
|
|
6
|
+
/** 解压 */
|
|
7
|
+
export function decompress(data) {
|
|
8
|
+
return ungzip(data);
|
|
9
|
+
}
|
|
10
10
|
//# sourceMappingURL=index-browser.js.map
|
package/dist/gzip/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** 压缩 */
|
|
2
|
-
export declare function compress(data: Uint8Array): Promise<Uint8Array>;
|
|
3
|
-
/** 解压 */
|
|
4
|
-
export declare function decompress(data: Uint8Array): Promise<Uint8Array>;
|
|
1
|
+
/** 压缩 */
|
|
2
|
+
export declare function compress(data: Uint8Array): Promise<Uint8Array>;
|
|
3
|
+
/** 解压 */
|
|
4
|
+
export declare function decompress(data: Uint8Array): Promise<Uint8Array>;
|
package/dist/gzip/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { gzip, gunzip } from 'zlib';
|
|
2
|
-
/** 压缩 */
|
|
3
|
-
export function compress(data) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
gzip(data, (err, result) => {
|
|
6
|
-
if (err || !result)
|
|
7
|
-
reject(err);
|
|
8
|
-
resolve(
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
/** 解压 */
|
|
13
|
-
export function decompress(data) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
gunzip(data, (err, result) => {
|
|
16
|
-
if (err || !result)
|
|
17
|
-
reject(err);
|
|
18
|
-
resolve(
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}
|
|
1
|
+
import { gzip, gunzip } from 'zlib';
|
|
2
|
+
/** 压缩 */
|
|
3
|
+
export function compress(data) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
gzip(data, (err, result) => {
|
|
6
|
+
if (err || !result)
|
|
7
|
+
reject(err);
|
|
8
|
+
resolve(result);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** 解压 */
|
|
13
|
+
export function decompress(data) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
gunzip(data, (err, result) => {
|
|
16
|
+
if (err || !result)
|
|
17
|
+
reject(err);
|
|
18
|
+
resolve(result);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/dist/gzip/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gzip/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,SAAS;AACT,MAAM,UAAU,QAAQ,CAAC,IAAgB;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACvB,IAAI,GAAG,IAAI,CAAC,MAAM;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gzip/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,SAAS;AACT,MAAM,UAAU,QAAQ,CAAC,IAAgB;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACvB,IAAI,GAAG,IAAI,CAAC,MAAM;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS;AACT,MAAM,UAAU,UAAU,CAAC,IAAgB;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACzB,IAAI,GAAG,IAAI,CAAC,MAAM;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/** 可用的压缩算法 */
|
|
2
|
-
export type CompressionAlgorithm = 'zstd' | 'gzip' | 'none';
|
|
3
|
-
/** 压缩算法的魔数 */
|
|
4
|
-
export declare const MAGIC_NUMBERS: {
|
|
5
|
-
zstd: number[];
|
|
6
|
-
gzip: number[];
|
|
7
|
-
};
|
|
8
|
-
/** 使用指定算法压缩 */
|
|
9
|
-
export declare function compress(data: Uint8Array, algorithm?: CompressionAlgorithm): CompressionResult;
|
|
10
|
-
/** 压缩/解压缩结果 */
|
|
11
|
-
export type CompressionResult = Promise<Uint8Array> & {
|
|
12
|
-
algorithm: CompressionAlgorithm;
|
|
13
|
-
};
|
|
14
|
-
/** 探测压缩算法 */
|
|
15
|
-
export declare function detectCompression(data: Uint8Array): CompressionAlgorithm;
|
|
16
|
-
/** 探测压缩算法并解压缩 */
|
|
17
|
-
export declare function decompress(data: Uint8Array): CompressionResult;
|
|
1
|
+
/** 可用的压缩算法 */
|
|
2
|
+
export type CompressionAlgorithm = 'zstd' | 'gzip' | 'none';
|
|
3
|
+
/** 压缩算法的魔数 */
|
|
4
|
+
export declare const MAGIC_NUMBERS: {
|
|
5
|
+
zstd: number[];
|
|
6
|
+
gzip: number[];
|
|
7
|
+
};
|
|
8
|
+
/** 使用指定算法压缩 */
|
|
9
|
+
export declare function compress(data: Uint8Array, algorithm?: CompressionAlgorithm): CompressionResult;
|
|
10
|
+
/** 压缩/解压缩结果 */
|
|
11
|
+
export type CompressionResult = Promise<Uint8Array> & {
|
|
12
|
+
algorithm: CompressionAlgorithm;
|
|
13
|
+
};
|
|
14
|
+
/** 探测压缩算法 */
|
|
15
|
+
export declare function detectCompression(data: Uint8Array): CompressionAlgorithm;
|
|
16
|
+
/** 探测压缩算法并解压缩 */
|
|
17
|
+
export declare function decompress(data: Uint8Array): CompressionResult;
|
package/dist/index.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/** 压缩算法的魔数 */
|
|
2
|
-
export const MAGIC_NUMBERS = {
|
|
3
|
-
zstd: [0x28, 0xb5, 0x2f, 0xfd],
|
|
4
|
-
gzip: [0x1f, 0x8b],
|
|
5
|
-
};
|
|
6
|
-
const modules = {
|
|
7
|
-
zstd: () => import('
|
|
8
|
-
gzip: () => import('./gzip/index.js'),
|
|
9
|
-
};
|
|
10
|
-
/** 加载相关库 */
|
|
11
|
-
function loadLib(algorithm) {
|
|
12
|
-
if (!(algorithm in modules))
|
|
13
|
-
throw new Error(`Unknown compression algorithm: ${algorithm}`);
|
|
14
|
-
return modules[algorithm]();
|
|
15
|
-
}
|
|
16
|
-
/** 使用指定算法压缩 */
|
|
17
|
-
export function compress(data, algorithm = 'zstd') {
|
|
18
|
-
if (algorithm === 'none') {
|
|
19
|
-
const ret = Promise.resolve(data);
|
|
20
|
-
ret.algorithm = 'none';
|
|
21
|
-
return ret;
|
|
22
|
-
}
|
|
23
|
-
const ret = loadLib(algorithm).then((lib) => lib.compress(data));
|
|
24
|
-
ret.algorithm = algorithm;
|
|
25
|
-
return ret;
|
|
26
|
-
}
|
|
27
|
-
/** 探测压缩算法 */
|
|
28
|
-
export function detectCompression(data) {
|
|
29
|
-
for (const key in MAGIC_NUMBERS) {
|
|
30
|
-
const k = key;
|
|
31
|
-
const magicNumber = MAGIC_NUMBERS[k];
|
|
32
|
-
if (data.length <= magicNumber.length)
|
|
33
|
-
continue;
|
|
34
|
-
let match = true;
|
|
35
|
-
for (let i = 0; i < magicNumber.length; i++) {
|
|
36
|
-
if (data[i] !== magicNumber[i]) {
|
|
37
|
-
match = false;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (match)
|
|
42
|
-
return k;
|
|
43
|
-
}
|
|
44
|
-
return 'none';
|
|
45
|
-
}
|
|
46
|
-
/** 探测压缩算法并解压缩 */
|
|
47
|
-
export function decompress(data) {
|
|
48
|
-
const algorithm = detectCompression(data);
|
|
49
|
-
if (algorithm === 'none') {
|
|
50
|
-
// 不是压缩数据
|
|
51
|
-
const result = Promise.resolve(data);
|
|
52
|
-
result.algorithm = 'none';
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
const result = loadLib(algorithm).then(({ decompress }) => decompress(data));
|
|
56
|
-
result.algorithm = algorithm;
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
1
|
+
/** 压缩算法的魔数 */
|
|
2
|
+
export const MAGIC_NUMBERS = {
|
|
3
|
+
zstd: [0x28, 0xb5, 0x2f, 0xfd],
|
|
4
|
+
gzip: [0x1f, 0x8b],
|
|
5
|
+
};
|
|
6
|
+
const modules = {
|
|
7
|
+
zstd: () => import('@cloudpss/zstd'),
|
|
8
|
+
gzip: () => import('./gzip/index.js'),
|
|
9
|
+
};
|
|
10
|
+
/** 加载相关库 */
|
|
11
|
+
function loadLib(algorithm) {
|
|
12
|
+
if (!(algorithm in modules))
|
|
13
|
+
throw new Error(`Unknown compression algorithm: ${algorithm}`);
|
|
14
|
+
return modules[algorithm]();
|
|
15
|
+
}
|
|
16
|
+
/** 使用指定算法压缩 */
|
|
17
|
+
export function compress(data, algorithm = 'zstd') {
|
|
18
|
+
if (algorithm === 'none') {
|
|
19
|
+
const ret = Promise.resolve(data);
|
|
20
|
+
ret.algorithm = 'none';
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
const ret = loadLib(algorithm).then((lib) => lib.compress(data));
|
|
24
|
+
ret.algorithm = algorithm;
|
|
25
|
+
return ret;
|
|
26
|
+
}
|
|
27
|
+
/** 探测压缩算法 */
|
|
28
|
+
export function detectCompression(data) {
|
|
29
|
+
for (const key in MAGIC_NUMBERS) {
|
|
30
|
+
const k = key;
|
|
31
|
+
const magicNumber = MAGIC_NUMBERS[k];
|
|
32
|
+
if (data.length <= magicNumber.length)
|
|
33
|
+
continue;
|
|
34
|
+
let match = true;
|
|
35
|
+
for (let i = 0; i < magicNumber.length; i++) {
|
|
36
|
+
if (data[i] !== magicNumber[i]) {
|
|
37
|
+
match = false;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (match)
|
|
42
|
+
return k;
|
|
43
|
+
}
|
|
44
|
+
return 'none';
|
|
45
|
+
}
|
|
46
|
+
/** 探测压缩算法并解压缩 */
|
|
47
|
+
export function decompress(data) {
|
|
48
|
+
const algorithm = detectCompression(data);
|
|
49
|
+
if (algorithm === 'none') {
|
|
50
|
+
// 不是压缩数据
|
|
51
|
+
const result = Promise.resolve(data);
|
|
52
|
+
result.algorithm = 'none';
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
const result = loadLib(algorithm).then(({ decompress }) => decompress(data));
|
|
56
|
+
result.algorithm = algorithm;
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
59
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc;AACd,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC9B,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,OAAO,GAAG;IACZ,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc;AACd,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IAC9B,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,OAAO,GAAG;IACZ,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC;IACpC,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC;CACxC,CAAC;AAEF,YAAY;AACZ,SAAS,OAAO,CAAC,SAAgD;IAC7D,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,SAAS,EAAE,CAAC,CAAC;IAC5F,OAAO,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;AAChC,CAAC;AAED,eAAe;AACf,MAAM,UAAU,QAAQ,CAAC,IAAgB,EAAE,YAAkC,MAAM;IAC/E,IAAI,SAAS,KAAK,MAAM,EAAE;QACtB,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAsB,CAAC;QACvD,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC;QACvB,OAAO,GAAG,CAAC;KACd;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAsB,CAAC;IACtF,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC;IAC1B,OAAO,GAAG,CAAC;AACf,CAAC;AAKD,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAC9C,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;QAC7B,MAAM,CAAC,GAAG,GAAiC,CAAC;QAC5C,MAAM,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,MAAM;YAAE,SAAS;QAChD,IAAI,KAAK,GAAG,IAAI,CAAC;QACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACzC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE;gBAC5B,KAAK,GAAG,KAAK,CAAC;gBACd,MAAM;aACT;SACJ;QACD,IAAI,KAAK;YAAE,OAAO,CAAC,CAAC;KACvB;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,iBAAiB;AACjB,MAAM,UAAU,UAAU,CAAC,IAAgB;IACvC,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAE1C,IAAI,SAAS,KAAK,MAAM,EAAE;QACtB,SAAS;QACT,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAsB,CAAC;QAC1D,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC;QAC1B,OAAO,MAAM,CAAC;KACjB;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAsB,CAAC;IAClG,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpss/compress",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,16 +23,17 @@
|
|
|
23
23
|
"benchmark": "node ./benchmark"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@
|
|
26
|
+
"@cloudpss/zstd": "^0.2.0",
|
|
27
27
|
"pako": "^2.1.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@bokuweb/zstd-wasm": "^0.0.
|
|
31
|
-
"@types/node": "^18.15.
|
|
30
|
+
"@bokuweb/zstd-wasm": "^0.0.20",
|
|
31
|
+
"@types/node": "^18.15.12",
|
|
32
32
|
"@types/pako": "^2.0.0",
|
|
33
|
+
"@xingrz/cppzst": "^2.1.0-alpha.8",
|
|
33
34
|
"brotli-wasm": "^1.3.1",
|
|
34
35
|
"pretty-bytes": "^6.1.0",
|
|
35
|
-
"type-fest": "^3.
|
|
36
|
+
"type-fest": "^3.8.0",
|
|
36
37
|
"wasm-flate": "1.0.2"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/src/gzip/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export function compress(data: Uint8Array): Promise<Uint8Array> {
|
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
6
|
gzip(data, (err, result) => {
|
|
7
7
|
if (err || !result) reject(err);
|
|
8
|
-
resolve(
|
|
8
|
+
resolve(result);
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
}
|
|
@@ -15,7 +15,7 @@ export function decompress(data: Uint8Array): Promise<Uint8Array> {
|
|
|
15
15
|
return new Promise((resolve, reject) => {
|
|
16
16
|
gunzip(data, (err, result) => {
|
|
17
17
|
if (err || !result) reject(err);
|
|
18
|
-
resolve(
|
|
18
|
+
resolve(result);
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
}
|