11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst zlib = require('zlib'); 51cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst file = fixtures.readSync('person.jpg'); 81cb0ef41Sopenharmony_ciconst chunkSize = 16; 91cb0ef41Sopenharmony_ciconst opts = { level: 0 }; 101cb0ef41Sopenharmony_ciconst deflater = zlib.createDeflate(opts); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst chunk = file.slice(0, chunkSize); 131cb0ef41Sopenharmony_ciconst expectedNone = Buffer.from([0x78, 0x01]); 141cb0ef41Sopenharmony_ciconst blkhdr = Buffer.from([0x00, 0x10, 0x00, 0xef, 0xff]); 151cb0ef41Sopenharmony_ciconst adler32 = Buffer.from([0x00, 0x00, 0x00, 0xff, 0xff]); 161cb0ef41Sopenharmony_ciconst expectedFull = Buffer.concat([blkhdr, chunk, adler32]); 171cb0ef41Sopenharmony_cilet actualNone; 181cb0ef41Sopenharmony_cilet actualFull; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cideflater.write(chunk, function() { 211cb0ef41Sopenharmony_ci deflater.flush(zlib.constants.Z_NO_FLUSH, function() { 221cb0ef41Sopenharmony_ci actualNone = deflater.read(); 231cb0ef41Sopenharmony_ci deflater.flush(function() { 241cb0ef41Sopenharmony_ci const bufs = []; 251cb0ef41Sopenharmony_ci let buf; 261cb0ef41Sopenharmony_ci while ((buf = deflater.read()) !== null) 271cb0ef41Sopenharmony_ci bufs.push(buf); 281cb0ef41Sopenharmony_ci actualFull = Buffer.concat(bufs); 291cb0ef41Sopenharmony_ci }); 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci}); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciprocess.once('exit', function() { 341cb0ef41Sopenharmony_ci assert.deepStrictEqual(actualNone, expectedNone); 351cb0ef41Sopenharmony_ci assert.deepStrictEqual(actualFull, expectedFull); 361cb0ef41Sopenharmony_ci}); 37