denoland / denoland/dnt

readFile() and readFileSync() output don't match

Open
#449 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.3k
Forks
49
PR merge metrics
No merged PRs in 30d

Description

The reproduction code is below.
This is happening in 0.41.3, but also in previous versions.

mod.js
```
export function check(uint8array) {
console.log(uint8array.buffer);
}
```

test.js
```
import { check } from "./mod.js";

Deno.test("readFileSync", () => {
const uint8array = Deno.readFileSync("file");
check(uint8array);
});
Deno.test("readFile", async () => {
const uint8array = await Deno.readFile("file");
check(uint8array);
});
```

deno run -A build_npm.js
```
Running tests in ./esm/test.js...

test readFileSync ...ArrayBuffer {
[Uint8Contents]: <2f 00 00 00 00 00 00 00 00 01 00 00 00 0b 00 80 00 03 00 30 47 53 55 42 20 8b 25 7a 00 00 01 38 00 00 00 54 4f 53 2f 32 38 3e 45 89 00 00 01 8c 00 00 00 60 63 6d 61 70 e9 b2 bd 48 00 00 01 f4 00 00 01 70 67 6c 79 66 bb e0 8f 70 00 00 03 6c 00 00 00 50 68 65 61 64 25 2b ff 77 00 00 00 e0 00 00 00 36 ... 8092 more bytes>,
byteLength: 8192
}
test readFile ...ArrayBuffer {
[Uint8Contents]: <00 01 00 00 00 0b 00 80 00 03 00 30 47 53 55 42 20 8b 25 7a 00 00 01 38 00 00 00 54 4f 53 2f 32 38 3e 45 89 00 00 01 8c 00 00 00 60 63 6d 61 70 e9 b2 bd 48 00 00 01 f4 00 00 01 70 67 6c 79 66 bb e0 8f 70 00 00 03 6c 00 00 00 50 68 65 61 64 25 2b ff 77 00 00 00 e0 00 00 00 36 68 68 65 61 03 d6 02 03 ... 1580 more bytes>,
byteLength: 1680
}
```
Only the result of `readFile()` is correct.
I know the following workaround, but I don't want to use it because it involves memory copying.

```
export function check(uint8array) {
const arrayBuffer = uint8array.buffer.slice(
uint8array.byteOffset,
uint8array.byteOffset + uint8array.byteLength
);
console.log(arrayBuffer);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.