lzg is library and command line tool to compress and decompress files and streams using LZG compression algorithm
LZG algorithm is a minimal implementation of an LZ77 class compression. The main characteristic of the algorithm is that the decoding routine is very simple, fast, and requires no memory.
In general, lzg does not compress as well as zlib, for instance. On the other hand the decoder is very simple and very fast - ideal for systems with tight memory limits or limited processing capabilities, including in-browser by pure JavaScript.
Compressed files can be easily decompresed in-browser with very low-footprint lzgmini decompressor: https://github.com/mbitsnbites/liblzg/tree/master/src/extra/lzgmini.js
This Node.JS module is based on original C implementation of liblzg (ver. 1.0.10) by Marcus Geelnard
- install Node.JS (if not already installed)
- from command line execute:
$ npm install -g lzg
Compression
$ lzg [options] <originalFile> <compressedFile>
Decompression
$ lzg -d <compressedFile> <decompressedFile>
For full list of supported options execute:
$ lzg -h
All options are optional. When not specified, they are ignored or have default value. Boolean options are true if flag is present, false otherwise.
Option | Type | Default value |
---|---|---|
-d , --decompress |
Boolean |
false |
-l , --level |
Integer [1..9] |
9 |
-v , --verbose |
Boolean |
false |
-h , --help |
Boolean |
|
-V , --version |
Boolean |
When this flag is given, tool decompress input file otherwise (by default, without flag) tool compresses input file to output file.
Specifies compression level, integer between 1 and 9 1 is the fastest but weakest and 9 is the best but slowest
When given, additional debug information are displayed on console
Displays all options with short description.
Displays version of application (match NPM/Git version number).
$ npm test
compress specified input file to output file
var lzg = require("lzg");
await lzg.compressFileAsync("big.txt", "copressed.lzg", 9, true);
decompress specified lzg file to original output file
var lzg = require("lzg");
await lzg.decompressFileAsync("copressed.lzg", "original.txt", true);
returns compressed Node.JS buffer object
returns decompressed Node.JS buffer object
First, install and configure Emscripten from http://emscripten.org/ On Windows, use WSL2 to build
Then run command:
$ npm run build
or build it directly:
$ cd ./vendor
$ emmake make clean install
2.0.0 2022-02-04
- upgraded for most recent version od emscripten
- upgraded liblzg
- converted to async
1.0.0 2016-12-07
- initial release
This project is port of original C implementation of liblzg
Copyright (c) 2010-2022 Marcus Geelnard http://liblzg.bitsnbites.eu/ https://github.com/mbitsnbites/liblzg
Transpiled to JavaScript using Emscripten
For compression test using text of Moby Dick by Herman Melville