mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 03:05:55 +00:00

This is similar to https://github.com/nodejs/node/pull/44117 and addresses the indeterminate nature of the hardware accelerated compression. PR-URL: https://github.com/nodejs/node/pull/46367 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
// 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);
|
|
|
|
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'].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', {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
assert.throws(
|
|
() => Reflect.get(CompressionStream.prototype, 'writable', {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
assert.throws(
|
|
() => Reflect.get(DecompressionStream.prototype, 'readable', {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
assert.throws(
|
|
() => Reflect.get(DecompressionStream.prototype, 'writable', {}), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|