Skip to content

Commit

Permalink
Added check for correct command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vrza committed Feb 24, 2023
1 parent a565ccd commit 67a4522
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions b2sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
/**
* Takes an algorithm name and prints the hex digest of stdin.
* Example:
* cat file | ./b2sum.js blake2b
* $ node b2sum.js blake2b < file
*/

"use strict";

const blake2 = require('./index');
if (process.argv.length === 2) {
const EXIT_USAGE = 1;
const progname = process.argv[0].concat(' ', process.argv[1]);
const usageMsg = `Usage: ${progname} <algo>`;
console.error(usageMsg);
process.exit(EXIT_USAGE);
}

const algo = process.argv[2];
const blake2 = require('./index');
const hash = new blake2.Hash(algo);
hash.setEncoding('hex');

const stream = process.stdin;

stream.on('end', function() {
hash.end();
const digest = hash.read();
console.log(digest);
});

stream.pipe(hash);

0 comments on commit 67a4522

Please sign in to comment.