diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-07-06 23:16:03 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-07-06 10:16:03 -0400 |
commit | a948f9ff541e5983bc29113d1e0f1898206f8581 (patch) | |
tree | 67e47efd88468886a8e2a50ad28cc2c75be69389 /js/xeval.ts | |
parent | 33cb79d24cf03c2c771dfa499e4cc8ee7bcee800 (diff) |
io: change Reader interface (#2591)
Instead of returning { nread: number, eof: bool }, read() returns EOF | number.
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; |