-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_zlib_async.js
More file actions
66 lines (55 loc) · 1.65 KB
/
test_zlib_async.js
File metadata and controls
66 lines (55 loc) · 1.65 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
import zlib from 'node:zlib';
const input = new Uint8Array(2000);
for (let i = 0; i < input.length; i++) {
input[i] = (i % 256);
}
console.log('--- Zlib Async Test ---');
let completed = 0;
const total = 7;
function check(name, inflated) {
let pass = inflated.length === input.length;
for (let i = 0; i < input.length; i++) {
if (inflated[i] !== input[i]) {
pass = false;
break;
}
}
console.log(`${name}: ${pass ? 'PASS' : 'FAIL'}`);
completed++;
}
zlib.deflate(input, (err, deflated) => {
if (err) console.error(err);
zlib.inflate(deflated, (err, inflated) => {
check('Deflate/Inflate', inflated);
});
});
zlib.gzip(input, (err, gzipped) => {
zlib.gunzip(gzipped, (err, gunzipped) => {
check('Gzip/Gunzip', gunzipped);
});
});
zlib.deflateRaw(input, (err, raw) => {
zlib.inflateRaw(raw, (err, inflated) => {
check('DeflateRaw/InflateRaw', inflated);
});
});
zlib.deflate(input, (err, deflated) => {
zlib.unzip(deflated, (err, unzipped) => {
check('Unzip (zlib)', unzipped);
});
});
zlib.gzip(input, (err, gzipped) => {
zlib.unzip(gzipped, (err, unzipped) => {
check('Unzip (gzip)', unzipped);
});
});
// Test some error cases
zlib.inflate(new Uint8Array([1, 2, 3]), (err, result) => {
console.log('Error test (invalid data):', err ? 'PASS (caught error)' : 'FAIL');
completed++;
});
// Test unzip error
zlib.unzip(new Uint8Array([1, 2, 3]), (err, result) => {
console.log('Error test (unzip):', err ? 'PASS (caught error)' : 'FAIL');
completed++;
});