Cannot pipe. Not readable.
vitkarpov opened this issue · 5 comments
Here's the point:
var concat = require('concat-stream');
process.stdin
.pipe(concat(function(buff) {
// do smth
}))
.pipe(process.stdout);
It gives the following:
Error: Cannot pipe. Not readable.
at ConcatStream.Writable.pipe (.../node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:142:22)
Why chaining is broken in this case? Does concat-stream apply this one?
concat-stream isn't a readable stream, just a writable one. you can do this though:
process.stdin
.pipe(concat(function(buff) {
process.stdout.write(buff)
}))
Is there a reason why concat-stream
isn't readable? I would really benefit from that, instead of having to create a new readable from the output.
Yea, concat stream is the end-of-the-line for streaming data. It wouldn't
make sense to pipe it somewhere as it would only emit a single buffer,
hence the single callback API. Streams are for when you have a series of
chunks
On Tuesday, February 25, 2014, Karel Ledru-Mathé notifications@github.com
wrote:
Is there a reason why concat-stream isn't readable? I would really
benefit from that, instead of having to create a new readable from the
output.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/20#issuecomment-36062251
.
I understand your point. I guess it makes sense it most cases. Though here is my use case (I am new to streams).
I am writing a parser that extract pieces of informations recursively in all the files within a folder (and subfolders). Once all is parsed, I use concat-stream
to merge all the information in a single array.
Now let's say I want to create a gulp plugin out of this. I should return a stream so other plugin could pipe into my plugin. Right now, I should 'hack' it in the final callback.
I think being able to pipe the result of concat stream would make it more "composable". I actually have an use case where I want to either concat a stream into one big array or emit the chunks one at a time to another stream. Callback being the only API makes that a bit difficult.
update
Workaround I came up with.
stream-reduce = require 'stream-reduce'
# append :: a → [a] → [a]
{append, flip} = require 'ramda'
concat-stream = stream-reduce flip(append), []
stream
.pipe concat-stream
.on \data ->
# data [1,2]
stream.push 1
stream.push 2
stream.push null