Georges R
Georges R

Reputation: 1

Node.js: Pipe data parsed from "zlib.createGunZip" and "tar.extract" to custom transform function

I am using packages "tar-stream" and "zlib" to extract files from a TGZ file.

Is there a way to send data to a custom Transform function ?

"tarStream.extract()" doesn't have a ".pipe()" callback so i can't build my own data and send it to the next pipe.

Thanks

My code down below:

fs.createReadStream("/path/to/my/tgz/file")
    .pipe(zlib.createGunzip())
    .pipe(extract)
    // .pipe(myCustomTransformer); <---- this doesn't work, getting an error

extract.on("entry", (header, stream, next) => {
    let chunks = '';

    stream.on("end", async function() {
        /*
         * Try to pipe some data to a custom transform function ...
         * Example: ().pipe(myCustomTransformer, { chunks })
         */
        next();
    });

    stream.on("data", chunk => chunks += chunk.toString("utf-8"));
});

Upvotes: 0

Views: 37

Answers (0)

Related Questions