Comparing version 3.0.4 to 3.0.5
@@ -15,3 +15,3 @@ var util = require('util') | ||
} | ||
, customGzip = function (callback) { | ||
, customGzip = function (data, callback) { | ||
var buffers = [] | ||
@@ -27,14 +27,60 @@ , size = 0 | ||
size += buffer.length | ||
}).on('end', function () { | ||
callback(null, Buffer.concat(buffers, size)) | ||
}) | ||
gzip.on('end', function () { | ||
gzip.write(data) | ||
gzip.end() | ||
} | ||
, customGunzip = function (data, callback) { | ||
var buffers = [] | ||
, size = 0 | ||
, gunzip = new zlib.Gunzip() | ||
gunzip.on('data', function (buffer) { | ||
buffers.push(buffer) | ||
size += buffer.length | ||
}).on('end', function () { | ||
callback(null, Buffer.concat(buffers, size)) | ||
buffers.length = 0 | ||
}) | ||
gzip.write(input) | ||
gunzip.write(data) | ||
gunzip.end() | ||
} | ||
, customDeflate = function (data, callback) { | ||
var buffers = [] | ||
, size = 0 | ||
, deflate = new zlib.Deflate() | ||
gzip.end() | ||
deflate.on('data', function (buffer) { | ||
buffers.push(buffer) | ||
size += buffer.length | ||
}).on('end', function () { | ||
callback(null, Buffer.concat(buffers, size)) | ||
}) | ||
deflate.write(data) | ||
deflate.end() | ||
} | ||
, customInflate = function (data, callback) { | ||
var buffers = [] | ||
, size = 0 | ||
, inflate = new zlib.Inflate({ | ||
level: zlib.Z_BEST_SPEED | ||
, memLevel: zlib.Z_MAX_MEMLEVEL | ||
}) | ||
inflate.on('data', function (buffer) { | ||
buffers.push(buffer) | ||
size += buffer.length | ||
}).on('end', function () { | ||
callback(null, Buffer.concat(buffers, size)) | ||
}) | ||
inflate.write(data) | ||
inflate.end() | ||
} | ||
console.log(chalk.underline(util.format('input size %s', bytes(input.length)))) | ||
@@ -79,9 +125,27 @@ console.log() | ||
} | ||
, function (done) { | ||
benchmark( | ||
'zlib.deflate()' | ||
, zlib.deflate.bind(zlib, input) | ||
, function (err, event) { | ||
console.log(chalk.white(event.target.toString())) | ||
zlib.deflate(input, function (err, compressed) { | ||
var str = util.format( | ||
'compressed size %s (%s%)' | ||
, bytes(compressed.length) | ||
, round(compressed.length / input.length * 100) | ||
) | ||
console.log(chalk.white(str)) | ||
done() | ||
}) | ||
} | ||
) | ||
} | ||
, function (done) { | ||
benchmark( | ||
'zlib.Gzip with custom options' | ||
, customGzip | ||
, customGzip.bind(zlib, input) | ||
, function (err, event) { | ||
console.log(chalk.magenta(event.target.toString())) | ||
customGzip(function (err, compressed) { | ||
customGzip(input, function (err, compressed) { | ||
var str = util.format( | ||
@@ -93,2 +157,20 @@ 'compressed size %s (%s%)' | ||
console.log(chalk.magenta(str)) | ||
done() | ||
}) | ||
} | ||
) | ||
} | ||
, function (done) { | ||
benchmark( | ||
'zlib.Deflate with custom options' | ||
, customDeflate.bind(zlib, input) | ||
, function (err, event) { | ||
console.log(chalk.green(event.target.toString())) | ||
customDeflate(input, function (err, compressed) { | ||
var str = util.format( | ||
'compressed size %s (%s%)' | ||
, bytes(compressed.length) | ||
, round(compressed.length / input.length * 100) | ||
) | ||
console.log(chalk.green(str)) | ||
console.log() | ||
@@ -124,2 +206,38 @@ done() | ||
} | ||
, function (done) { | ||
zlib.deflate(input, function (err, compressed) { | ||
benchmark( | ||
'zlib.inflate()' | ||
, zlib.inflate.bind(zlib, compressed) | ||
, function (err, event) { | ||
console.log(chalk.white(event.target.toString())) | ||
done() | ||
} | ||
) | ||
}) | ||
} | ||
, function (done) { | ||
customGzip(input, function (err, compressed) { | ||
benchmark( | ||
'zlib.Gunzip with custom options' | ||
, customGunzip.bind(zlib, compressed) | ||
, function (err, event) { | ||
console.log(chalk.magenta(event.target.toString())) | ||
done() | ||
} | ||
) | ||
}) | ||
} | ||
, function (done) { | ||
customDeflate(input, function (err, compressed) { | ||
benchmark( | ||
'zlib.Inflate with custom options' | ||
, customInflate.bind(zlib, compressed) | ||
, function (err, event) { | ||
console.log(chalk.green(event.target.toString())) | ||
done() | ||
} | ||
) | ||
}) | ||
} | ||
]) |
@@ -5,3 +5,3 @@ { | ||
"description": "Nodejs bindings to Google's Snappy compression library", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"homepage": "https://github.com/kesla/node-snappy", | ||
@@ -19,3 +19,3 @@ "repository": { | ||
"bindings": "~1.1.1", | ||
"nan": "~1.2.0" | ||
"nan": "1.5.3" | ||
}, | ||
@@ -22,0 +22,0 @@ "devDependencies": { |
@@ -21,3 +21,3 @@ # snappy[![build status](https://secure.travis-ci.org/kesla/node-snappy.svg)](http://travis-ci.org/kesla/node-snappy) | ||
```javascript | ||
var snappy = require('./snappy') | ||
var snappy = require('snappy') | ||
@@ -24,0 +24,0 @@ snappy.compress('beep boop', function (err, compressed) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1762311
341