Skip to content

Instantly share code, notes, and snippets.

@nkint
Created September 28, 2019 14:45
Show Gist options
  • Save nkint/823a4d308eee300c272a32f4213bb59e to your computer and use it in GitHub Desktop.
Save nkint/823a4d308eee300c272a32f4213bb59e to your computer and use it in GitHub Desktop.
Load array buffer via XMLHttpRequest, the old good way
function ab2str(buf: any) {
return Buffer.from(buf).toString("utf8");
}
console.log("hello");
var oReq = new XMLHttpRequest();
console.log(oReq);
oReq.addEventListener("load", reqListener);
oReq.open("GET", "./test.env");
oReq.responseType = "arraybuffer";
oReq.send();
function reqListener(responseText: any) {
console.log("load", responseText);
console.log("array buffer:", ab2str(oReq.response), ".");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment