diff --git a/lib/deflate.js b/lib/deflate.js index e1f38bf..36ff744 100644 --- a/lib/deflate.js +++ b/lib/deflate.js @@ -1,7 +1,8 @@ 'use strict'; -var zlib = require('zlib/deflate.js'); +//var zlib_deflate = require('./zlib/deflate.js'); +var utils = require('./zlib/utils'); /** @@ -10,7 +11,7 @@ var zlib = require('zlib/deflate.js'); * @param {Object} [options] zlib options * @constructor */ -var Deflate = function(options) { +var Deflate = function(/*options*/) { }; @@ -19,7 +20,7 @@ var Deflate = function(options) { * Compresses the input data and fills output buffer with compressed data. * @return {Array|Uint8Array} compressed data */ -Deflate.prototype.deflate = function(input) { +Deflate.prototype.push = function(/*data_in*/) { }; @@ -31,11 +32,11 @@ Deflate.prototype.finish = function() { }; -Deflate.prototype.onData = function(output) { +Deflate.prototype.onData = function(/*data_out*/) { }; -Deflate.prototype.onEnd = function(error) { +Deflate.prototype.onEnd = function(/*err*/) { }; @@ -49,11 +50,51 @@ exports.Deflate = Deflate; * @param [options] * @returns {Array|Uint8Array} */ -exports.deflate = function(input, options) { +function deflate(input, options) { + var result; + var chains = []; + var deflator = new Deflate(options); -}; + deflator.onData = function(data_out) { + chains.push(data_out); + }; + + deflator.onEnd = function(error) { + var i, l, len, pos, chain; + + if (error) { throw error; } + + // calculate data length + len = 0; + for (i=0, l=chains.length; i