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.
|
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?
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
Would you be able to expose a synchronous API for
load? Maybe namedparse, which takes in anArrayBuffer?