summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-10-08 16:11:32 +0530
committerGitHub <noreply@github.com>2024-10-08 10:41:32 +0000
commitff4e682ff95af37b52c404d694ffcfcfa57bb127 (patch)
treea14e6b7af1b494393796a7eac56fbc3ca3ac8927
parent2d488e4bfb9ffdfd2d043cc4bba9e6037b4cc24e (diff)
fix(ext/node): internal buffer length in readSync (#26064)
Closes https://github.com/denoland/deno/issues/26054
-rw-r--r--ext/node/polyfills/_fs/_fs_read.ts2
-rw-r--r--tests/unit_node/fs_test.ts11
2 files changed, 12 insertions, 1 deletions
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!);
+});