Description
Streams don't have an API that adheres to the node callback convention. This makes them awkward to use with other control flow tools. The following two methods would be the most useful:
readAll([encoding], function(err, data) {})
- on readable streams it collects all data, or is called with the first error
ended(function(err) {})
- Like the previous one, except it doesn't collect any data - its just called when everything ends (either successfully or at the first error). finished
could be used for writable streams.
Both of the above would act as if an .on('error', cb)
was attached.
The following would also be useful:
readNext(function(err, data) { ... })
Read the next packet or object. The callback is called with the current packet on the "next tick", with the "current packet" changing for subsequent requests right before the callback is called.
Would act as if a .once('error', cb)
was attached
And the last method would also be useful, but I'm unsure of the semantics:
writeNext(data, [enc], function(err) { ...})
- The callback would be called when the source is allowed to continue writing. Now I'm not entirely sure what this would mean, but I suppose that for streams with buffers, this would mean "called immediately" if the buffer is not full and called after flush if it is, and for streams without buffers this would be called after flush.
This should be taken as a rough sketch, as I'm not sure I understand enough about node streams internals to give a good proposal :)
edit: sorry for the close/open noise, I accidentally the button.