-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mod.ts
54 lines (50 loc) 路 1.49 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
53
54
// Copyright 2020-present the denosaurs team. All rights reserved. MIT license.
import init, {
source,
compress as wasm_compress,
decompress as wasm_decompress,
} 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: number = 4096,
quality: number = 6,
lgwin: number = 22,
): Uint8Array {
return wasm_compress(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: number = 4096,
): Uint8Array {
return wasm_decompress(input, bufferSize);
}