Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Combined fstream.Reader ? #8

Open
Filirom1 opened this issue Apr 25, 2012 · 2 comments
Open

Combined fstream.Reader ? #8

Filirom1 opened this issue Apr 25, 2012 · 2 comments

Comments

@Filirom1
Copy link

Hi,

Is there a way to combine fstream Readers, into one Writer ?

For example I would like to pipe two different folders into a new one.

The ideal would be to do something like this:

fstream.CombinedReaders()
.append(fstream.Reader(dir1))
.append(fstream.Reader(dir2))
.pipe(options.tar ? tar.Pack() : fstream.Writer(outDir))

Or should I use the events do do it manually ?

BTW fstream looks really great, but the doc is quite thin :)

@isaacs
Copy link
Contributor

isaacs commented Apr 25, 2012

This would be a good idea for an fstream extension. (That is, a child class that inherits from Reader, but lives in its own repo/package.)

The question would be whether it's a merge, or just copies the two folders over as siblings. It would be pretty easy to do something like this:

CombinedReader.prototype.append = function (entry) {
  this.emit('entry', entry)
}

then the Writer will put them out as siblings.

But it sounds like what you really want is for the entries to be merged together. So, if the added Reader is a dir, then any entry events get emitted as entry events, and if it's not a Directory, then just emit a single entry event.

fstream.CombinedReaders()
.append(fstream.Reader(someDir))
.append(fstream.Reader(someFile))
.pipe(options.tar ? tar.Pack() : fstream.Writer(outDir))

So, then, that'd combine the contents of someDir, along with someFile, in either the tarball or the outDir.

@Filirom1
Copy link
Author

Thank you, I will try.
I will close this issue with a gist or something like that, if somebody need it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants