title: How do I extract a tar file in nodejs using the pipeline() method?
body: <p>My current code looks like this:</p>
  <pre><code>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) =&gt; {
      if (err) {
          console.error('An error occurred:', err);
          process.exitCode = 1;
      }
  });
  </code></pre>
  <p>But I'm getting this error:</p>
  <pre><code>internal/streams/pipeline.js:108
    throw new ERR_INVALID_ARG_TYPE(
    ^
  
  TypeError [ERR_INVALID_ARG_TYPE]: The &quot;val&quot; 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.&lt;anonymous&gt; (/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'
  }
  </code></pre>
  <p>I've also tried</p>
  <pre><code>const pack2 = tar.extract();
  </code></pre>
  <p>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: <a href="https://www.npmjs.com/package/tar" rel="nofollow noreferrer">https://www.npmjs.com/package/tar</a> has unfortunately not been very helpful.</p>