playcanvas
Version:
PlayCanvas WebGL game engine
33 lines (30 loc) • 744 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 };