Skip to content

Commit

Permalink
Fixed shims from not displaying debug information.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Mar 7, 2021
1 parent c5a53d6 commit a953f71
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions packages/shims/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,25 @@
var fr = new FileReader();
try {
fr.readAsArrayBuffer(new Blob([ "hello" ], { type: "text/plain" }));
return;
} catch (error) { }

shims.push("FileReader.prototype.readAsArrayBuffer");
FileReader.prototype.readAsArrayBuffer = function (blob) {
if (this.readyState === this.LOADING) throw new Error("InvalidStateError");
this._setReadyState(this.LOADING);
this._result = null;
this._error = null;
var fr = new FileReader();
fr.onloadend = () => {
var content = atob(fr.result.split(",").pop().trim());
var buffer = new ArrayBuffer(content.length);
var view = new Uint8Array(buffer);
view.set(Array.from(content).map(c => c.charCodeAt(0)));
this._result = buffer;
this._setReadyState(this.DONE);
};
fr.readAsDataURL(blob);
} catch (error) {
shims.push("FileReader.prototype.readAsArrayBuffer");
FileReader.prototype.readAsArrayBuffer = function (blob) {
if (this.readyState === this.LOADING) { throw new Error("InvalidStateError"); }
this._setReadyState(this.LOADING);
this._result = null;
this._error = null;
var fr = new FileReader();
fr.onloadend = () => {
var content = atob(fr.result.split(",").pop().trim());
var buffer = new ArrayBuffer(content.length);
var view = new Uint8Array(buffer);
view.set(Array.from(content).map(c => c.charCodeAt(0)));
this._result = buffer;
this._setReadyState(this.DONE);
};
fr.readAsDataURL(blob);
}
}

} catch (error) {
console.log("Missing FileReader; unsupported platform");
}
Expand Down

0 comments on commit a953f71

Please sign in to comment.