aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-zlib-write-after-flush.js
blob: 89edaf93043d88227323b87b6cbadfb4ab88c54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
require('../common');
const assert = require('assert');
const zlib = require('zlib');

const gzip = zlib.createGzip();
const gunz = zlib.createUnzip();

gzip.pipe(gunz);

var output = '';
const input = 'A line of data\n';
gunz.setEncoding('utf8');
gunz.on('data', function(c) {
  output += c;
});

process.on('exit', function() {
  assert.equal(output, input);

  // Make sure that the flush flag was set back to normal
  assert.equal(gzip._flushFlag, zlib.constants.Z_NO_FLUSH);

  console.log('ok');
});

// make sure that flush/write doesn't trigger an assert failure
gzip.flush(); write();
function write() {
  gzip.write(input);
  gzip.end();
  gunz.read(0);
}