-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod.ts
37 lines (33 loc) · 1.02 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
// Copyright 2020-present the denosaurs team. All rights reserved. MIT license.
import init, { lz4_compress, lz4_decompress, source } from "./wasm.js";
await init(source);
/**
* Compress a byte array using lz4.
*
* ```typescript
* import { compress } from "https://deno.land/x/lz4/mod.ts";
* const text = new TextEncoder().encode("X".repeat(64));
* console.log(text.length); // 64 Bytes
* console.log(compress(text).length); // 6 Bytes
* ```
*
* @param input Input data.
*/
export function compress(input: Uint8Array): Uint8Array {
return lz4_compress(input);
}
/**
* Decompress a byte array using lz4.
*
* ```typescript
* import { decompress } from "https://deno.land/x/lz4/mod.ts";
* const compressed = Uint8Array.from([ 31, 88, 1, 0, 44, 0 ]);
* console.log(compressed.length); // 6 Bytes
* console.log(decompress(compressed).length); // 64 Bytes
* ```
*
* @param input Input data.
*/
export function decompress(input: Uint8Array): Uint8Array {
return lz4_decompress(input);
}