Giter Site home page Giter Site logo

lz4js's Introduction

Lz4.js NPM version Build Status codecov

Lz4.js is an implementation of Lz4 designed to be used in web browsers. It contains no dependencies on external libraries or Node.JS, though it is organized as a set of CommonJS modules. It is recommended to use Browserify or WebPack to bundle this for the web browser.

Installation

npm install lz4js

Usage

var lz4 = require("lz4js");
var fs = require("fs");

// Compress 128 bytes of zero.
var compressed = lz4.compress(new Array(128));

// Decompress.
var decompressed = lz4.decompress(compressed);

// Compress file.bin to file.lz4.
var data = fs.readFileSync("file.bin");
compressed = Buffer.from(lz4.compress(data));
fs.writeFileSync('file.lz4', compressed);

Note: The high-level compress and decompress functions deal with framed Lz4 data and do not support raw block data nor legacy Lz4 blocks.

API

The API accepts either Arrays or Uint8Arrays. Arrays are expected to be arrays of unsigned 8-bit values. The API will return Uint8Arrays if the browser supports them, or Arrays otherwise.

  • compress(buffer: Array, maxSize: Number): Array

    Compresses a buffer using Lz4. maxSize sets bounds on the output length; it is recommended to not specify this unless you know what you're doing. Any unused buffer data will be sliced before the buffer is returned.

  • decompress(buffer: Array, maxSize: Number): Array

    Decompresses a buffer using Lz4. maxSize sets bounds on the output length; if you know the output length, this will reduce memory usage somewhat. Any unused buffer data will be sliced before the buffer is returned.

lz4js's People

Contributors

jchv avatar ledbit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.