wren-lang / wren-cli

A command line tool for the Wren programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the correct behavior of `Stdin.readByte`?

joshgoebel opened this issue · comments

Working on new File IO abstractions and found this TODO issue:

if (__buffered != null) {
        // TODO: Is this correct for readByte()?
        // Emit the last remaining bytes.
        var result = __buffered
        __buffered = null
        __waitingFiber.transfer(result)

This behavior is clearly incorrect. If the input closes then the last call to readByte will return a string with all remaining buffered data (or an empty string), not a byte. This begs the question of what SHOULD happen? I would suggest that repeat calls to readByte should continue to return bytes until either null (is returned repeatedly) or a Fiber.abort is triggered.

This is the same question as with readLine on whether reaching the EOF should be an error condition or not.

Related: #125