11cb0ef41Sopenharmony_ci// Flags: --no-warnings 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst common = require('../common'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst { 71cb0ef41Sopenharmony_ci CompressionStream, 81cb0ef41Sopenharmony_ci DecompressionStream, 91cb0ef41Sopenharmony_ci} = require('stream/web'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst assert = require('assert'); 121cb0ef41Sopenharmony_ciconst dec = new TextDecoder(); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciasync function test(format) { 151cb0ef41Sopenharmony_ci const gzip = new CompressionStream(format); 161cb0ef41Sopenharmony_ci const gunzip = new DecompressionStream(format); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci gzip.readable.pipeTo(gunzip.writable).then(common.mustCall()); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci const reader = gunzip.readable.getReader(); 211cb0ef41Sopenharmony_ci const writer = gzip.writable.getWriter(); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci const compressed_data = []; 241cb0ef41Sopenharmony_ci const reader_function = ({ value, done }) => { 251cb0ef41Sopenharmony_ci if (value) 261cb0ef41Sopenharmony_ci compressed_data.push(value); 271cb0ef41Sopenharmony_ci if (!done) 281cb0ef41Sopenharmony_ci return reader.read().then(reader_function); 291cb0ef41Sopenharmony_ci assert.strictEqual(dec.decode(Buffer.concat(compressed_data)), 'hello'); 301cb0ef41Sopenharmony_ci }; 311cb0ef41Sopenharmony_ci const reader_promise = reader.read().then(reader_function); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci await Promise.all([ 341cb0ef41Sopenharmony_ci reader_promise, 351cb0ef41Sopenharmony_ci reader_promise.then(() => reader.read().then(({ done }) => assert(done))), 361cb0ef41Sopenharmony_ci writer.write('hello'), 371cb0ef41Sopenharmony_ci writer.close(), 381cb0ef41Sopenharmony_ci ]); 391cb0ef41Sopenharmony_ci} 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciPromise.all(['gzip', 'deflate'].map((i) => test(i))).then(common.mustCall()); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci[1, 'hello', false, {}].forEach((i) => { 441cb0ef41Sopenharmony_ci assert.throws(() => new CompressionStream(i), { 451cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE', 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci assert.throws(() => new DecompressionStream(i), { 481cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE', 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci}); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciassert.throws( 531cb0ef41Sopenharmony_ci () => Reflect.get(CompressionStream.prototype, 'readable', {}), { 541cb0ef41Sopenharmony_ci code: 'ERR_INVALID_THIS', 551cb0ef41Sopenharmony_ci }); 561cb0ef41Sopenharmony_ciassert.throws( 571cb0ef41Sopenharmony_ci () => Reflect.get(CompressionStream.prototype, 'writable', {}), { 581cb0ef41Sopenharmony_ci code: 'ERR_INVALID_THIS', 591cb0ef41Sopenharmony_ci }); 601cb0ef41Sopenharmony_ciassert.throws( 611cb0ef41Sopenharmony_ci () => Reflect.get(DecompressionStream.prototype, 'readable', {}), { 621cb0ef41Sopenharmony_ci code: 'ERR_INVALID_THIS', 631cb0ef41Sopenharmony_ci }); 641cb0ef41Sopenharmony_ciassert.throws( 651cb0ef41Sopenharmony_ci () => Reflect.get(DecompressionStream.prototype, 'writable', {}), { 661cb0ef41Sopenharmony_ci code: 'ERR_INVALID_THIS', 671cb0ef41Sopenharmony_ci }); 68