bjorn3 / browser_wasi_shim

A WASI shim for in the browser
Apache License 2.0
307 stars 41 forks source link

feature request: implement `fd_pread`, golang `"archive/zip"` library fails because `fd_pread` returns `-1` #43

Closed HarikrishnanBalagopal closed 1 year ago

HarikrishnanBalagopal commented 1 year ago

https://github.com/bjorn3/browser_wasi_shim/blob/f4d2382d9e61d6fda580b7a5afb37699a0015745/src/fd.ts#L38-L39

time="2023-10-11T10:49:24Z" level=fatal msg="impossible to open zip reader: read /language-platforms.zip: errno 4294967295"
proxy for fd_pread !! 4 25784616 1 128772n 25784612
index.js:110 return_value for fd_pread is -1

-1 becomes positive 4294967295 2^32-1 in javascript because of signed 2s complement being interpreted as unsigned javascript number

bjorn3 commented 1 year ago

When I initially prototyped this project I returned -1 as error for unimplemented things rather than a real error. Some usages have been fixed since, but several still remain. fd_pread is one of those unimplemented syscalls.

HarikrishnanBalagopal commented 1 year ago

When I initially prototyped this project I returned -1 as error for unimplemented things rather than a real error. Some usages have been fixed since, but several still remain. fd_pread is one of those unimplemented syscalls.

Right, is it feasible to implement it? It's required for basic stuff like expanding a zip archive. https://www.practical-go-lessons.com/post/how-to-unzip-a-file-or-directory-with-golang-ccb0328321as70o6ujjg

I can contribute a PR if it's feasible.

Read from the file at the given offset without updating the file cursor. This acts like a stateless version of Seek + Read.

The description sounds a lot like a normal fd_read

https://github.com/bjorn3/browser_wasi_shim/blob/f4d2382d9e61d6fda580b7a5afb37699a0015745/src/fs_fd.ts#L19-L38

Not sure if there any blockers that I am not aware of.

bjorn3 commented 1 year ago

I think you could copy the fd_read impl except use the given file offset instead of reading and modifying this.file_pos.

HarikrishnanBalagopal commented 1 year ago

@bjorn3 have implemented the fd_pread and now Golang "archive/zip" is working for expanding .zip archives.

bjorn3 commented 1 year ago

Nice! Merged your PR.