+3
deno.json
+3
deno.json
+23
deno.lock
+23
deno.lock
···
1
+
{
2
+
"version": "4",
3
+
"specifiers": {
4
+
"jsr:@std/assert@^1.0.12": "1.0.12",
5
+
"jsr:@std/internal@^1.0.6": "1.0.6"
6
+
},
7
+
"jsr": {
8
+
"@std/assert@1.0.12": {
9
+
"integrity": "08009f0926dda9cbd8bef3a35d3b6a4b964b0ab5c3e140a4e0351fbf34af5b9a",
10
+
"dependencies": [
11
+
"jsr:@std/internal"
12
+
]
13
+
},
14
+
"@std/internal@1.0.6": {
15
+
"integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4"
16
+
}
17
+
},
18
+
"workspace": {
19
+
"dependencies": [
20
+
"jsr:@std/assert@^1.0.12"
21
+
]
22
+
}
23
+
}
+66
lib/mod.test.ts
+66
lib/mod.test.ts
···
1
+
import { assertEquals } from '@std/assert';
2
+
3
+
import { MaybeDecompressionStream } from './mod.ts';
4
+
5
+
Deno.test({
6
+
name: 'decompresses a gzip stream',
7
+
async fn() {
8
+
const { readable, writable } = new MaybeDecompressionStream();
9
+
10
+
{
11
+
const writer = writable.getWriter();
12
+
13
+
// deno-fmt-ignore
14
+
writer.write(
15
+
new Uint8Array([
16
+
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 242, 72, 205, 201, 201, 215, 81,
17
+
40, 207, 47, 202, 73, 81, 4, 0, 0, 0, 255, 255, 3, 0, 230, 198, 230,
18
+
235, 13, 0, 0, 0,
19
+
]),
20
+
);
21
+
22
+
writer.close();
23
+
}
24
+
25
+
{
26
+
let buffer = new Uint8Array(0);
27
+
for await (const chunk of readable) {
28
+
const concat = new Uint8Array(buffer.length + chunk.length);
29
+
concat.set(buffer);
30
+
concat.set(chunk, buffer.length);
31
+
buffer = concat;
32
+
}
33
+
34
+
const decoded = new TextDecoder().decode(buffer);
35
+
36
+
assertEquals(decoded, 'Hello, world!');
37
+
}
38
+
},
39
+
});
40
+
41
+
Deno.test({
42
+
name: 'passthroughs a non-gzip stream',
43
+
async fn() {
44
+
const { readable, writable } = new MaybeDecompressionStream();
45
+
46
+
const input = new Uint8Array([1, 2, 3, 4, 5]);
47
+
48
+
{
49
+
const writer = writable.getWriter();
50
+
writer.write(input);
51
+
writer.close();
52
+
}
53
+
54
+
{
55
+
let buffer = new Uint8Array(0);
56
+
for await (const chunk of readable) {
57
+
const concat = new Uint8Array(buffer.length + chunk.length);
58
+
concat.set(buffer);
59
+
concat.set(chunk, buffer.length);
60
+
buffer = concat;
61
+
}
62
+
63
+
assertEquals(buffer, input);
64
+
}
65
+
},
66
+
});