@naturalcycles/nodejs-lib 15.66.0 → 15.67.0
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/zip/zip.util.d.ts +8 -0
- package/dist/zip/zip.util.js +20 -0
- package/package.json +1 -1
- package/src/zip/zip.util.ts +25 -0
package/dist/zip/zip.util.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { ZlibOptions, ZstdOptions } from 'node:zlib';
|
|
2
|
+
export declare function decompressZstdOrInflateToString(buf: Buffer): Promise<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Detects if Buffer is zstd-compressed.
|
|
5
|
+
* Otherwise attempts to Inflate.
|
|
6
|
+
*/
|
|
7
|
+
export declare function decompressZstdOrInflate(buf: Buffer): Promise<Buffer<ArrayBuffer>>;
|
|
2
8
|
/**
|
|
3
9
|
* deflateBuffer uses `deflate`.
|
|
4
10
|
* It's 9 bytes shorter than `gzip`.
|
|
@@ -26,3 +32,5 @@ export declare function gunzipToString(buf: Buffer, options?: ZlibOptions): Prom
|
|
|
26
32
|
export declare function zstdCompress(input: Buffer | string, options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
|
|
27
33
|
export declare function zstdDecompressToString(input: Buffer, options?: ZstdOptions): Promise<string>;
|
|
28
34
|
export declare function zstdDecompress(input: Buffer, options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
|
|
35
|
+
export declare function isZstdBuffer(input: Buffer): boolean;
|
|
36
|
+
export declare function isGzipBuffer(input: Buffer): boolean;
|
package/dist/zip/zip.util.js
CHANGED
|
@@ -6,6 +6,19 @@ const gzip = promisify(zlib.gzip.bind(zlib));
|
|
|
6
6
|
const gunzip = promisify(zlib.gunzip.bind(zlib));
|
|
7
7
|
const zstdCompressAsync = promisify(zlib.zstdCompress.bind(zlib));
|
|
8
8
|
const zstdDecompressAsync = promisify(zlib.zstdDecompress.bind(zlib));
|
|
9
|
+
export async function decompressZstdOrInflateToString(buf) {
|
|
10
|
+
return (await decompressZstdOrInflate(buf)).toString();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Detects if Buffer is zstd-compressed.
|
|
14
|
+
* Otherwise attempts to Inflate.
|
|
15
|
+
*/
|
|
16
|
+
export async function decompressZstdOrInflate(buf) {
|
|
17
|
+
if (isZstdBuffer(buf)) {
|
|
18
|
+
return await zstdDecompressAsync(buf);
|
|
19
|
+
}
|
|
20
|
+
return await inflate(buf);
|
|
21
|
+
}
|
|
9
22
|
/**
|
|
10
23
|
* deflateBuffer uses `deflate`.
|
|
11
24
|
* It's 9 bytes shorter than `gzip`.
|
|
@@ -55,3 +68,10 @@ export async function zstdDecompressToString(input, options = {}) {
|
|
|
55
68
|
export async function zstdDecompress(input, options = {}) {
|
|
56
69
|
return await zstdDecompressAsync(input, options);
|
|
57
70
|
}
|
|
71
|
+
const ZSTD_MAGIC_NUMBER = 0xfd2fb528;
|
|
72
|
+
export function isZstdBuffer(input) {
|
|
73
|
+
return input.readUInt32LE(0) === ZSTD_MAGIC_NUMBER;
|
|
74
|
+
}
|
|
75
|
+
export function isGzipBuffer(input) {
|
|
76
|
+
return input[0] === 0x1f && input[1] === 0x8b;
|
|
77
|
+
}
|
package/package.json
CHANGED
package/src/zip/zip.util.ts
CHANGED
|
@@ -9,6 +9,21 @@ const gunzip = promisify(zlib.gunzip.bind(zlib))
|
|
|
9
9
|
const zstdCompressAsync = promisify(zlib.zstdCompress.bind(zlib))
|
|
10
10
|
const zstdDecompressAsync = promisify(zlib.zstdDecompress.bind(zlib))
|
|
11
11
|
|
|
12
|
+
export async function decompressZstdOrInflateToString(buf: Buffer): Promise<string> {
|
|
13
|
+
return (await decompressZstdOrInflate(buf)).toString()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Detects if Buffer is zstd-compressed.
|
|
18
|
+
* Otherwise attempts to Inflate.
|
|
19
|
+
*/
|
|
20
|
+
export async function decompressZstdOrInflate(buf: Buffer): Promise<Buffer<ArrayBuffer>> {
|
|
21
|
+
if (isZstdBuffer(buf)) {
|
|
22
|
+
return await zstdDecompressAsync(buf)
|
|
23
|
+
}
|
|
24
|
+
return await inflate(buf)
|
|
25
|
+
}
|
|
26
|
+
|
|
12
27
|
/**
|
|
13
28
|
* deflateBuffer uses `deflate`.
|
|
14
29
|
* It's 9 bytes shorter than `gzip`.
|
|
@@ -92,3 +107,13 @@ export async function zstdDecompress(
|
|
|
92
107
|
): Promise<Buffer<ArrayBuffer>> {
|
|
93
108
|
return await zstdDecompressAsync(input, options)
|
|
94
109
|
}
|
|
110
|
+
|
|
111
|
+
const ZSTD_MAGIC_NUMBER = 0xfd2fb528
|
|
112
|
+
|
|
113
|
+
export function isZstdBuffer(input: Buffer): boolean {
|
|
114
|
+
return input.readUInt32LE(0) === ZSTD_MAGIC_NUMBER
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function isGzipBuffer(input: Buffer): boolean {
|
|
118
|
+
return input[0] === 0x1f && input[1] === 0x8b
|
|
119
|
+
}
|