|
| 1 | +# node-liblzma |
| 2 | + |
| 3 | +> Node.js bindings for liblzma (XZ/LZMA2 compression). Provides streaming |
| 4 | +> and buffer APIs compatible with zlib, plus a portable CLI tool (nxz). |
| 5 | +> Supports prebuilt binaries for Linux, macOS, and Windows. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install node-liblzma |
| 11 | +``` |
| 12 | + |
| 13 | +## Key APIs |
| 14 | + |
| 15 | +- [Streaming API](https://github.com/oorabona/node-liblzma#streaming-api): `createXz()`, `createUnxz()` - zlib-compatible transform streams |
| 16 | +- [Buffer API](https://github.com/oorabona/node-liblzma#buffer-api): `xz()`, `unxz()`, `xzSync()`, `unxzSync()` - callback and sync variants |
| 17 | +- [Promise API](https://github.com/oorabona/node-liblzma#promise-api): `xzAsync()`, `unxzAsync()` - modern async/await support |
| 18 | +- [File API](https://github.com/oorabona/node-liblzma#file-api): `xzFile()`, `unxzFile()` - compress/decompress files directly |
| 19 | +- [Utility API](https://github.com/oorabona/node-liblzma#utility-functions): `isXZ()`, `parseFileIndex()`, `versionString()` - format detection and metadata |
| 20 | + |
| 21 | +## CLI Tool (nxz) |
| 22 | + |
| 23 | +Portable xz-like command line tool included in the package: |
| 24 | + |
| 25 | +```bash |
| 26 | +npx node-liblzma file.txt # compress |
| 27 | +npx node-liblzma -d file.xz # decompress |
| 28 | +npx node-liblzma -l file.xz # list info |
| 29 | +npx node-liblzma -9e large.bin # max compression |
| 30 | +``` |
| 31 | + |
| 32 | +Options: `-z` compress, `-d` decompress, `-l` list, `-k` keep, `-f` force, `-c` stdout, `-o FILE` output, `-0`.`-9` preset, `-e` extreme, `-v` verbose, `-q` quiet |
| 33 | + |
| 34 | +## Documentation |
| 35 | + |
| 36 | +- [README](https://github.com/oorabona/node-liblzma#readme): Quick start and examples |
| 37 | +- [TypeDoc API Reference](https://oorabona.github.io/node-liblzma/): Full API documentation |
| 38 | +- [Migration from zlib](https://github.com/oorabona/node-liblzma#compatibility-with-zlib): Drop-in replacement guide |
| 39 | + |
| 40 | +## Quick Examples |
| 41 | + |
| 42 | +```typescript |
| 43 | +import { xzAsync, unxzAsync, createXz } from 'node-liblzma'; |
| 44 | + |
| 45 | +// Buffer API |
| 46 | +const compressed = await xzAsync(Buffer.from('Hello World')); |
| 47 | +const original = await unxzAsync(compressed); |
| 48 | + |
| 49 | +// Streaming API |
| 50 | +import { createReadStream, createWriteStream } from 'fs'; |
| 51 | +createReadStream('input.txt') |
| 52 | + .pipe(createXz()) |
| 53 | + .pipe(createWriteStream('output.xz')); |
| 54 | +``` |
| 55 | + |
| 56 | +## Optional |
| 57 | + |
| 58 | +- [Contributing Guide](https://github.com/oorabona/node-liblzma/blob/master/CONTRIBUTING.md): How to contribute |
| 59 | +- [Changelog](https://github.com/oorabona/node-liblzma/blob/master/CHANGELOG.md): Version history |
| 60 | +- [Benchmark](https://github.com/oorabona/node-liblzma#benchmark): Performance comparison with native xz |
| 61 | +- [License](https://github.com/oorabona/node-liblzma/blob/master/LICENSE): LGPL-3.0 |
0 commit comments