Skip to content

SukkaW/zstd-size

Repository files navigation

zstd-size

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.

Install

npm install zstd-size
yarn add zstd-size
pnpm add zstd-size

Usage

import { 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));
//=> 133

API

size(input, options?)

Returns a Promise<number> with the compressed size.

sync(input, options?)

Returns the compressed size.

  • input: string | Buffer
  • options:

file(path, options?)

Returns a Promise<number> with the compressed size of the file.

  • path: string

fileSync(path, options?)

Returns the compressed size of the file.

  • path: string

stream(options?)

Returns a stream.Transform. The stream emits a zstd-size event and has a zstdSize property.

License

MIT


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

About

Get the zstd compressed size of a string or buffer.

Topics

Resources

License

Stars

4 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors