Skip to content

Instantly share code, notes, and snippets.

@gagan-bansal
Created July 14, 2022 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagan-bansal/0ffd2d98e08cfdac6e4fc0eaeaccba15 to your computer and use it in GitHub Desktop.
Save gagan-bansal/0ffd2d98e08cfdac6e4fc0eaeaccba15 to your computer and use it in GitHub Desktop.
Compress a file with gz using node.js zlib module.
const file = process.argv[2];
const {promisify} = require('util');
const zlib = require('zlib');
const gzip = promisify(zlib.gzip);
(async () => {
const fs = require('fs');
const data = fs.readFileSync(file, 'utf-8');
const buf = await gzip(data)
fs.writeFileSync(`${file}.gz`, buf);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment