Deno.iterSync

\color{red}{function} Deno.iterSync(r: ReaderSync, options?: { bufSize: number }) : IterableIterator<Uint8Array>

\color{red}{作用}

将ReaderSync r变成迭代器。

Turns a ReaderSync, r, into an iterator.

\color{red}{参数}

r : ReaderSync
options ?: { bufSize: number }

r : ReaderSync
options ?: { bufSize: number }

\color{red}{返回值}

IterableIterator<Uint8Array>

IterableIterator<Uint8Array>

\color{red}{示列代码}

let f = Deno.openSync("/etc/passwd");
for (const chunk of Deno.iterSync(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.iterSync(f, {
  bufSize: 1024 * 1024
});
for (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 目录

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

推荐阅读更多精彩内容