Skip to content

Instantly share code, notes, and snippets.

@kevireilly
Last active July 8, 2016 16:59
Show Gist options
  • Save kevireilly/32d77601477e4e9c04e19baacb9265e1 to your computer and use it in GitHub Desktop.
Save kevireilly/32d77601477e4e9c04e19baacb9265e1 to your computer and use it in GitHub Desktop.
Example of streaming a file to blake2
'use strict';
// Dependencies
const blake2 = require('blake2'),
fs = require('fs');
// Setup the blake2eb hash
const hash = new blake2.Hash('blake2b');
hash.setEncoding('hex');
// Setup a read stream of the "foo.js" file
const stream = fs.createReadStream('./foo.js');
stream.on('end', function(){
// When the stream finishes,
// create the blake2 hash
hash.end();
const digest = hash.read();
console.log(digest);
});
// Start piping the file to blake2
stream.pipe(hash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment