kriskowal/q-io — pull request #57 by kriskowal (2013-10-08 04:01:53+00:00)
Title: Promise streams

All specs pass.

Implemented Readable as an abstract interface that provides `forEach`,
`map`, `reduce`, `buffer`, `all`, `copy`, and `read` for any
implementation that provides the asynchronous iterator method, `next`.
Readable makes use of a semaphore `Queue` and a `Pipe` to control
back-pressure based on user-given or methd-specific-default parallelism
limits.

Implemented a Reader stream that wraps an array or any object, local or
remote, that provides a `next` method, including iterators and generator
iterators. Thus, a stream can lazily consume an indefinite iteration.

Brought in a cleaner implementation of the indefinite promise `Queue`.
This implementation lacks the `close` and `closed` hacks that exist in
the current `q/queue`, which will likely be removed when these changes
get traction, particularly in Q-Connection.

Implemented a Buffer stream, backed by a Queue, that provides both
`Reader` and `Writer` interfaces.

The Node.js stream reader has been reimplemented based on the latest
rendition of Node.js streams and the new `Buffer`, so promise streams
send back pressure down to the underlying system. Cosmetic changes only
to `Writer`.

Created a separate Mock file stream, which manages an internal `chunks`
array which can be reused on mock file system nodes between reads and
writes. This turned out to be different enough from `Reader` and
`Buffer` that a different implementation was needed.

BufferStream is deprecated in favor of Buffer or MockFsStream.