diff options
Diffstat (limited to 'js/xeval.ts')
-rw-r--r-- | js/xeval.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/js/xeval.ts b/js/xeval.ts index f769a2ead..81e79f590 100644 --- a/js/xeval.ts +++ b/js/xeval.ts @@ -1,7 +1,7 @@ import { Buffer } from "./buffer"; import { stdin } from "./files"; import { TextEncoder, TextDecoder } from "./text_encoding"; -import { Reader } from "./io"; +import { Reader, EOF } from "./io"; export type XevalFunc = (v: string) => void; @@ -35,12 +35,13 @@ async function* chunks( // Record how far we have gone with delimiter matching. let nextMatchIndex = 0; while (true) { - const rr = await reader.read(inspectArr); - if (rr.nread < 0) { + let result = await reader.read(inspectArr); + let rr = result === EOF ? 0 : result; + if (rr < 0) { // Silently fail. break; } - const sliceRead = inspectArr.subarray(0, rr.nread); + const sliceRead = inspectArr.subarray(0, rr); // Remember how far we have scanned through inspectArr. let nextSliceStartIndex = 0; for (let i = 0; i < sliceRead.length; i++) { @@ -74,7 +75,7 @@ async function* chunks( } // Write all unprocessed chunk to buffer for future inspection. await writeAll(inputBuffer, sliceRead.subarray(nextSliceStartIndex)); - if (rr.eof) { + if (result === EOF) { // Flush the remainder unprocessed chunk. const lastChunk = inputBuffer.toString(); yield lastChunk; |