-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mod.ts
52 lines (49 loc) · 1.37 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import init, {
compress as wasmCompress,
decompress as wasmDecompress,
source,
} from "./wasm.js";
await init(source);
/**
* Compress a byte array.
*
* ```typescript
* import { compress } from "https://deno.land/x/brotli/mod.ts";
* const text = new TextEncoder().encode("X".repeat(64));
* console.log(text.length); // 64 Bytes
* console.log(compress(text).length); // 10 Bytes
* ```
*
* @param input Input data.
* @param bufferSize Read buffer size
* @param quality Controls the compression-speed vs compression-
* density tradeoff. The higher the quality, the slower the compression.
* @param lgwin Base 2 logarithm of the sliding window size.
*/
export function compress(
input: Uint8Array,
bufferSize = 4096,
quality = 6,
lgwin = 22,
): Uint8Array {
return wasmCompress(input, bufferSize, quality, lgwin);
}
/**
* Decompress a byte array.
*
* ```typescript
* import { decompress } from "https://deno.land/x/brotli/mod.ts";
* const compressed = Uint8Array.from([ 27, 63, 0, 0, 36, 176, 226, 153, 64, 18 ]);
* console.log(compressed.length); // 10 Bytes
* console.log(decompress(compressed).length); // 64 Bytes
* ```
*
* @param input Input data.
* @param bufferSize Read buffer size
*/
export function decompress(
input: Uint8Array,
bufferSize = 4096,
): Uint8Array {
return wasmDecompress(input, bufferSize);
}