Skip to content

[BUG] Pipeline stream unexpectly being closed when using extract #321

@jeferson-sb

Description

@jeferson-sb

What / Why

When you attempt to extract a tarball through streams sometimes it will be closed with an error: [ERR_STREAM_PREMATURE_CLOSE]: Premature close, although the files are successfully extracted. No Errors Codes are shown in the process.

It seems to happen only on newer versions of Node > v18
Looking at the spec it seems now that streams that emit a close event before a end event trigger this error, so worth taking a look on that.

When

  • n/a

Where

  • n/a

How

Current Behavior

  • It throws an ERR_STREAM_PREMATURE_CLOSE Error when trying to extract

Steps to Reproduce

$ nvm install 18.7.0
$ npm install tar got
$ mkdir output
import stream from 'node:stream';
import { promisify } from 'util';
import tar from 'tar';
import got from 'got';

const pipeline = promisify(stream.pipeline);

pipeline(
  got.stream('https://codeload.github.com/npm/node-tar/tar.gz/main'),
  tar.extract({ cwd: './output' }, ['node-tar-main/lib'])
)

Expected Behavior

  • It should extract the content of the archive without any issues

References

  • Related to Next.js Issue #39321

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions