Open tedmx opened 8 years ago
fstream_hash_issue_example.js computes MD5 hash of a file read from filesystem.
fstream_hash_issue_example.js
Program call and output in cmd.exe, Windows :
F:\...>node fstream_hash_issue_example.js fs.createReadStream: dd9e30aa94c1074d863846c4ed35b8bd fstream.Reader: d41d8cd98f00b204e9800998ecf8427e fstream.Reader: dd9e30aa94c1074d863846c4ed35b8bd
The code:
var crypto = require('crypto'), fs = require('fs'), fstream = require('fstream'), through = require('through2'); function getHasher(tag){ var md5Hasher = crypto.createHash('md5', { encoding: 'hex' }); md5Hasher.on('readable', () => { var data = md5Hasher.read(); if (data) console.log( tag+data ); }); return md5Hasher; } fs.createReadStream("program.js").pipe(getHasher('fs.createReadStream: ')); fstream.Reader("program.js").pipe(getHasher('fstream.Reader: ')); fstream.Reader("program.js").pipe(through( //No-op stream function(buf,_,next){ this.push(buf); next(); } )).pipe(getHasher('fstream.Reader: '));
Environment: Windows 10 Pro, node v.4.2.4, fstream 1.0.10
fstream_hash_issue_example.js
computes MD5 hash of a file read from filesystem.Program call and output in cmd.exe, Windows :
The code:
Environment: Windows 10 Pro, node v.4.2.4, fstream 1.0.10