Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Probable bug when piped into Hash #54

Open
tedmx opened this issue Jul 12, 2016 · 0 comments
Open

Probable bug when piped into Hash #54

tedmx opened this issue Jul 12, 2016 · 0 comments

Comments

@tedmx
Copy link

tedmx commented Jul 12, 2016

fstream_hash_issue_example.js computes MD5 hash of a file read from filesystem.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant