mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00

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
Fixes: https://github.com/nodejs/node/issues/48412 PR-URL: https://github.com/nodejs/node/pull/52100 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const zlib = require('zlib');
|
|
|
|
function compressWithPledgedSrcSize({ pledgedSrcSize, actualSrcSize }) {
|
|
return new Promise((resolve, reject) => {
|
|
const compressor = zlib.createZstdCompress({ pledgedSrcSize });
|
|
compressor.on('error', (e) => {
|
|
reject(e);
|
|
});
|
|
compressor.on('end', resolve);
|
|
compressor.write('x'.repeat(actualSrcSize), () => {
|
|
compressor.end();
|
|
compressor.resume();
|
|
});
|
|
}).then(() => {
|
|
// Compression should only succeed if sizes match
|
|
assert.strictEqual(pledgedSrcSize, actualSrcSize);
|
|
}, (error) => {
|
|
assert.strictEqual(error.code, 'ZSTD_error_srcSize_wrong');
|
|
// Size error should only happen when sizes do not match
|
|
assert.notStrictEqual(pledgedSrcSize, actualSrcSize);
|
|
}).then(common.mustCall());
|
|
}
|
|
|
|
compressWithPledgedSrcSize({ pledgedSrcSize: 0, actualSrcSize: 0 });
|
|
|
|
compressWithPledgedSrcSize({ pledgedSrcSize: 0, actualSrcSize: 42 });
|
|
|
|
compressWithPledgedSrcSize({ pledgedSrcSize: 13, actualSrcSize: 42 });
|
|
|
|
compressWithPledgedSrcSize({ pledgedSrcSize: 42, actualSrcSize: 0 });
|
|
|
|
compressWithPledgedSrcSize({ pledgedSrcSize: 42, actualSrcSize: 13 });
|
|
|
|
compressWithPledgedSrcSize({ pledgedSrcSize: 42, actualSrcSize: 42 });
|