copy / copy/v86

read_file returns null for empty file

Open
#659 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
23.5k
Forks
1.9k
Avg merge
2d 14h
Merged PRs (30d)
7

Description

If an empty file is created by a command, `FS.read_file` returns `null` instead of empty `Uint8Array`. Empty files created by `create_file` doesn't have this issue.

This happens because of [this line](https://github.com/copy/v86/blob/56b74146/lib/filesystem.js#L1132) in `get_data`, but I don't know if it can be changed to `return new Uint8Array`. There is similar code in `get_buffer`, which also claims to `@return {!Promise}`.

How to reproduce: execute command `touch /mnt/f` in the following VM, then press `read f` button. Result: `null` is printed to js console.
```html

onload = function()
{
emulator = new V86Starter({
wasm_path: "../build/v86.wasm",
bios: { url: "../bios/seabios.bin" },
vga_bios: { url: "../bios/vgabios.bin" },
bzimage: { url: "../images/buildroot-bzimage.bin" },
filesystem: {},
screen_container: screen_container,
autostart: true
});
}
async function read_f()
{
let data = await emulator.fs9p.read_file("f");
console.log(data);
}




read f
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.