From 31d63707a90a8f6f623ed9d25721aa7e3b35102e Mon Sep 17 00:00:00 2001 From: Hirahara Date: Sat, 31 Oct 2026 11:07:16 +0900 Subject: [PATCH] [docs] Describe what FS.init() callbacks really receive. NFC 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 #17117. --- site/source/docs/api_reference/Filesystem-API.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/site/source/docs/api_reference/Filesystem-API.rst b/site/source/docs/api_reference/Filesystem-API.rst index fbafd51c52394..27349166c16d3 100644 --- a/site/source/docs/api_reference/Filesystem-API.rst +++ b/site/source/docs/api_reference/Filesystem-API.rst @@ -284,11 +284,15 @@ By default: malfunctioned. :param input: Input callback. This will be called with no parameters whenever - the program attempts to read from ``stdin``. It should return an ASCII - character code when data is available, or ``null`` when it isn't. - :param output: Output callback. This will be called with an ASCII character - code whenever the program writes to ``stdout``. It may also be called with - ``null`` to flush the output. + the program attempts to read from ``stdin``, once per byte. It should return + the next byte as an integer in the range 0-255, ``null`` at the end of the + input, or ``undefined`` if no data is available yet (a read that has not + received any bytes then fails with ``EAGAIN``). + :param output: Output callback. This will be called once for each byte the + program writes to ``stdout``. The byte is passed as a signed integer in the + range -128 to 127, so bytes above 127 (such as the bytes of a multi-byte + UTF-8 character) arrive as negative numbers. Use ``value & 0xFF`` to get + the unsigned byte. :param error: Error callback. This is similar to ``output``, except it is called when data is written to ``stderr``.