Skip to content

stream: add an option to let stream.pipeline not throw if the source is destroyed #48667

Closed as not planned
@ErickWendel

Description

@ErickWendel

What is the problem this feature will solve?

Reopening it to discuss.

When using standard source.pipe(dest) source will not be destroyed if dest emits close or an error.

stream.pipeline came to solve this problem but if the source is destroyed it throws an error of premature close.

see the example below:

import stream from 'stream'

setTimeout(() => process.stdin.destroy(), 200);

stream.promises.pipeline(
    process.stdin,
    process.stdout,
    { end: false }
)
// Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close

it works If I explicitly convert it to a readable stream and override it as:

import stream from 'stream'

const stdin = stream.Readable.from(process.stdin, { emitClose: false })
setTimeout(() => stdin.destroy(), 200);

stream.promises.pipeline(
    stdin,
    process.stdout,
    { end: false }
)

Still, for DX reasons pipeline IMHO should be able to consume partial streams without relying on its source if users want to.

cc @nodejs/streams WDYT?

What is the feature you are proposing to solve the problem?

The idea is to add an option to let stream.pipeline not throw if the source is destroyed. This is useful when working with files and an user disconnects from the webserver and it's not needed to consume the full stream

@nodejs/streams

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions