From d7edf393b6f1178bc91ec9113412f23f5dbd61e1 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Fri, 7 Feb 2020 18:51:01 -0500 Subject: [PATCH] toAsyncIterable: Remove unnecessary EOF check (#3914) In denoland/deno#2335 a conditional was added to make sure toAsyncIterator didn't skip chunks because the reader returned data and EOF in a single call, fixing #2330. Later, in denoland/deno#2591, the `Reader` interface changed to `Promise`. Since the reader no longer returns data and EOF in a single call, this conditional is not necessary. We can just return `{ done: true }` when we get `EOF`. Co-authored-by: Arun Srinivasan Co-authored-by: Arun Srinivasan --- cli/js/io.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/cli/js/io.ts b/cli/js/io.ts index 4e839fcc23..348394061b 100644 --- a/cli/js/io.ts +++ b/cli/js/io.ts @@ -135,28 +135,14 @@ export async function copy(dst: Writer, src: Reader): Promise { */ export function toAsyncIterator(r: Reader): AsyncIterableIterator { const b = new Uint8Array(1024); - // Keep track if end-of-file has been reached, then - // signal that iterator is done during subsequent next() - // call. This is required because `r` can return a `number | EOF` - // with data read and EOF reached. But if iterator returns - // `done` then `value` is discarded. - // - // See https://github.com/denoland/deno/issues/2330 for reference. - let sawEof = false; - return { [Symbol.asyncIterator](): AsyncIterableIterator { return this; }, async next(): Promise> { - if (sawEof) { - return { value: new Uint8Array(), done: true }; - } - const result = await r.read(b); if (result === EOF) { - sawEof = true; return { value: new Uint8Array(), done: true }; }