@cloudpss/compress 0.5.37 → 0.5.39
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/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +8 -6
- package/tests/e2e.js +4 -4
package/dist/index.js
CHANGED
|
@@ -12,14 +12,14 @@ export const CompressionAlgorithms = Object.freeze({
|
|
|
12
12
|
}),
|
|
13
13
|
});
|
|
14
14
|
const modules = {
|
|
15
|
-
zstd: () => import('@cloudpss/zstd'),
|
|
16
|
-
gzip: () => import('#gzip'),
|
|
15
|
+
zstd: async () => import('@cloudpss/zstd'),
|
|
16
|
+
gzip: async () => import('#gzip'),
|
|
17
17
|
};
|
|
18
18
|
/** 加载相关库 */
|
|
19
|
-
function loadLib(algorithm) {
|
|
19
|
+
async function loadLib(algorithm) {
|
|
20
20
|
if (!(algorithm in modules))
|
|
21
21
|
throw new Error(`Unknown compression algorithm: ${algorithm}`);
|
|
22
|
-
return modules[algorithm]();
|
|
22
|
+
return await modules[algorithm]();
|
|
23
23
|
}
|
|
24
24
|
/** 支持的数据转为 Uint8Array */
|
|
25
25
|
function toUint8Array(data) {
|
|
@@ -39,7 +39,7 @@ export function compress(data, algorithm = 'zstd') {
|
|
|
39
39
|
ret.algorithm = 'none';
|
|
40
40
|
return ret;
|
|
41
41
|
}
|
|
42
|
-
const ret = loadLib(algorithm).then(({ compress }) => compress(d));
|
|
42
|
+
const ret = loadLib(algorithm).then(async ({ compress }) => compress(d));
|
|
43
43
|
ret.algorithm = algorithm;
|
|
44
44
|
return ret;
|
|
45
45
|
}
|
|
@@ -76,7 +76,7 @@ export function decompress(data) {
|
|
|
76
76
|
result.algorithm = 'none';
|
|
77
77
|
return result;
|
|
78
78
|
}
|
|
79
|
-
const result = loadLib(algorithm).then(({ decompress }) => decompress(d));
|
|
79
|
+
const result = loadLib(algorithm).then(async ({ decompress }) => decompress(d));
|
|
80
80
|
result.algorithm = algorithm;
|
|
81
81
|
return result;
|
|
82
82
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc;AACd,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,SAAS,EAAE,MAAe;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACpD,OAAO,EAAE,CAAC;KACb,CAAC;IACF,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,SAAS,EAAE,MAAe;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,OAAO,EAAE,EAAE;KACd,CAAC;CACqC,CAAC,CAAC;AAE7C,MAAM,OAAO,GAAG;IACZ,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc;AACd,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,SAAS,EAAE,MAAe;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACpD,OAAO,EAAE,CAAC;KACb,CAAC;IACF,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,SAAS,EAAE,MAAe;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,OAAO,EAAE,EAAE;KACd,CAAC;CACqC,CAAC,CAAC;AAE7C,MAA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AO,CAAC,OAAO,CAAC,CAAC,CAAsB,CAAC;QACvD,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC;QAC1B,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAsB,CAAC;IACrG,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.5.
|
|
3
|
+
"version": "0.5.39",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"fflate": "^0.8.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@bokuweb/zstd-wasm": "
|
|
26
|
-
"@types/node": "^
|
|
25
|
+
"@bokuweb/zstd-wasm": "0.0.21-alpha.5",
|
|
26
|
+
"@types/node": "^22.5.1",
|
|
27
27
|
"@types/pako": "^2.0.3",
|
|
28
28
|
"@xingrz/cppzst": "2.1.0-alpha.8",
|
|
29
29
|
"brotli-wasm": "^3.0.1",
|
|
30
30
|
"fzstd": "^0.1.1",
|
|
31
31
|
"pako": "^2.1.0",
|
|
32
|
-
"type-fest": "^4.
|
|
32
|
+
"type-fest": "^4.26.0",
|
|
33
33
|
"wasm-flate": "1.0.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -26,14 +26,16 @@ export const CompressionAlgorithms = Object.freeze({
|
|
|
26
26
|
} satisfies Record<string, CompressionInfo>);
|
|
27
27
|
|
|
28
28
|
const modules = {
|
|
29
|
-
zstd: () => import('@cloudpss/zstd'),
|
|
30
|
-
gzip: () => import('#gzip'),
|
|
29
|
+
zstd: async () => import('@cloudpss/zstd'),
|
|
30
|
+
gzip: async () => import('#gzip'),
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/** 加载相关库 */
|
|
34
|
-
function loadLib(
|
|
34
|
+
async function loadLib(
|
|
35
|
+
algorithm: Exclude<CompressionAlgorithm, 'none'>,
|
|
36
|
+
): Promise<Awaited<ReturnType<(typeof modules)[keyof typeof modules]>>> {
|
|
35
37
|
if (!(algorithm in modules)) throw new Error(`Unknown compression algorithm: ${algorithm}`);
|
|
36
|
-
return modules[algorithm]();
|
|
38
|
+
return await modules[algorithm]();
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/** 支持的数据转为 Uint8Array */
|
|
@@ -55,7 +57,7 @@ export function compress(data: BinaryData, algorithm: CompressionAlgorithm = 'zs
|
|
|
55
57
|
ret.algorithm = 'none';
|
|
56
58
|
return ret;
|
|
57
59
|
}
|
|
58
|
-
const ret = loadLib(algorithm).then(({ compress }) => compress(d)) as CompressionResult;
|
|
60
|
+
const ret = loadLib(algorithm).then(async ({ compress }) => compress(d)) as CompressionResult;
|
|
59
61
|
ret.algorithm = algorithm;
|
|
60
62
|
return ret;
|
|
61
63
|
}
|
|
@@ -98,7 +100,7 @@ export function decompress(data: BinaryData): CompressionResult {
|
|
|
98
100
|
return result;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
const result = loadLib(algorithm).then(({ decompress }) => decompress(d)) as CompressionResult;
|
|
103
|
+
const result = loadLib(algorithm).then(async ({ decompress }) => decompress(d)) as CompressionResult;
|
|
102
104
|
result.algorithm = algorithm;
|
|
103
105
|
return result;
|
|
104
106
|
}
|
package/tests/e2e.js
CHANGED
|
@@ -100,15 +100,15 @@ describe(`other data types`, () => {
|
|
|
100
100
|
describe('rejects bad input', () => {
|
|
101
101
|
it('compress', () => {
|
|
102
102
|
// @ts-expect-error test
|
|
103
|
-
expect(() => compress(123)).toThrow();
|
|
103
|
+
expect(async () => compress(123)).toThrow();
|
|
104
104
|
// @ts-expect-error test
|
|
105
|
-
expect(() => compress([1, 2, 3])).toThrow();
|
|
105
|
+
expect(async () => compress([1, 2, 3])).toThrow();
|
|
106
106
|
// @ts-expect-error test
|
|
107
|
-
expect(() => compress(Buffer.alloc(10), 'xxx')).toThrow();
|
|
107
|
+
expect(async () => compress(Buffer.alloc(10), 'xxx')).toThrow();
|
|
108
108
|
});
|
|
109
109
|
it('decompress', () => {
|
|
110
110
|
// @ts-expect-error test
|
|
111
|
-
expect(() => decompress(123)).toThrow();
|
|
111
|
+
expect(async () => decompress(123)).toThrow();
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
|