ts-zstd
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

TypeScript zstd

TypeScript functions for reading/writing Zstd compressed files. Includes Zstd binaries for Linux, Windows, and Mac OSX.

Compression

The compress function takes a path to an input and output file destination. The optional third parameter specifies the compression level, between 1 and 22.

import { compress } from 'ts-zstd'

async function main() {
	await compress('/path/to/input.zstd', '/path/to/output')
	await compress('/path/to/input.zstd', '/path/to/output', 20)
}

Decompression

The decompress, streamDecompress, and decompressToStream functions provide the option to decompress an entire file into a target directory, or stream the contents of the compressed file in memory for processing.

import { decompress, streamDecompress } from 'ts-zstd'

async function main() {
	await decompress('/path/to/input.zstd', '/path/to/output')

	// Read the input
	const stream = await streamDecompress('/path/to/input.zstd')
	stream.on('data', (data: Buffer) => {
		console.log(data.toString())
	})
	stream.on('error', (error) => {
		console.error(error)
	})
	stream.on('end', () => {
		console.log('Done reading compressed file')
	})
}

Author

Keshav Saharia created this for reading Lichess PGN files.

Readme

Keywords

Package Sidebar

Install

npm i ts-zstd

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

2.56 MB

Total Files

26

Last publish

Collaborators

  • keshavsaharia