mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
BREAKING CHANGE: rename Deno.toAsyncIterator() to Deno.iter() (#4848)
* rename Deno.toAsyncIterator() to Deno.iter() * adds sync version Deno.iterSync() * adds optional second argument for buffer size
This commit is contained in:
parent
da6819a14c
commit
68d287eed5
6 changed files with 169 additions and 28 deletions
54
cli/js/lib.deno.ns.d.ts
vendored
54
cli/js/lib.deno.ns.d.ts
vendored
|
@ -573,13 +573,61 @@ declare namespace Deno {
|
|||
*/
|
||||
export function copy(dst: Writer, src: Reader): Promise<number>;
|
||||
|
||||
/** Turns a Reader, `r`, into an async iterator.
|
||||
/** **UNSTABLE**: new API, yet to be vetted
|
||||
* Turns a Reader, `r`, into an async iterator.
|
||||
*
|
||||
* for await (const chunk of toAsyncIterator(reader)) {
|
||||
* let f = await open("/etc/passwd");
|
||||
* for await (const chunk of iter(f)) {
|
||||
* console.log(chunk);
|
||||
* }
|
||||
* f.close();
|
||||
*
|
||||
* Second argument can be used to tune size of a buffer.
|
||||
* Default size of the buffer is 1024 bytes.
|
||||
*
|
||||
* let f = await open("/etc/passwd");
|
||||
* for await (const chunk of iter(f, 1024 * 1024)) {
|
||||
* console.log(chunk);
|
||||
* }
|
||||
* f.close();
|
||||
*
|
||||
* Iterator uses internal buffer of fixed size for efficiency returning
|
||||
* a view on that buffer on each iteration. It it therefore callers
|
||||
* responsibility to copy contents of the buffer if needed; otherwise
|
||||
* next iteration will overwrite contents of previously returned chunk.
|
||||
*/
|
||||
export function toAsyncIterator(r: Reader): AsyncIterableIterator<Uint8Array>;
|
||||
export function iter(
|
||||
r: Reader,
|
||||
bufSize?: number
|
||||
): AsyncIterableIterator<Uint8Array>;
|
||||
|
||||
/** **UNSTABLE**: new API, yet to be vetted
|
||||
* Turns a SyncReader, `r`, into an iterator.
|
||||
*
|
||||
* let f = await open("/etc/passwd");
|
||||
* for (const chunk of iterSync(reader)) {
|
||||
* console.log(chunk);
|
||||
* }
|
||||
* f.close();
|
||||
*
|
||||
* Second argument can be used to tune size of a buffer.
|
||||
* Default size of the buffer is 1024 bytes.
|
||||
*
|
||||
* let f = await open("/etc/passwd");
|
||||
* for (const chunk of iterSync(reader, 1024 * 1024)) {
|
||||
* console.log(chunk);
|
||||
* }
|
||||
* f.close()
|
||||
*
|
||||
* Iterator uses internal buffer of fixed size for efficiency returning
|
||||
* a view on that buffer on each iteration. It it therefore callers
|
||||
* responsibility to copy contents of the buffer if needed; otherwise
|
||||
* next iteration will overwrite contents of previously returned chunk.
|
||||
*/
|
||||
export function iterSync(
|
||||
r: SyncReader,
|
||||
bufSize?: number
|
||||
): IterableIterator<Uint8Array>;
|
||||
|
||||
/** Synchronously open a file and return an instance of `Deno.File`. The
|
||||
* file does not need to previously exist if using the `create` or `createNew`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue