Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
How do I extract a tar file in nodejs using the pipeline() method?

My current code looks like this:

const gzip2 = zlib.createUnzip();
const pack2 = new tar.Unpack();
const source2 = Readable.from('public/img.tar.gz');
const destination2 = fs.createWriteStream('public/images2');
pipeline(source2, gzip2, pack2, destination2, (err) => {
    if (err) {
        console.error('An error occurred:', err);
        process.exitCode = 1;
    }
});

But I'm getting this error:

internal/streams/pipeline.js:108
  throw new ERR_INVALID_ARG_TYPE(
  ^

TypeError [ERR_INVALID_ARG_TYPE]: The "val" argument must be an instance of Readable, Iterable, or AsyncIterable. Received an instance of Unpack
    at makeAsyncIterable (internal/streams/pipeline.js:108:9)
    at pipeline (internal/streams/pipeline.js:265:15)
    at Object.<anonymous> (/mnt/c/index.js:39:1)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'
}

I've also tried

const pack2 = tar.extract();

without luck. If anyone can help me to extract this tar file using pipeline, so that I can also unzip the file. I would be very grateful. I've seen people use .pipe(tar.extract()) online, but I'm trying to keep my code as clean and uniform as possible. This: https://www.npmjs.com/package/tar has unfortunately not been very helpful.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

const tar = require('tar.gz2')
var read = tar().createReadStream('/public/images');
var write = fs.createWriteStream('compressed.tar.gz');
pipeline(read,write,  
   (err) => {
   if (err) {
    throw err
   }
})
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda