# xz

> node bindings for the xz compression library

Latest version **2.0.2** (published 2019-10-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install xz
pnpm add xz
yarn add xz
bun add xz
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2019-10-29 |
| First published | 2014-07-29 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Robey Pointer |
| Maintainers | robey |
| Keywords | compression, xz |

## Links

- npm: https://www.npmjs.com/package/xz
- Repository: https://github.com/robey/node-xz
- Issues: https://github.com/robey/node-xz/issues
- npm.io page: https://npm.io/package/xz

## Dependencies (1)

- [node-addon-api](https://npm.io/package/node-addon-api.md) ^1.6.1

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.0.2 (latest) — 2019-10-29
- 2.0.1 — 2019-07-16
- 2.0.0 — 2018-12-17
- 1.4.0 — 2018-11-30
- 1.3.0 — 2018-11-17
- 1.2.2 — 2016-05-07
- 1.2.1 — 2015-12-26
- 1.2.0 — 2015-08-21
- 1.1.1 — 2015-02-08
- 1.0.4 — 2014-12-08
- 1.0.3 — 2014-09-04
- 1.0.2 — 2014-09-04
- 1.0.1 — 2014-07-29
- 1.0.0 — 2014-07-29

## README

# xz

[![Build Status](https://travis-ci.org/robey/node-xz.png?branch=master)](https://travis-ci.org/robey/node-xz)

Xz is the node binding for the xz library, which implements (streaming) LZMA2 compression. It consists of a very thin binding around liblzma, and wrapper javascript classes to implement the nodejs "stream" transform interface. Typescript definitions are included.

LZMA2 is better than gzip & bzip2 in many cases. Read more about LZMA here: http://en.wikipedia.org/wiki/Lempel-Ziv-Markov_chain_algorithm


## Install

```sh
$ npm install
$ npm test
```


## API

The API consists of only two stream transform classes: `Compressor` and `Decompressor`.

- `new xz.Compressor(options?: XzTransformOptions)`
- `new xz.Decompressor(options?: XzTransformOptions)`

The options object is passed to node's `Transform`, and has two additional optional fields:

- `preset: number`: an abstraction of the compression difficulty level, from 1 to 9, where 1 puts in the least effort. The default is 6.
- `bufferSize: number`: minimum buffer size to use for encoding/decoding blocks of data. The default is 1KB, but it will grow to match the block size of its input as it processes data. (You shouldn't normally need to care about this.)

Both objects are stream transforms that consume and produce Buffers. Here's example code to compress the sample file included with this distribution:

```javascript
var fs = require("fs");
var xz = require("xz");

var compression = new xz.Compressor(9);
var inFile = fs.createReadStream("./testdata/minecraft.png");
var outFile = fs.createWriteStream("./testdata/minecraft.png.lzma2");

inFile.pipe(compression).pipe(outFile);
```


## Non-streaming API

If you aren't using nodejs streams, an API similar to the crypto API is available on both `Compressor` and `Decompressor`:

- `update(input: Buffer, callback: (error?: Error, output?: Buffer) => void)`
- `final(callback: (error?: Error, output?: Buffer) => void)`

A promise-based API is also available:

- `updatePromise(input: Buffer): Promise<Buffer>`
- `finalPromise(): Promise<Buffer>`

Each method feeds a `Buffer` into the lzma2 engine, which may be executed on a separate core (asynchronously). The returned `Buffer` may have a length of 0: lzma2 keeps a large internal buffer while compressing, so it's common to receive empty `Buffer`s while you compress, followed by a large final `Buffer` when you end the stream with `final`.


## License

Apache 2 (open-source) license, included in 'LICENSE.txt'.


## Authors

- @robey - Robey Pointer <robeypointer@gmail.com>

---
_Source: https://npm.io/package/xz · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
