Obtaining the hash of a file using the stream capabilities of crypto module (ie: without hash.update and hash.digest)

后端 未结 6 938
醉酒成梦
醉酒成梦 2020-12-04 15:25

The crypto module of node.js (at the time of this writing at least) is not still deemed stable and so the API may change. In fact, the methods that everyone in the internet

6条回答
  •  抹茶落季
    2020-12-04 16:11

    var fs = require('fs');
    var crypto = require('crypto');
    var fd = fs.createReadStream('data.txt');
    var hash = crypto.createHash('md5');
    hash.setEncoding('hex');
    fd.pipe(hash);
    hash.on('data', function (data) {
        console.log('# ',data);
    });
    

提交回复
热议问题