node/test/parallel/test-zlib-write-after-flush.js
Jan Krems bf12d72faa
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
zlib: add zstd support
Fixes: https://github.com/nodejs/node/issues/48412
PR-URL: https://github.com/nodejs/node/pull/52100
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2025-02-08 12:43:53 +00:00

60 lines
2.1 KiB
JavaScript

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const assert = require('node:assert');
const zlib = require('node:zlib');
const { test } = require('node:test');
test('zlib should accept writing after flush', async () => {
for (const [ createCompress, createDecompress ] of [
[ zlib.createGzip, zlib.createGunzip ],
[ zlib.createBrotliCompress, zlib.createBrotliDecompress ],
[ zlib.createZstdCompress, zlib.createZstdDecompress ],
]) {
const { promise, resolve, reject } = Promise.withResolvers();
const gzip = createCompress();
const gunz = createDecompress();
gzip.pipe(gunz);
let output = '';
const input = 'A line of data\n';
gunz.setEncoding('utf8');
gunz.on('error', reject);
gunz.on('data', (c) => output += c);
gunz.on('end', () => {
assert.strictEqual(output, input);
resolve();
});
// Make sure that flush/write doesn't trigger an assert failure
gzip.flush();
gzip.write(input);
gzip.end();
gunz.read(0);
await promise;
}
});