Skip to content

[docs] Describe what FS.init() callbacks really receive. NFC - #28118

Open
n-hiraha wants to merge 1 commit into
emscripten-core:mainfrom
n-hiraha:docs/fs-init-callback-bytes
Open

n-hiraha wants to merge 1 commit into
emscripten-core:mainfrom
n-hiraha:docs/fs-init-callback-bytes

Conversation

@n-hiraha

Copy link
Copy Markdown

Fixes #17117.

The FS.init() docs say the callbacks deal in "ASCII character codes" and that output gets null to flush. Testing with emcc 6.0.13 on Node, that's not what happens:

  • output gets one call per byte, as a signed value, because fd_write passes HEAP8. Writing "é" gives -61, -87.
  • output is never called with null, even after fflush, fsync, or exit.
  • input can return any byte 0-255. null means end of input (read returns 0), and undefined with nothing read yet gives EAGAIN.

This only updates the docs to match. Switching output to unsigned bytes would change what existing callbacks see, so I left that alone, but I'm happy to look at it if you'd prefer.

The input and output callbacks deal in bytes, not ASCII character codes.
output gets each byte as a signed value (from HEAP8) and is never called
with null. input returns 0-255, null for end of input, or undefined for
no data yet.

Fixes emscripten-core#17117.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Filesystem API documentation in Filesystem-API.rst to clarify the behavior of the input and output callbacks. Specifically, it explains that these callbacks are executed once per byte, details the expected return values and ranges (including handling of undefined for EAGAIN and signed integers for output), and provides instructions on how to retrieve unsigned bytes. There are no review comments, and I have no feedback to provide.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misinformation in the FS.init() docs

1 participant