Skip to content
A proposed reference API for wren streams, implemented in wren with no native optimisation.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
example.wren
main.wren
stream.wren
streamChunk.wren
streamInputSequence.wren
streamOutputSequence.wren

README.md

wren-stream-proposal

A proposed reference API for wren streams, implemented in wren with no native optimisation.

API explination below

Abstract

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 example.wren.

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

API:

Strings are written to the Stream's 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 readFiber yields, and we wait until more data is buffered.

The Stream takes 3 flags as config:

  • writeable: can the Stream be written to in wren land
  • readable: can the Stream be read from in wren land
  • readPartialChunk: if false, the iterating over the stream will only produce chunks of exactly chunkSize in length. The last call to readFiber, when the Stream is closed will produce chunks of any length.

Not implemented

Overflow

Consider var overflow = (stream.writeInterface = input). If 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 Stream.

Pipe

Could probably do with a system for pipeing one stream into another

Transform

A Callable that transforms the contents of the buffer before it is passed to the read loop

You can’t perform that action at this time.