Last active
October 8, 2018 00:53
-
-
Save davidgilbertson/d4978d531828b0ca89b0809d06d2b01f to your computer and use it in GitHub Desktop.
Get the size a file will be when gzipped
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}%`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And a one liner to run in the Node cli
zlib.gzipSync(fs.readFileSync('./someFile.js')).length