Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tar entry destroyed when piping extract to pack #167

Open
mstimvol opened this issue Jul 17, 2024 · 0 comments
Open

tar entry destroyed when piping extract to pack #167

mstimvol opened this issue Jul 17, 2024 · 0 comments

Comments

@mstimvol
Copy link

Hi, I'm trying to "merge" multiple tar archives to one big archive using the tar-stream library and return the merged archive using fastify. My problem is, while merging the archives I'm getting the following error:

node:events:498
      throw er; // Unhandled 'error' event
      ^

Error: tar entry destroyed
    at Sink._getError (C:\app\node_modules\tar-stream\pack.js:111:36)
    at Sink._destroy (C:\app\node_modules\tar-stream\pack.js:121:53)
    at WritableState.updateNonPrimary (C:\app\node_modules\streamx\index.js:208:16)
    at WritableState.update (C:\app\node_modules\streamx\index.js:190:72)
    at WritableState.updateWriteNT (C:\app\node_modules\streamx\index.js:550:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
Emitted 'error' event on Extract instance at:
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at errorOrDestroy (node:internal/streams/destroy:239:7)
    at Extract.onerror (node:internal/streams/readable:1024:9)
    at Extract.emit (node:events:520:28)
    at WritableState.afterDestroy (C:\app\node_modules\streamx\index.js:500:19)
    at Extract._destroy (C:\app\node_modules\tar-stream\extract.js:301:5)
    at WritableState.updateNonPrimary (C:\app\node_modules\streamx\index.js:208:16)
    [... lines matching original stack trace ...]
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

My source is the following:

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

const { ReadableStream } = require('node:stream/web')

function addArchive (pack, archive) {
  const extract = tar.extract()
  archive.pipe(extract)

  return new Promise(resolve => {
    extract.on('entry', function (header, stream, callback) {
      if (header.type !== 'file') {
        callback()
      }

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

    extract.on('finish', resolve)
  })
}

async function handleRoute(req, reply) {
  const pack = tar.pack()
  const stream = ReadableStream.from(pack)

  reply.send(stream)

  const a1 = await axios.get('https://someurl/archive1.tar', {
    responseType: 'stream'
  })

  await addArchive(pack, a1.data)

  const a2 = await axios.get('https://someurl/archive1.tar', {
    responseType: 'stream'
  })

  await addArchive(pack, a2.data)

  pack.finalize()
}

I was already checking out #24 because it's very similar, but unfortunately I wasn't able to find a solution for my problem... Any ideas how I can solve the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant