Deno.iter

\color{red}{function} Deno.iter(r: Reader, options?: { bufSize: number }) : AsyncIterableIterator<Uint8Array>

\color{red}{作用}

将Reader r变成异步迭代器。

Turns a Reader, r, into an async iterator.

\color{red}{参数}

r : Reader
options ?: { bufSize: number }

r : Reader
options ?: { bufSize: number }

\color{red}{返回值}

AsyncIterableIterator<Uint8Array>

AsyncIterableIterator<Uint8Array>

\color{red}{示列代码}

let f = await Deno.open("/etc/passwd");
for await (const chunk of Deno.iter(f)) {
  console.log(chunk);
}
f.close();

\color{red}{其它}

第二个参数可用于调整缓冲区的大小。 缓冲区的默认大小为32kB。

Second argument can be used to tune size of a buffer. Default size of the buffer is 32kB.

let f = await Deno.open("/etc/passwd");
const iter = Deno.iter(f, {
  bufSize: 1024 * 1024
});
for await (const chunk of iter) {
  console.log(chunk);
}
f.close();

迭代器使用固定大小的内部缓冲区来提高效率; 它在每次迭代时都返回该缓冲区的视图。 因此,调用方有责任在需要时复制缓冲区的内容。 否则,下一次迭代将覆盖先前返回的块的内容。

Iterator uses an internal buffer of fixed size for efficiency; it returns a view on that buffer on each iteration. It is therefore caller's responsibility to copy contents of the buffer if needed; otherwise the next iteration will overwrite contents of previously returned chunk.

原文地址:点此跳转

Deno 目录

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 上一篇:051-python库PIL(一) 一、The Image Module(图像模块) The Image ...
    AncientMing阅读 726评论 0 0
  • 超高速音视频编码器用法: ffmpeg [options] [[infile options] -i infile...
    吉凶以情迁阅读 4,663评论 0 4
  • 多线程。线程是进程中的一个执行单元(执行路径),可以并发。System.gc();申请启动垃圾回收器,垃圾回收器比...
    MikleLi阅读 199评论 0 0
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,573评论 16 22
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,613评论 0 11