summaryrefslogtreecommitdiff
path: root/cli/js/lib.deno.ns.d.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-04-22 21:30:45 +0200
committerGitHub <noreply@github.com>2020-04-22 21:30:45 +0200
commit68d287eed5dcdc7b84a317fa90c4c9131389c0b8 (patch)
tree2d6c623858ef89504f26a49ffd169e1d2b2e8453 /cli/js/lib.deno.ns.d.ts
parentda6819a14c54d1a2221b37f00b3302eb2d50660b (diff)
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
Diffstat (limited to 'cli/js/lib.deno.ns.d.ts')
-rw-r--r--cli/js/lib.deno.ns.d.ts54
1 files changed, 51 insertions, 3 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 9f2c854d9..ed2e40f84 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -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.
+ *
+ * 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.
*
- * for await (const chunk of toAsyncIterator(reader)) {
+ * 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 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 toAsyncIterator(r: Reader): AsyncIterableIterator<Uint8Array>;
+ 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`