Skip to content

Instantly share code, notes, and snippets.

@dashawk
Created July 1, 2019 00:45
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 dashawk/ada103da348519f2ad9973fde9d2ee4e to your computer and use it in GitHub Desktop.
Save dashawk/ada103da348519f2ad9973fde9d2ee4e to your computer and use it in GitHub Desktop.
// reference https://gist.github.com/GuillermoPena/9233069#gistcomment-2636187
// sha-cli.js
const filename = process.argv[2];
const crypto = require('crypto');
const fs = require('fs');
const hash = crypto.createHash('sha256');
const input = fs.createReadStream(filename);
input.on('readable', () => {
const data = input.read();
if (data)
hash.update(data);
else {
console.log(`${hash.digest('hex')} ${filename}`);
}
});
// Example usage if you saved that code in sha-cli.js file would be:
// node sha-cli.js example-input-file.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment