11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst zlib = require('zlib'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst input = '0123456789'.repeat(4); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cifor (const [ compress, decompressor ] of [ 91cb0ef41Sopenharmony_ci [ zlib.deflateRawSync, zlib.createInflateRaw ], 101cb0ef41Sopenharmony_ci [ zlib.deflateSync, zlib.createInflate ], 111cb0ef41Sopenharmony_ci [ zlib.brotliCompressSync, zlib.createBrotliDecompress ], 121cb0ef41Sopenharmony_ci]) { 131cb0ef41Sopenharmony_ci const compressed = compress(input); 141cb0ef41Sopenharmony_ci const trailingData = Buffer.from('not valid compressed data'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci for (const variant of [ 171cb0ef41Sopenharmony_ci (stream) => { stream.end(compressed); }, 181cb0ef41Sopenharmony_ci (stream) => { stream.write(compressed); stream.write(trailingData); }, 191cb0ef41Sopenharmony_ci (stream) => { stream.write(compressed); stream.end(trailingData); }, 201cb0ef41Sopenharmony_ci (stream) => { stream.write(Buffer.concat([compressed, trailingData])); }, 211cb0ef41Sopenharmony_ci (stream) => { stream.end(Buffer.concat([compressed, trailingData])); }, 221cb0ef41Sopenharmony_ci ]) { 231cb0ef41Sopenharmony_ci let output = ''; 241cb0ef41Sopenharmony_ci const stream = decompressor(); 251cb0ef41Sopenharmony_ci stream.setEncoding('utf8'); 261cb0ef41Sopenharmony_ci stream.on('data', (chunk) => output += chunk); 271cb0ef41Sopenharmony_ci stream.on('end', common.mustCall(() => { 281cb0ef41Sopenharmony_ci assert.strictEqual(output, input); 291cb0ef41Sopenharmony_ci assert.strictEqual(stream.bytesWritten, compressed.length); 301cb0ef41Sopenharmony_ci })); 311cb0ef41Sopenharmony_ci variant(stream); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci} 34