diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-07-23 08:16:39 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-07-23 11:16:39 -0400 |
commit | e49d1e16ca2fca45e959c1add9b5a1d6866dbb90 (patch) | |
tree | 1415190fcd43e18e0994eba5f13b9babf2b474db /js/xeval.ts | |
parent | 70de8dd51d465ea2016d6bb7c0728111f4493668 (diff) |
feat: expose writeAll() and writeAllSync() (#2298)
Symmetric with `readAll()` and `readAllSync()`. Also used in `xeval`.
Also correct usage in `writeFile()`/`writeFileSync()`.
Diffstat (limited to 'js/xeval.ts')
-rw-r--r-- | js/xeval.ts | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/js/xeval.ts b/js/xeval.ts index 81e79f590..fa706ae20 100644 --- a/js/xeval.ts +++ b/js/xeval.ts @@ -1,22 +1,10 @@ -import { Buffer } from "./buffer"; +import { Buffer, writeAll } from "./buffer"; import { stdin } from "./files"; import { TextEncoder, TextDecoder } from "./text_encoding"; import { Reader, EOF } from "./io"; export type XevalFunc = (v: string) => void; -async function writeAll(buffer: Buffer, arr: Uint8Array): Promise<void> { - let bytesWritten = 0; - while (bytesWritten < arr.length) { - try { - const nwritten = await buffer.write(arr.subarray(bytesWritten)); - bytesWritten += nwritten; - } catch { - return; - } - } -} - // TODO(kevinkassimo): Move this utility to deno_std. // Import from there once doable. // Read from reader until EOF and emit string chunks separated |