From ff4e682ff95af37b52c404d694ffcfcfa57bb127 Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Tue, 8 Oct 2024 16:11:32 +0530 Subject: fix(ext/node): internal buffer length in readSync (#26064) Closes https://github.com/denoland/deno/issues/26054 --- ext/node/polyfills/_fs/_fs_read.ts | 2 +- tests/unit_node/fs_test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/_fs/_fs_read.ts b/ext/node/polyfills/_fs/_fs_read.ts index dec3a8bbd..df4f5e375 100644 --- a/ext/node/polyfills/_fs/_fs_read.ts +++ b/ext/node/polyfills/_fs/_fs_read.ts @@ -173,7 +173,7 @@ export function readSync( validateBuffer(buffer); if (length == null) { - length = 0; + length = buffer.byteLength; } if (typeof offsetOrOpt === "number") { diff --git a/tests/unit_node/fs_test.ts b/tests/unit_node/fs_test.ts index b1f7c53e8..2d1465aec 100644 --- a/tests/unit_node/fs_test.ts +++ b/tests/unit_node/fs_test.ts @@ -4,13 +4,16 @@ import { assert, assertEquals, assertThrows } from "@std/assert"; import { join } from "node:path"; import { tmpdir } from "node:os"; import { + closeSync, constants, createWriteStream, existsSync, lstatSync, mkdtempSync, + openSync, promises, readFileSync, + readSync, Stats, statSync, writeFileSync, @@ -201,3 +204,11 @@ Deno.test( assertEquals(res, [0, 1, 2, 3, 4, 5]); }, ); + +Deno.test("[node/fs] readSync works", () => { + const fd = openSync("tests/testdata/assets/hello.txt", "r"); + const buf = new Uint8Array(256); + const bytesRead = readSync(fd!, buf); + assertEquals(bytesRead, 12); + closeSync(fd!); +}); -- cgit v1.2.3