相关疑难解决方法(0)

如何使用ES8异步/等待流?

/sf/answers/1306102941/中是如何使用内置加密库和流计算文件的md5的示例.

var fs = require('fs');
var crypto = require('crypto');

// the file you want to get the hash    
var fd = fs.createReadStream('/some/file/name.txt');
var hash = crypto.createHash('sha1');
hash.setEncoding('hex');

fd.on('end', function() {
    hash.end();
    console.log(hash.read()); // the desired sha1sum
});

// read all file and pipe it (write it) to the hash object
fd.pipe(hash);
Run Code Online (Sandbox Code Playgroud)

但是有可能将其转换为使用ES8 async/await而不是如上所述使用回调,但是仍然保持使用流的效率吗?

javascript node.js async-await ecmascript-2017

40
推荐指数
6
解决办法
3万
查看次数