Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

RFC: Support ArrayBuffer as an alternative to Buffer input argument #404

@lidel

Description

@lidel

Status

Right now we accept cid, multihash and data as Buffer in various places across entire JS API. It makes sense for Node.js and there was no better alternative for use in browsers at a time.

The landscape changed and we now have native vendor support for ArrayBuffer in web browsers:

The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.

Proposed API Improvement

Short and sweet:

  • Add support for ArrayBuffer as input in every API that accepts Buffer right now.

Why?

  • Low risk, High win:
    • This is backward-compatible change (Buffer support remains)
    • Should be a relatively small change (internally detect and convert ArrayBuffer to Buffer for now)
    • DRY: removes the need of tedious type conversion of various inputs
    • enables browser console experimentation without need for Buffer polyfil
    • Together with Async Iterators makes JS API feel modern an more attractive to developers

Refs

cc @alanshaw

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions