npm / fstream

Advanced FS Streaming for Node
ISC License
208 stars 43 forks source link

entries (stream of streams) interface for other modules #10

Closed alunny closed 12 years ago

alunny commented 12 years ago

fstream is awesome. I'm working on a zip/unzip module that interoperates with it - http://github.com/alunny/zstream

I've gotten unzip to work with the Directory Writer stream - just wondering if I'm missing anything obvious I need to implement, or if I'm making any assumptions about this.

For unzipping, I have a stream called UnzipStream that emits entry events with FileEntry objects.

UnzipStream patches pipe like so:

UnzipStream.prototype.pipe = function (dest) {
    if (typeof dest.add == 'function') {
        this.on('entry', function (entry) {
            dest.add(entry);
        });
    }

    Stream.prototype.pipe.call(this, dest);
}

Each FileEntry has a path property and a props property. Then it acts as a regular readable stream (decompressing the content) that gets written to a new FileEntry.

Does that all sound sane? I can write up a doc for using other libraries with fstream if this is generally useful.

isaacs commented 12 years ago

That sounds pretty much exactly right, and basically the same thing that node-tar does. Yes, documentation would be super duper rad.

Note: a lot about fstream will change when I eventually port it to use the new 0.10-style node streams. Check out the action on https://github.com/isaacs/readable-stream or https://github.com/joyent/node/commits/streams2

alunny commented 12 years ago

Cool.

I still need to work on the other direction (DirectoryReader -> ZipStream), but I'll work on a doc after that.