mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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>
This commit is contained in:
parent
f5353100be
commit
bf12d72faa
22 changed files with 997 additions and 21 deletions
|
@ -5,7 +5,7 @@ const zlib = require('zlib');
|
|||
const bench = common.createBenchmark(main, {
|
||||
type: [
|
||||
'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip',
|
||||
'BrotliCompress', 'BrotliDecompress',
|
||||
'BrotliCompress', 'BrotliDecompress', 'ZstdCompress', 'ZstdDecompress',
|
||||
],
|
||||
options: ['true', 'false'],
|
||||
n: [5e5],
|
||||
|
|
|
@ -7,7 +7,7 @@ const bench = common.createBenchmark(main, {
|
|||
inputLen: [1024],
|
||||
duration: [5],
|
||||
type: ['string', 'buffer'],
|
||||
algorithm: ['gzip', 'brotli'],
|
||||
algorithm: ['gzip', 'brotli', 'zstd'],
|
||||
}, {
|
||||
test: {
|
||||
inputLen: 1024,
|
||||
|
@ -15,14 +15,19 @@ const bench = common.createBenchmark(main, {
|
|||
},
|
||||
});
|
||||
|
||||
const algorithms = {
|
||||
'gzip': [zlib.createGzip, zlib.createGunzip],
|
||||
'brotli': [zlib.createBrotliCompress, zlib.createBrotliDecompress],
|
||||
'zstd': [zlib.createZstdCompress, zlib.createZstdDecompress],
|
||||
};
|
||||
|
||||
function main({ inputLen, duration, type, algorithm }) {
|
||||
const buffer = Buffer.alloc(inputLen, fs.readFileSync(__filename));
|
||||
const chunk = type === 'buffer' ? buffer : buffer.toString('utf8');
|
||||
|
||||
const input = algorithm === 'gzip' ?
|
||||
zlib.createGzip() : zlib.createBrotliCompress();
|
||||
const output = algorithm === 'gzip' ?
|
||||
zlib.createGunzip() : zlib.createBrotliDecompress();
|
||||
const [createCompress, createUncompress] = algorithms[algorithm];
|
||||
const input = createCompress();
|
||||
const output = createUncompress();
|
||||
|
||||
let readFromOutput = 0;
|
||||
input.pipe(output);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue