Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Last active October 8, 2018 00:53
Show Gist options
  • Save davidgilbertson/d4978d531828b0ca89b0809d06d2b01f to your computer and use it in GitHub Desktop.
Save davidgilbertson/d4978d531828b0ca89b0809d06d2b01f to your computer and use it in GitHub Desktop.
Get the size a file will be when gzipped
const fs = require('fs');
const zlib = require('zlib');
const file = fs.readFileSync('./some_file.js');
const rawSize = file.length;
const gzippedSize = zlib.gzipSync(file).length;
console.log('Raw size: ', (rawSize / 1000), 'KB');
console.log('Gzipped size: ', (gzippedSize / 1000), 'KB');
console.log('Compression: ', `${100 - Math.round(gzippedSize / rawSize * 1000) / 10}%`);
@davidgilbertson
Copy link
Author

And a one liner to run in the Node cli zlib.gzipSync(fs.readFileSync('./someFile.js')).length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment