Skip to content

stream: suggestion stream._writeMany #29034

@ronag

Description

@ronag

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.streamIssues 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