阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js stream readable

      Node.js stream readable[Symbol.asyncIterator]()

      新增于: v10.0.0

      • Returns:to fully consume the stream. const fs = require(‘fs’);
      async function print(readable) {
        readable.setEncoding('utf8');
        let data = '';
        for await (const k of readable) {
          data += k;
        }
        console.log(data);
      }
      

      print(fs.createReadStream(‘file’)).catch(console.log); If the loop terminates with a break or a throw, the stream will be destroyed. In other terms, iterating over a stream will consume the stream fully. The stream will be read in chunks of size equal to the highWaterMark option. In the code example above, data will be in a single chunk if the file has less then 64kb of data because no highWaterMark option is provided to fs.createReadStream().


      更多内容请参考:Node.js stream 流,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录