Skip to content

v12 - avoid needless data copying in fs.promises.writeFileHandle when called with Uint8Array #35343

Closed
@joelrbrandt

Description

@joelrbrandt

Is your feature request related to a problem? Please describe.
In node v12, fs.promises.writeFileHandle performs needless data copying when writing a Uint8Array. See:
https://github.com/nodejs/node/blob/v12.x/lib/internal/fs/promises.js#L151

If data is a Uint8Array, the local variable buffer will actually be a Uint8Array object. Calling .slice on a Uint8Array creates a shallow copy of the values. This is documented both on MDN and in the node documentation.

Describe the solution you'd like
Don't use .slice on Uint8Arrays

Describe alternatives you've considered
Manually making a Buffer out of my Uint8Array before calling fs write functions.

Thanks for all your hard work in making Node awesome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions