Skip to content

New principle: APIs which vend byte buffers should return a Uint8Array #463

@bakkot

Description

@bakkot

This already seems to be a principle. See some more discussion here.

ArrayBuffer is almost never what you want because you can't read from one directly. You have to create a view such as a Uint8Array to actually read it.

Almost all APIs which accept an ArrayBuffer also accept a Uint8Array, and some APIs require a Uint8Array, so it's rare for a Uint8Array to be less convenient than an ArrayBuffer.

This is currently somewhat inconsistent: some APIs (like Response) provide an ArrayBuffer, while others (like TextEncoder) provide a Uint8Array. Having this written down as a principle could help with that.

I'm not sure what the process here is, but if this is accepted I'm happy to send a PR adding this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions