I created a module that does this https://github.com/fent/node-kat

You want to give the option to pass a stream into the collection of streams 
to concatenate because streams do not only exist from the file system.

Reading data sequentially is the way to do it, since what you're doing is 
concatenating, order matters. Doing it in parallel would mean to keep a lot 
of those data events in memory, taking away one of the main benefits of 
using streams.

The way node-kat does it is it opens all of the files at once, with an 
opening queue, and not if the passed input is a stream already. Then, since 
it supports reading fromt a given start to a given end, it looks at each 
file's stat for the file size. Then it creates a readable stream as it 
needs them.

On Friday, July 20, 2012 7:25:32 AM UTC-7, Juan Ignacio Dopazo wrote:
>
> Hi!
>
> While learning about streams I ended up trying to write a module that 
> reads several files and concatenates them. I liked the idea of writing it 
> as a Stream mostly because of the API and how it plays along with other 
> streams:
>
> combo.createStream(['foo.js', 
> 'bar.js']).pipe(zlib.createGzip()).pipe(httpResponse);
>
> At first I thought about keeping a stack of files, creating reading 
> streams sequentially and firing only "data" events until I emptied the 
> stack. But "sequential" doesn't sound fast.
>
> I'm having trouble finding good information about streams, so I thought 
> about asking here. Do you think it makes sense to use streams in this case? 
> Should I open all streams at the same time and fire "data" events in order? 
> Or is the callback based version enough? What other advantages do streams 
> provide compared to the callback based API?
>
> Thanks,
>
> Juan
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to