mafintosh / tar-stream

tar-stream is a streaming tar parser and generator.
MIT License
406 stars 92 forks source link

Is it possible to remove/delete a file in the tar? #92

Closed jadams2305 closed 1 year ago

jadams2305 commented 5 years ago

Is it possible to remove/delete a file in the tar?

Like https://www.gnu.org/software/tar/manual/html_node/delete.html

Thank you

alxpsr commented 2 years ago

Yes, i did it like that

const tar = require('tar-stream');

function main(rawTar) {
  const extract = tar.extract();
  const pack = tar.pack();

  const readStream = Readable.from(rawTar);
  extract.on('entry', function (header, stream, callback) {
    if (header.name.match(/your-match-pattern/)) {
      header.name = header.name.replace(/your-pattern/, '');
    }

   stream.pipe(pack.entry(header, callback));
  })

  extract.on('finish', function () {
     pack.finalize();
  })

  readStream.pipe(extract);
}