Skip to content

Instantly share code, notes, and snippets.

@tralamazza
Created October 2, 2012 00:49
Show Gist options
  • Select an option

  • Save tralamazza/3815514 to your computer and use it in GitHub Desktop.

Select an option

Save tralamazza/3815514 to your computer and use it in GitHub Desktop.
stupid nodejs stream example
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