playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
33 lines (32 loc) • 686 B
JavaScript
import { http, Http } from "../../platform/net/http.js";
import { ResourceHandler } from "./handler.js";
class BinaryHandler extends ResourceHandler {
constructor(app) {
super(app, "binary");
}
load(url, callback) {
if (typeof url === "string") {
url = {
load: url,
original: url
};
}
http.get(url.load, {
responseType: Http.ResponseType.ARRAY_BUFFER,
retry: this.maxRetries > 0,
maxRetries: this.maxRetries
}, (err, response) => {
if (!err) {
callback(null, response);
} else {
callback(`Error loading binary resource: ${url.original} [${err}]`);
}
});
}
openBinary(data) {
return data.buffer;
}
}
export {
BinaryHandler
};