Skip to content

Commit

Permalink
Added ArrayBuffer support (#36)
Browse files Browse the repository at this point in the history
* Added ArrayBuffer support

Added support for loading ArrayBuffer type

* Define arrayBuf outside of the conditional for scoping

---------

Co-authored-by: Jordan Matelsky <j6k4m8@users.noreply.github.com>
  • Loading branch information
AdityaSarwade and j6k4m8 authored Aug 4, 2023
1 parent 2f1fb64 commit e92af61
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ class npyjs {
Loads an array from a stream of bytes.
*/
fetchArgs = fetchArgs || {};
const resp = await fetch(filename, { ...fetchArgs });
const arrayBuf = await resp.arrayBuffer();
let arrayBuf;
// If filename is ArrayBuffer
if (filename instanceof ArrayBuffer) {
arrayBuf = filename;
}
// If filename is a file path
else {
const resp = await fetch(filename, { ...fetchArgs });
arrayBuf = await resp.arrayBuffer();
}
const result = this.parse(arrayBuf);
if (callback) {
return callback(result);
Expand Down

0 comments on commit e92af61

Please sign in to comment.