Get the zstd compressed size of a string or buffer
Uses Node.js built-in node:zlib zstd support (Requires Node.js >= 22.15.0 (LTS) or >= 23.8.0), zero dependencies.
npm install zstd-size
yarn add zstd-size
pnpm add zstd-sizeimport { size, sync } from 'zstd-size';
const text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.';
console.log(text.length);
//=> 191
console.log(sync(text));
//=> 133Returns a Promise<number> with the compressed size.
Returns the compressed size.
- input:
string | Buffer - options:
- level:
number, default to3(ZSTD_CLEVEL_DEFAULT). Compression level (1-22). - strategy:
number. Zstd compression strategy.
- level:
Returns a Promise<number> with the compressed size of the file.
- path:
string
Returns the compressed size of the file.
- path:
string
Returns a stream.Transform. The stream emits a zstd-size event and has a zstdSize property.
zstd-size © Sukka, Released under the MIT License. Authored and maintained by Sukka with help from contributors (list).
Personal Website · Blog · GitHub @SukkaW · Telegram Channel @SukkaChannel · Mastodon @sukka@acg.mn · Twitter @isukkaw · BlueSky @skk.moe