Skip to content
creationix edited this page Aug 30, 2012 · 1 revision

This page documents various API Interfaces

Readable Stream (not implemented yet)

A readable stream is an Emitter with a :read(callback) method on it. The callback will be called with (value, [encoding]) if there is data left in the stream and with () when the stream is done. In data streams, the value will be a lua string. But streams can also contain arbitrary values. The optional encoding value is a string, and it's meaning is not defined by the interface. Encoding should be omitted for pure data streams where raw strings are used.

When implementing readable streams, you should pause your input source if the read callback doesn't call read again in the same tick. If your input is paused when .read is called, then it should be resumed. You should also pause the input stream if read isn't called within the first tick of the stream being created.

If there is some error reading, then emit an "error" event on the stream itself.

To make is easier for others to know this is readable, set a .readable property to some truthy value on the stream table.

In the core.iStream class (which inherits from core.Emitter) There will be a :pipe(dest) method that pipes a readable stream into a writable stream. Inherit from iStream instead of Emitter (and set .readable) if you want this method available on your stream.

Clone this wiki locally