Comparing version 0.0.3 to 0.0.4
26
index.js
var ReadableStream = require('stream').Readable; | ||
var filesize = require('filesize'); | ||
var colors = require('chalk'); | ||
var zlib = require('zlib'); | ||
function displayStats(original, compressed, ratio) { | ||
console.log(colors.yellow('Original size:'), colors.green(filesize(original))); | ||
console.log(colors.yellow('Compressed size:'), colors.green(filesize(compressed))); | ||
console.log(colors.yellow('Compression ratio:'), colors.green((ratio * 100).toFixed(2) + '%')); | ||
} | ||
function calculate(buffer) { | ||
function calculate(buffer, cb) { | ||
var gzipped = zlib.gzip(buffer, function (err, gzipped) { | ||
if (err) throw err; | ||
if (err) return cb(err); | ||
displayStats(buffer.length, gzipped.length, buffer.length / gzipped.length); | ||
cb(null, { | ||
original: buffer.length, | ||
compressed: gzipped.length, | ||
ratio: gzipped.length / buffer.length | ||
}); | ||
}); | ||
} | ||
module.exports.calculate = function (stream) { | ||
module.exports.calculate = function (stream, cb) { | ||
var buffers = []; | ||
@@ -28,4 +24,8 @@ | ||
stream.on('end', function () { | ||
calculate(Buffer.concat(buffers)); | ||
calculate(Buffer.concat(buffers), cb); | ||
}); | ||
stream.on('error', function (err) { | ||
cb(err); | ||
}); | ||
}; |
{ | ||
"name": "gzipped", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Command line utility to calculate gzip compression savings", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
3926
8
39
1