diff options
author | Alexandre Szymocha <alexandre@szymocha.com> | 2019-12-28 14:48:36 +0100 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-28 08:48:36 -0500 |
commit | 4d4908dde31316462acae5caec8dfcbbf7a244bd (patch) | |
tree | c3c2f4da8c65f3a3e790849b18730d969b868fe3 /cli/js/files.ts | |
parent | 954a0c64e77aca31d2627562d432f164c68a50dc (diff) |
Fix: allow reading into a 0-length array (#3329)
Diffstat (limited to 'cli/js/files.ts')
-rw-r--r-- | cli/js/files.ts | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cli/js/files.ts b/cli/js/files.ts index 66a70f981..d3a4b5809 100644 --- a/cli/js/files.ts +++ b/cli/js/files.ts @@ -50,6 +50,9 @@ export async function open( * */ export function readSync(rid: number, p: Uint8Array): number | EOF { + if (p.length == 0) { + return 0; + } const nread = sendSyncMinimal(dispatch.OP_READ, rid, p); if (nread < 0) { throw new Error("read error"); @@ -70,6 +73,9 @@ export function readSync(rid: number, p: Uint8Array): number | EOF { * const text = new TextDecoder().decode(buf); */ export async function read(rid: number, p: Uint8Array): Promise<number | EOF> { + if (p.length == 0) { + return 0; + } const nread = await sendAsyncMinimal(dispatch.OP_READ, rid, p); if (nread < 0) { throw new Error("read error"); |