Implement a new `readByte()` static method on the `Stdin` class that reads one byte from standard input, blocking the current fiber until a byte is received. The method returns the byte value as a number or `null` if stdin is closed. Refactor the internal buffering mechanism by introducing a shared `read_()` helper method that both `readByte()` and `readLine()` use, replacing the previous per-method buffering logic. The `readByte()` implementation peels off the first byte from the internal `__buffered` string using `bytes[0]` and slicing. Add two test files: `read_byte.wren` verifying byte-by-byte reading of "first" and "second" input lines, and `read_byte_eof.wren` confirming that reading after stdin is closed returns the expected error message.
20 lines
433 B
Markdown
20 lines
433 B
Markdown
^title Stdin Class
|
|
|
|
The standard input stream.
|
|
|
|
## Static Methods
|
|
|
|
### **readByte**()
|
|
|
|
Reads one byte of input from stdin. Blocks the current fiber until a byte has
|
|
been received.
|
|
|
|
Returns the byte value as a number or `null` if stdin is closed.
|
|
|
|
### **readLine**()
|
|
|
|
Reads one line of input from stdin. Blocks the current fiber until a full line
|
|
of input has been received.
|
|
|
|
Returns the string of input or `null` if stdin is closed.
|