Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A streaming compression for node.js.

Fetching latest commit…

Cannot retrieve the latest commit at this time


A streaming compression module for node.js.
Note, that API has changed since v0.1.0 and is compatible with original API by
waveto no more.
Since v0.1.1 supports streams API.

Supports gzip and bzip2 compression/decompression.

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

node-waf configure
node-waf build

This will put the compress-bindings.node binary module in build/default. 
By default library would be built with gzip support only.
Use --with-bzip key to configure library with bzip support. 
Use --no-gzip key to configure library without gzip support.

Quick example

var compress=require("../compress-bindings");
var sys=require("sys");
var posix=require("fs");
var Buffer = require('buffer').Buffer;

function createBuffer(str, enc) {
  enc = enc || 'utf8';
  var len = Buffer.byteLength(str, enc);
  var buf = new Buffer(len);
  buf.write(str, enc, 0);
  return buf;

// Create gzip stream
var gzip=new compress.Gzip(4);

// Pump data to be compressed
var gzdata1, gzdata2, gzdata3;
gzip.write(createBuffer("My data that needs "), function(err, data) {
  gzdata1 = data;
sys.puts("Compressed size : "+gzdata1.length);

gzip.write(createBuffer("to be compressed. 01234567890."), function(err, data) {
  gzdata2 = data;
sys.puts("Compressed size : "+gzdata2.length);

gzip.close(function(err, data) {
  gzdata3 = data;
sys.puts("Last bit : "+gzdata3.length);

// Take the output stream, and chop it up into two
var gzdata = gzdata1+gzdata2+gzdata3;
sys.puts("Total compressed size : "+gzdata.length);
var d1 = gzdata.substr(0, 25);
var d2 = gzdata.substr(25);

// Create gunzip stream to decode these
var data1, data2, data3;
var gunzip = new compress.Gunzip;
gunzip.write(createBuffer(d1, 'binary'), function(err, data) {
  data1 = data;
gunzip.write(createBuffer(d2, 'binary'), function(err, data) {
  data2 = data;
gunzip.close(function(err, data) {
  data3 = data;


Quick streams example

var compress=require("../compress");
var sys=require("sys");
var posix=require("fs");
var Buffer = require('buffer').Buffer;

var gzdata = '';
var gzip=new compress.GzipStream();
gzip.addListener('data', function(data) {
  gzdata += data;
}).addListener('error', function(err) {
  throw err;
}).addListener('end', function() {
  sys.puts('Compressed length: ' + gzdata.length);

gzip.write("My data that needs ");
gzip.write("to be compressed. 01234567890.");
sys.puts('Compression finished.');

var d1 = gzdata.substr(0, 25);
var d2 = gzdata.substr(25);

var rawdata = '';
var gunzip = new compress.GunzipStream();
gunzip.addListener('data', function(data) {
  rawdata += data;
}).addListener('error', function(err) {
  throw err;
}).addListener('end', function() {
  sys.puts('Decompressed length: ' + rawdata.length);
  sys.puts('Raw data: ' + rawdata);
sys.puts('Decompression finished.');

Something went wrong with that request. Please try again.