@cloudpss/compress 0.5.29 → 0.5.31
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** 压缩 */
|
|
2
|
-
export declare function compress(data: Uint8Array): Uint8Array
|
|
2
|
+
export declare function compress(data: Uint8Array): Promise<Uint8Array>;
|
|
3
3
|
/** 解压 */
|
|
4
|
-
export declare function decompress(data: Uint8Array): Uint8Array
|
|
4
|
+
export declare function decompress(data: Uint8Array): Promise<Uint8Array>;
|
|
@@ -1,10 +1,57 @@
|
|
|
1
|
-
import { gzipSync, gunzipSync } from 'fflate';
|
|
2
1
|
/** 压缩 */
|
|
3
|
-
export function compress(data) {
|
|
4
|
-
|
|
2
|
+
export async function compress(data) {
|
|
3
|
+
if (typeof CompressionStream === 'undefined') {
|
|
4
|
+
const { gzipSync } = await import('fflate');
|
|
5
|
+
return gzipSync(data);
|
|
6
|
+
}
|
|
7
|
+
const stream = new ReadableStream({
|
|
8
|
+
start(controller) {
|
|
9
|
+
controller.enqueue(data);
|
|
10
|
+
controller.close();
|
|
11
|
+
},
|
|
12
|
+
}).pipeThrough(new CompressionStream('gzip'));
|
|
13
|
+
const reader = stream.getReader();
|
|
14
|
+
const chunks = [];
|
|
15
|
+
for (;;) {
|
|
16
|
+
const { done, value } = await reader.read();
|
|
17
|
+
if (done)
|
|
18
|
+
break;
|
|
19
|
+
chunks.push(value);
|
|
20
|
+
}
|
|
21
|
+
const result = new Uint8Array(chunks.reduce((sum, chunk) => sum + chunk.length, 0));
|
|
22
|
+
let offset = 0;
|
|
23
|
+
for (const chunk of chunks) {
|
|
24
|
+
result.set(chunk, offset);
|
|
25
|
+
offset += chunk.length;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
5
28
|
}
|
|
6
29
|
/** 解压 */
|
|
7
|
-
export function decompress(data) {
|
|
8
|
-
|
|
30
|
+
export async function decompress(data) {
|
|
31
|
+
if (typeof DecompressionStream === 'undefined') {
|
|
32
|
+
const { gunzipSync } = await import('fflate');
|
|
33
|
+
return gunzipSync(data);
|
|
34
|
+
}
|
|
35
|
+
const stream = new ReadableStream({
|
|
36
|
+
start(controller) {
|
|
37
|
+
controller.enqueue(data);
|
|
38
|
+
controller.close();
|
|
39
|
+
},
|
|
40
|
+
}).pipeThrough(new DecompressionStream('gzip'));
|
|
41
|
+
const reader = stream.getReader();
|
|
42
|
+
const chunks = [];
|
|
43
|
+
for (;;) {
|
|
44
|
+
const { done, value } = await reader.read();
|
|
45
|
+
if (done)
|
|
46
|
+
break;
|
|
47
|
+
chunks.push(value);
|
|
48
|
+
}
|
|
49
|
+
const result = new Uint8Array(chunks.reduce((sum, chunk) => sum + chunk.length, 0));
|
|
50
|
+
let offset = 0;
|
|
51
|
+
for (const chunk of chunks) {
|
|
52
|
+
result.set(chunk, offset);
|
|
53
|
+
offset += chunk.length;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
9
56
|
}
|
|
10
57
|
//# sourceMappingURL=index-browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.js","sourceRoot":"","sources":["../../src/gzip/index-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index-browser.js","sourceRoot":"","sources":["../../src/gzip/index-browser.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAgB;IAC3C,IAAI,OAAO,iBAAiB,KAAK,WAAW,EAAE,CAAC;QAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,cAAc,CAAa;QAC1C,KAAK,CAAC,UAAU;YACZ,UAAU,CAAC,OAAO,CAAC,I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ACJ,CAAC,CAAC,WAAW,CAAa,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,SAAS,CAAC;QACN,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI;YAAE,MAAM;QAChB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IACpF,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IACD,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.31",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"./dist/gzip/index.js": "./dist/gzip/index-browser.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@cloudpss/zstd": "^0.
|
|
21
|
+
"@cloudpss/zstd": "^0.3.0",
|
|
22
22
|
"fflate": "^0.8.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@bokuweb/zstd-wasm": "^0.0.20",
|
|
26
|
-
"@types/node": "^20.12.
|
|
26
|
+
"@types/node": "^20.12.12",
|
|
27
27
|
"@types/pako": "^2.0.3",
|
|
28
28
|
"@xingrz/cppzst": "2.1.0-alpha.8",
|
|
29
|
-
"brotli-wasm": "^
|
|
29
|
+
"brotli-wasm": "^3.0.0",
|
|
30
30
|
"fzstd": "^0.1.1",
|
|
31
31
|
"pako": "^2.1.0",
|
|
32
|
-
"type-fest": "^4.
|
|
32
|
+
"type-fest": "^4.18.2",
|
|
33
33
|
"wasm-flate": "1.0.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
@@ -1,11 +1,55 @@
|
|
|
1
|
-
import { gzipSync, gunzipSync } from 'fflate';
|
|
2
|
-
|
|
3
1
|
/** 压缩 */
|
|
4
|
-
export function compress(data: Uint8Array): Uint8Array {
|
|
5
|
-
|
|
2
|
+
export async function compress(data: Uint8Array): Promise<Uint8Array> {
|
|
3
|
+
if (typeof CompressionStream === 'undefined') {
|
|
4
|
+
const { gzipSync } = await import('fflate');
|
|
5
|
+
return gzipSync(data);
|
|
6
|
+
}
|
|
7
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
8
|
+
start(controller) {
|
|
9
|
+
controller.enqueue(data);
|
|
10
|
+
controller.close();
|
|
11
|
+
},
|
|
12
|
+
}).pipeThrough<Uint8Array>(new CompressionStream('gzip'));
|
|
13
|
+
const reader = stream.getReader();
|
|
14
|
+
const chunks: Uint8Array[] = [];
|
|
15
|
+
for (;;) {
|
|
16
|
+
const { done, value } = await reader.read();
|
|
17
|
+
if (done) break;
|
|
18
|
+
chunks.push(value);
|
|
19
|
+
}
|
|
20
|
+
const result = new Uint8Array(chunks.reduce((sum, chunk) => sum + chunk.length, 0));
|
|
21
|
+
let offset = 0;
|
|
22
|
+
for (const chunk of chunks) {
|
|
23
|
+
result.set(chunk, offset);
|
|
24
|
+
offset += chunk.length;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
6
27
|
}
|
|
7
28
|
|
|
8
29
|
/** 解压 */
|
|
9
|
-
export function decompress(data: Uint8Array): Uint8Array {
|
|
10
|
-
|
|
30
|
+
export async function decompress(data: Uint8Array): Promise<Uint8Array> {
|
|
31
|
+
if (typeof DecompressionStream === 'undefined') {
|
|
32
|
+
const { gunzipSync } = await import('fflate');
|
|
33
|
+
return gunzipSync(data);
|
|
34
|
+
}
|
|
35
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
36
|
+
start(controller) {
|
|
37
|
+
controller.enqueue(data);
|
|
38
|
+
controller.close();
|
|
39
|
+
},
|
|
40
|
+
}).pipeThrough<Uint8Array>(new DecompressionStream('gzip'));
|
|
41
|
+
const reader = stream.getReader();
|
|
42
|
+
const chunks: Uint8Array[] = [];
|
|
43
|
+
for (;;) {
|
|
44
|
+
const { done, value } = await reader.read();
|
|
45
|
+
if (done) break;
|
|
46
|
+
chunks.push(value);
|
|
47
|
+
}
|
|
48
|
+
const result = new Uint8Array(chunks.reduce((sum, chunk) => sum + chunk.length, 0));
|
|
49
|
+
let offset = 0;
|
|
50
|
+
for (const chunk of chunks) {
|
|
51
|
+
result.set(chunk, offset);
|
|
52
|
+
offset += chunk.length;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
11
55
|
}
|