simple streams for galaxy
galaxy-streams module provides a simple API to work with node.js streams. It contains wrappers for all the main streams of the node API, as well as generic
Once you have wrapped a readable stream, you can read from it with:
var data = yield stream.read(size);
size parameter is optional. If you pass it and if the stream does not end prematurely, the
read call returns a
Buffer of exactly
size characters / bytes. If the stream ends before
size characters / bytes, the remaining data is returned. If you try to read past the end of the stream,
null is returned.
read returns the next chunk of data available from the stream, as a
Buffer depending on encoding. It returns
null at the end of the stream.
Readable streams also support a synchronous
unread(data) method, which is handy for parsers.
Writable streams are similar. Once you have wrapped a writable stream, you can write to it with:
yield stream.write(data, encoding);
Encoding is optional. For a binary stream, you do not pass any
data is a
Buffer. For a character stream, you must pass an
data is a
To end a stream, just write
. For example:
yield stream.write();. You can also end it with a synchronous