| 
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE.  | 
21 | 21 | 
 
  | 
22 | 22 | 'use strict';  | 
23 |  | -const common = require('../common');  | 
24 |  | -const assert = require('assert');  | 
25 |  | -const zlib = require('zlib');  | 
26 | 23 | 
 
  | 
27 |  | -for (const [ createCompress, createDecompress ] of [  | 
28 |  | -  [ zlib.createGzip, zlib.createGunzip ],  | 
29 |  | -  [ zlib.createBrotliCompress, zlib.createBrotliDecompress ],  | 
30 |  | -]) {  | 
31 |  | -  const gzip = createCompress();  | 
32 |  | -  const gunz = createDecompress();  | 
 | 24 | +require('../common');  | 
33 | 25 | 
 
  | 
34 |  | -  gzip.pipe(gunz);  | 
 | 26 | +const assert = require('node:assert');  | 
 | 27 | +const zlib = require('node:zlib');  | 
 | 28 | +const { test } = require('node:test');  | 
35 | 29 | 
 
  | 
36 |  | -  let output = '';  | 
37 |  | -  const input = 'A line of data\n';  | 
38 |  | -  gunz.setEncoding('utf8');  | 
39 |  | -  gunz.on('data', (c) => output += c);  | 
40 |  | -  gunz.on('end', common.mustCall(() => {  | 
41 |  | -    assert.strictEqual(output, input);  | 
42 |  | -  }));  | 
 | 30 | +test('zlib should accept writing after flush', async () => {  | 
 | 31 | +  for (const [createCompress, createDecompress] of [  | 
 | 32 | +    [zlib.createGzip, zlib.createGunzip],  | 
 | 33 | +    [zlib.createBrotliCompress, zlib.createBrotliDecompress],  | 
 | 34 | +  ]) {  | 
 | 35 | +    const { promise, resolve, reject } = Promise.withResolvers();  | 
 | 36 | +    const gzip = createCompress();  | 
 | 37 | +    const gunz = createDecompress();  | 
43 | 38 | 
 
  | 
44 |  | -  // Make sure that flush/write doesn't trigger an assert failure  | 
45 |  | -  gzip.flush();  | 
46 |  | -  gzip.write(input);  | 
47 |  | -  gzip.end();  | 
48 |  | -  gunz.read(0);  | 
49 |  | -}  | 
 | 39 | +    gzip.pipe(gunz);  | 
 | 40 | + | 
 | 41 | +    let output = '';  | 
 | 42 | +    const input = 'A line of data\n';  | 
 | 43 | +    gunz.setEncoding('utf8');  | 
 | 44 | +    gunz.on('error', reject);  | 
 | 45 | +    gunz.on('data', (c) => output += c);  | 
 | 46 | +    gunz.on('end', () => {  | 
 | 47 | +      assert.strictEqual(output, input);  | 
 | 48 | +      resolve();  | 
 | 49 | +    });  | 
 | 50 | + | 
 | 51 | +    // Make sure that flush/write doesn't trigger an assert failure  | 
 | 52 | +    gzip.flush();  | 
 | 53 | +    gzip.write(input);  | 
 | 54 | +    gzip.end();  | 
 | 55 | +    gunz.read(0);  | 
 | 56 | +    await promise;  | 
 | 57 | +  }  | 
 | 58 | +});  | 
0 commit comments