Skip to content

Synchronous API to parse an ArrayBuffer #68

@kylebarron

Description

@kylebarron

In my opinion it's really weird that you only expose an async method to load an NPY file.

Nothing about the NPY parsing itself requires asynchronous work, but you interleave data fetching and parsing into a single function, making it harder for downstream users to use, and impossible to use from a sync context.

npyjs/src/index.ts

Lines 146 to 156 in 3536ce1

let buf: ArrayBufferLike;
if (typeof source === "string") {
const res = await fetch(source);
buf = await res.arrayBuffer();
} else if (source instanceof ArrayBuffer) {
buf = source;
} else if (source instanceof Blob) {
buf = await source.arrayBuffer();
} else {
buf = source.buffer;
}

Would you be able to expose a synchronous API for load? Maybe named parse, which takes in an ArrayBuffer?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions