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 = 12 * 1024;
91cb0ef41Sopenharmony_ciconst opts = { level: 9, strategy: zlib.constants.Z_DEFAULT_STRATEGY };
101cb0ef41Sopenharmony_ciconst deflater = zlib.createDeflate(opts);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst chunk1 = file.slice(0, chunkSize);
131cb0ef41Sopenharmony_ciconst chunk2 = file.slice(chunkSize);
141cb0ef41Sopenharmony_ciconst blkhdr = Buffer.from([0x00, 0x5a, 0x82, 0xa5, 0x7d]);
151cb0ef41Sopenharmony_ciconst blkftr = Buffer.from('010000ffff7dac3072', 'hex');
161cb0ef41Sopenharmony_ciconst expected = Buffer.concat([blkhdr, chunk2, blkftr]);
171cb0ef41Sopenharmony_ciconst bufs = [];
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction read() {
201cb0ef41Sopenharmony_ci  let buf;
211cb0ef41Sopenharmony_ci  while ((buf = deflater.read()) !== null) {
221cb0ef41Sopenharmony_ci    bufs.push(buf);
231cb0ef41Sopenharmony_ci  }
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cideflater.write(chunk1, function() {
271cb0ef41Sopenharmony_ci  deflater.params(0, zlib.constants.Z_DEFAULT_STRATEGY, function() {
281cb0ef41Sopenharmony_ci    while (deflater.read());
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci    deflater.on('readable', read);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci    deflater.end(chunk2);
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci  while (deflater.read());
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciprocess.once('exit', function() {
381cb0ef41Sopenharmony_ci  const actual = Buffer.concat(bufs);
391cb0ef41Sopenharmony_ci  assert.deepStrictEqual(actual, expected);
401cb0ef41Sopenharmony_ci});
41