Created
October 2, 2012 00:49
-
-
Save tralamazza/3815514 to your computer and use it in GitHub Desktop.
stupid nodejs stream example
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
| var crypto = require('crypto'); | |
| var through = require('through'); | |
| exports.createHashStream = function(algorithm, input_encoding, output_encoding) { | |
| input_encoding = input_encoding || 'utf8'; | |
| output_encoding = output_encoding || 'hex'; | |
| var hashsum = crypto.createHash(algorithm || 'sha1'); | |
| return through(function write(data) { | |
| hashsum.update(data, input_encoding); | |
| }, function end() { | |
| this.emit('data', hashsum.digest(output_encoding)); | |
| this.emit('end'); | |
| }); | |
| } | |
| // require('fs').ReadStream(require('path').resolve(process.argv[2])).pipe(exports.createHashStream()).pipe(process.stdout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment