Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

stream: suggestion stream._writeMany #29034

Copy link
Copy link
@ronag

Description

@ronag
Issue body actions

Currently the stream.writev API has two drawbacks:

  • It requires adding properties to the input array (allBuffers).
  • It will always creates an array copy.
  • The array entries must be allocated objects.

It would be nice if user space could just create the correctly formatted array without having to perform any allocations, copies and transformations.

In order to not break anything I suggest a new signature writev maybe called writeMany?

Which would look something like:

Stream._writeMany = function (chunks, allBuffers, cb) {
}

e.g.

const chunks = [];
for (const { chunk } of data) {
  chunks.push(chunk);
}
w._writeMany(chunks, true, cb);
const chunks = [];
for (const { chunk, encoding } of data) {
  chunks.push(chunk, encoding);
}
w._writeMany(chunks, false, cb);

Looking at the current Writable implementation, the writev scenario will always create two "unnecessary" array copies in order to pass the chunks. Furthermore all the array entries are allocated objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.