Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.read() always returns 0 bytes in JS backends #20501

Closed
justinas opened this issue Jan 11, 2024 · 0 comments · Fixed by #20633
Closed

File.read() always returns 0 bytes in JS backends #20501

justinas opened this issue Jan 11, 2024 · 0 comments · Fixed by #20633
Labels
Bug This tag is applied to issues which reports bugs. Unit: JS Bugs/feature requests, that are related to the JavaScript backend.

Comments

@justinas
Copy link

justinas commented Jan 11, 2024

Describe the bug

In both js and js_browser backends, File.read() call seems to read 0 bytes

Reproduction Steps

import os

mut buf := []u8{len: 10}
f := os.open('/etc/hosts') or { panic(err) }
n := f.read(mut &buf) or { panic(err) }
println(buf[..n])

Expected Behavior

Using the js backend: expected to either read a non-zero amount of bytes, or raise an error.

Using the js_browser: expected to either fail compilation (since File I/O is unavailable in the browser), or for os.open() to always return an error.

Current Behavior

$ v run read_file.v    # runs as expected
[49, 50, 55, 46, 48, 46, 48, 46, 49, 32]
$  v -o read_file.js read_file.v && node read_file.js
[]
$ v -b js_browser -o read_file.js read_file.v && node read_file.js
[]

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.4 ac2dcc2

Environment details (OS name and version, etc.)

NixOS 23.11 (Tapir)
Node v18.18.2

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@justinas justinas added the Bug This tag is applied to issues which reports bugs. label Jan 11, 2024
@felipensp felipensp added the Unit: JS Bugs/feature requests, that are related to the JavaScript backend. label Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Unit: JS Bugs/feature requests, that are related to the JavaScript backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants