mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(ext/node): internal buffer length in readSync (#26064)
Closes https://github.com/denoland/deno/issues/26054
This commit is contained in:
parent
2d488e4bfb
commit
ff4e682ff9
2 changed files with 12 additions and 1 deletions
|
@ -173,7 +173,7 @@ export function readSync(
|
||||||
validateBuffer(buffer);
|
validateBuffer(buffer);
|
||||||
|
|
||||||
if (length == null) {
|
if (length == null) {
|
||||||
length = 0;
|
length = buffer.byteLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof offsetOrOpt === "number") {
|
if (typeof offsetOrOpt === "number") {
|
||||||
|
|
|
@ -4,13 +4,16 @@ import { assert, assertEquals, assertThrows } from "@std/assert";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import {
|
import {
|
||||||
|
closeSync,
|
||||||
constants,
|
constants,
|
||||||
createWriteStream,
|
createWriteStream,
|
||||||
existsSync,
|
existsSync,
|
||||||
lstatSync,
|
lstatSync,
|
||||||
mkdtempSync,
|
mkdtempSync,
|
||||||
|
openSync,
|
||||||
promises,
|
promises,
|
||||||
readFileSync,
|
readFileSync,
|
||||||
|
readSync,
|
||||||
Stats,
|
Stats,
|
||||||
statSync,
|
statSync,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
|
@ -201,3 +204,11 @@ Deno.test(
|
||||||
assertEquals(res, [0, 1, 2, 3, 4, 5]);
|
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!);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue