-
Notifications
You must be signed in to change notification settings - Fork 30.2k
/
Copy pathtest-whatwg-webstreams-compression.js
74 lines (62 loc) · 2.06 KB
/
test-whatwg-webstreams-compression.js
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
67
68
69
70
71
72
73
74
// Flags: --no-warnings
'use strict';
const common = require('../common');
const {
CompressionStream,
DecompressionStream,
} = require('stream/web');
const assert = require('assert');
const dec = new TextDecoder();
async function test(format) {
const gzip = new CompressionStream(format);
const gunzip = new DecompressionStream(format);
assert.strictEqual(gzip[Symbol.toStringTag], 'CompressionStream');
assert.strictEqual(gunzip[Symbol.toStringTag], 'DecompressionStream');
gzip.readable.pipeTo(gunzip.writable).then(common.mustCall());
const reader = gunzip.readable.getReader();
const writer = gzip.writable.getWriter();
const compressed_data = [];
const reader_function = ({ value, done }) => {
if (value)
compressed_data.push(value);
if (!done)
return reader.read().then(reader_function);
assert.strictEqual(dec.decode(Buffer.concat(compressed_data)), 'hello');
};
const reader_promise = reader.read().then(reader_function);
await Promise.all([
reader_promise,
reader_promise.then(() => reader.read().then(({ done }) => assert(done))),
writer.write('hello'),
writer.close(),
]);
}
Promise.all(['gzip', 'deflate', 'deflate-raw'].map((i) => test(i))).then(common.mustCall());
[1, 'hello', false, {}].forEach((i) => {
assert.throws(() => new CompressionStream(i), {
code: 'ERR_INVALID_ARG_VALUE',
});
assert.throws(() => new DecompressionStream(i), {
code: 'ERR_INVALID_ARG_VALUE',
});
});
assert.throws(
() => Reflect.get(CompressionStream.prototype, 'readable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(CompressionStream.prototype, 'writable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(DecompressionStream.prototype, 'readable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});
assert.throws(
() => Reflect.get(DecompressionStream.prototype, 'writable', {}), {
name: 'TypeError',
message: /Cannot read private member/,
});