Giter Club home page Giter Club logo

node-gzbz2's Introduction

INFO

gzbz2 - A Node.js interface to streaming gzip/bzip2 compression (built originally from wave.to/node-compress)

supports Buffe or string as both input and output, this is controlled by providing encodings to init (to produce Buffers), or by passing whichever you are using as input (with optional encoding for strings). Bzip and Gzip have the same interfaces, see Versions for specific options info. Also there are two simple js wrappers for producing usable read streams, gunzipstream.js and bunzipstream.js.

INSTALL

To install, ensure that you have libz (and libbz2) installed:

  • these will be looked for in: /usr/lib, /usr/local/lib, /opt/local/lib (on osx)

npm install gzbz2

or

waf way: node-waf configure [--no-bzip] [--no-gzip]

gyp way: node-gype configure (no idea how to conditionally configure..)

node-gyp build

Note: on osx, you must run node-waf with python2.6 or greater for configure to work properly. (unsure if this applies to node-gyp)

Quick Gzip example

var gzbz2 = require("gzbz2");
var util = require("util");

// Create gzip stream
var gzip = new gzbz2.Gzip;
// binary string output
// init also accepts level: [0-9]
gzip.init({encoding: 'binary'});

// Pump data to be compressed
var gzdata1 = gzip.deflate("My data that needs ", "ascii");
util.puts("Compressed size : "+gzdata1.length);

// treat string as binary encoded
var gzdata2 = gzip.deflate("to be compressed. 01234567890.");
util.puts("Compressed size : "+gzdata2.length);

var gzdata3 = gzip.end(); // important to capture end data
util.puts("Last bit : "+gzdata3.length);

// Normally stream this out as its generated, but just print here
var gzdata = gzdata1+gzdata2+gzdata3;
util.puts("Total compressed size : "+gzdata.length);

Quick Gunzip example

var gzbz2 = require("gzbz2");
var fs = require("fs");

var gunzip = new gzbz2.Gunzip;
gunzip.init({encoding: "utf8"});

var gzdata = fs.readFileSync("somefile.gz", "binary");
var inflated = gunzip.inflate(gzdata, "binary");
gunzip.end(); // returns nothing

Quick Gunzip Stream example

var fs = require('fs'),
    gunzip = require('gzbz2/gunzipstream');

var stream = gunzip.wrap(process.argv[2], {encoding: process.argv[3]});
stream.on('data', function(data) {
    process.stdout.write(data);
});
stream.on('end', function() {
    process.exit(0);
});

Versions

  • 0.2.0:
    • added ripcurld00d's updates for node-gyp & node_event.h removal
  • 0.1.*:
    • added bzip2 support. same interface. Bzip/Bunzip objects, bzip specific init options
      • bzip.init
        • encoding (the output encoding, undefined/null means Buffers)
        • level [1-9], 1 fastest (least memory), 9 slowest (most memory), default = 1
        • workfactor [0-250], read libbz2 docs, default = 30
      • bunzip.init
        • encoding (the output encoding, undefined/null means Buffers)
        • small (boolean[false]) deflate in slow but small memory mode, default = false
    • buffer capable (on by default, this changes the default api use)
      • buffer input inflate/deflate always allowed, buffer output from same is the default
    • init accepts options object to configure buffer behavior, compression, and inflated encoding etc:
      • Gzip.init({encoding: enc, level: [0-9]}), level controls compression level 0 = none, 1 = lowest etc.
      • Gunzip.init({encoding: enc})
      • if an encoding is provided to init(), then the output of inflate/deflate will be a string
      • when providing encodings (either for input our output) for binary data, 'binary' is the only viable encoding, as base64 is not currenlty supported
    • inflate accepts a buffer or binary string[+encoding[default = 'binary']], output will be a buffer or a string encoded according to init options
    • deflate accepts a buffer or string[+encoding[default = 'utf8']], output will be a buffer or a string encoded according to init options
    • also added two submodules gunzipstream, and bunzipstream
      • use these to quickly/easily decompress a file while writing similar code to regular input streams
  • 0.0.*:
    • all string based, encodings in inflate/deflate methods, no init params

Authors

  • wave.to: developer of node-compress aka 0.0.1 version and the general framework
  • [email protected], fixed bugs/memory leaks, added 0.1.* features: buffers, bzip2, npm as gzbz2,

node-gzbz2's People

Contributors

woodya avatar waveto avatar animetosho avatar rlidwka avatar saltwaterc avatar boaz0 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.