1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function md5(filename, cb) {
const crypto = require('crypto');
const fs = require('fs');

const hash = crypto.createHash('md5');

const input = fs.createReadStream(filename);
input.on('readable', () => {
// Only one element is going to be produced by the
// hash stream.
const data = input.read();
if (data)
hash.update(data);
else {
cb(hash.digest('hex'));
}
});
}

const filename = "/tmp/test.xt";

md5(filename, result => {
console.log(filename + " md5: ", result)
})