A proposed reference API for wren streams, implemented in wren with no native optimisation.
API explination below
These streams would be used to unify the interface for file/stdin/stdout/network reading/writing.
The hope is that once an API for the
Stream class is decided on, a partially native implementation can be made to improve performance.
A reference implementation can be found in
main.wren, and an example usage can be found in
Please have a play about, and try to find any issues/improvements
Opening Issues and creating Pull Requests is highly encouraged (and in fact the only reason this repo exists)
I hope that the code is clear, but if there is any confusion please open an issue, or message me on twitter @FreddieRidell
Strings are written to the
writeInterface, this triggers the stream to call its
readFiber, which can then iterate through a
Sequence generated by the
Stream to read the buffered data out. Once there is more more data to read, the
yields, and we wait until more data is buffered.
Stream takes 3 flags as config:
writeable: can the
Streambe written to in wren land
readable: can the
Streambe read from in wren land
readPartialChunk: if false, the iterating over the stream will only produce chunks of exactly
chunkSizein length. The last call to
readFiber, when the
Streamis closed will produce chunks of any length.
var overflow = (stream.writeInterface = input).
input will not fully fit in the stream buffer, the remainder is returned to
overflow so the calling script can push the remaining data into the
Could probably do with a system for pipeing one stream into another
Callable that transforms the contents of the buffer before it is passed to the read loop