Skip to content

Commit

Permalink
Use arrayBuffer instead of bytes for better compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
UX3D-haertl committed Aug 13, 2024
1 parent 9eadb93 commit 29f4448
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export default async () => {
const parent = model.mainFile.substring(0, model.mainFile.lastIndexOf("/") + 1);
return new Promise((resolve, reject) => {
fetch(parent + uri).then(response => {
response.bytes().then(buffer => {
resolve(buffer);
response.arrayBuffer().then(buffer => {
resolve(new Uint8Array(buffer));
}).catch(error => {
reject(error);
});
Expand All @@ -67,9 +67,11 @@ export default async () => {
});
};
const response = await fetch(model.mainFile);
const buffer = await response.bytes();
const result = await validateBytes(buffer, {externalResourceFunction: externalRefFunction, uri: model.mainFile});
return result;
const buffer = await response.arrayBuffer();
return await validateBytes(new Uint8Array(buffer), {
externalResourceFunction: externalRefFunction,
uri: model.mainFile
});
} else if (Array.isArray(model.mainFile)) {
const externalRefFunction = (uri) => {
uri = "/" + uri;
Expand All @@ -83,8 +85,8 @@ export default async () => {
}
}
if (foundFile) {
foundFile.bytes().then((buffer) => {
resolve(buffer);
foundFile.arrayBuffer().then((buffer) => {
resolve(new Uint8Array(buffer));
}).catch((error) => {
reject(error);
});
Expand All @@ -94,8 +96,11 @@ export default async () => {
});
};

const buffer = await model.mainFile[1].bytes();
return await validateBytes(buffer, {externalResourceFunction: externalRefFunction, uri: model.mainFile[0]});
const buffer = await model.mainFile[1].arrayBuffer();
return await validateBytes(new Uint8Array(buffer), {
externalResourceFunction: externalRefFunction,
uri: model.mainFile[0]
});
}
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 29f4448

Please sign in to comment.