Last active
July 8, 2016 16:59
-
-
Save kevireilly/32d77601477e4e9c04e19baacb9265e1 to your computer and use it in GitHub Desktop.
Example of streaming a file to blake2
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 characters
'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