summaryrefslogtreecommitdiff
path: root/tests/unit_node/_fs/_fs_handle_test.ts
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-08-16 09:48:57 -0700
committerGitHub <noreply@github.com>2024-08-16 09:48:57 -0700
commitff4226a3cd20ef6cfb155ca206c745785b6e098f (patch)
treec845e539ec01f4261a7f824cb3d50f1b6e2d7ab4 /tests/unit_node/_fs/_fs_handle_test.ts
parent4d1b263e91dc7b85e9c8cd1cb42270ddc0468396 (diff)
fix(node/fs): Use correct offset and length in node:fs.read and write (#25049)
My fix in #25030 was buggy, I forgot to pass the `byteOffset` and `byteLength`. Whoops. I also discovered that fs.read was not respecting the `offset` argument, and we were constructing a new `Buffer` for the callback instead of just passing the original one (which is what node does, and the @types/node definitions also indicate the callback should get the same type). Fixes #25028.
Diffstat (limited to 'tests/unit_node/_fs/_fs_handle_test.ts')
-rw-r--r--tests/unit_node/_fs/_fs_handle_test.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/unit_node/_fs/_fs_handle_test.ts b/tests/unit_node/_fs/_fs_handle_test.ts
index ea6af9c29..755e091fd 100644
--- a/tests/unit_node/_fs/_fs_handle_test.ts
+++ b/tests/unit_node/_fs/_fs_handle_test.ts
@@ -38,11 +38,15 @@ Deno.test("read specify opt", async function () {
buffer: new Buffer(byteLength),
offset: 6,
length: 5,
+ position: 6,
};
let res = await fileHandle.read(opt);
- assertEquals(res.bytesRead, byteLength);
- assertEquals(new TextDecoder().decode(res.buffer as Uint8Array), "world");
+ assertEquals(res.bytesRead, 5);
+ assertEquals(
+ new TextDecoder().decode(res.buffer.subarray(6) as Uint8Array),
+ "world",
+ );
const opt2 = {
buffer: new Buffer(byteLength),
@@ -51,8 +55,11 @@ Deno.test("read specify opt", async function () {
};
res = await fileHandle.read(opt2);
- assertEquals(res.bytesRead, byteLength);
- assertEquals(decoder.decode(res.buffer as Uint8Array), "hello");
+ assertEquals(res.bytesRead, 5);
+ assertEquals(
+ decoder.decode(res.buffer.subarray(0, 5) as Uint8Array),
+ "hello",
+ );
await fileHandle.close();
});