MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-whatwg-webstreams-compression.js:14–42  ·  view source on GitHub ↗
(format)

Source from the content-addressed store, hash-verified

12const dec = new TextDecoder();
13
14async function test(format) {
15 const gzip = new CompressionStream(format);
16 const gunzip = new DecompressionStream(format);
17
18 assert.strictEqual(gzip[Symbol.toStringTag], 'CompressionStream');
19 assert.strictEqual(gunzip[Symbol.toStringTag], 'DecompressionStream');
20
21 gzip.readable.pipeTo(gunzip.writable).then(common.mustCall());
22
23 const reader = gunzip.readable.getReader();
24 const writer = gzip.writable.getWriter();
25
26 const compressed_data = [];
27 const reader_function = common.mustCallAtLeast(({ value, done }) => {
28 if (value)
29 compressed_data.push(value);
30 if (!done)
31 return reader.read().then(reader_function);
32 assert.strictEqual(dec.decode(Buffer.concat(compressed_data)), 'hello');
33 });
34 const reader_promise = reader.read().then(reader_function);
35
36 await Promise.all([
37 reader_promise,
38 reader_promise.then(() => reader.read().then(({ done }) => assert(done))),
39 writer.write('hello'),
40 writer.close(),
41 ]);
42}
43
44Promise.all(['gzip', 'deflate', 'deflate-raw', 'brotli'].map((i) => test(i))).then(common.mustCall());
45

Calls 12

getReaderMethod · 0.80
getWriterMethod · 0.80
concatMethod · 0.80
allMethod · 0.80
decodeMethod · 0.65
closeMethod · 0.65
assertFunction · 0.50
thenMethod · 0.45
pipeToMethod · 0.45
pushMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…