Last active
October 20, 2019 18:55
-
-
Save TravisMullen/dfcd1f08887be1ed82f29276308fb82d to your computer and use it in GitHub Desktop.
Revisions
-
Travis Mullen revised this gist
Oct 20, 2019 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,13 @@ import { createHash } from 'crypto' import { createReadStream } from 'fs' /** * Generate hash from file. * @param {string} filename - path to file. * @param {string} algorithm * @returns {Promise} */ export const shasum = (filename, algorithm = 'sha256') => ( new Promise((resolve, reject) => { if (!(filename && typeof (filename) !== 'string')) { -
Travis Mullen revised this gist
Oct 20, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,9 +10,8 @@ import { createReadStream }from 'fs' * @param {string} algorithm * @returns {Promise} */ export const shasum = (filename = process.argv[2], algorithm = 'sha256') => ( new Promise((resolve, reject) => { if (!(filename && typeof (filename) !== 'string')) { reject(new Error('file not found.')) -
Travis Mullen created this gist
Oct 20, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #!/usr/bin/env node import { createHash }from 'crypto' import { createReadStream }from 'fs' /** * Generate hash from file. * @param {string} filename - path to file. * @param {string} algorithm * @returns {Promise} */ export const shasum = (filename, algorithm = 'sha256') => ( new Promise((resolve, reject) => { const filename = process.argv[2] if (!(filename && typeof (filename) !== 'string')) { reject(new Error('file not found.')) } const hash = createHash(algorithm) const input = createReadStream(filename) input.on('readable', () => { // Only one element is going to be produced by the // hash stream. const data = input.read() if (data) { hash.update(data) } else { const result = hash.digest('hex') console.log(`${result} ${filename}`) resolve(result) } }) hash.on('error', error => { reject(error) }) }) )