fstream icon indicating copy to clipboard operation
fstream copied to clipboard

Combined fstream.Reader ?

Open Filirom1 opened this issue 13 years ago • 2 comments

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 :)

Filirom1 avatar Apr 25 '12 21:04 Filirom1

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.

isaacs avatar Apr 25 '12 22:04 isaacs

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

Filirom1 avatar Apr 26 '12 05:04 Filirom1