Skip to content

Instantly share code, notes, and snippets.

@semlinker
Created July 25, 2022 10:27
Show Gist options
  • Select an option

  • Save semlinker/5ea7914995f805d659a99f034c9b3745 to your computer and use it in GitHub Desktop.

Select an option

Save semlinker/5ea7914995f805d659a99f034c9b3745 to your computer and use it in GitHub Desktop.
Get Binary Content
function getBinaryContent(url, start, end, i) {
return new Promise((resolve, reject) => {
try {
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("range", `bytes=${start}-${end}`); // Set range request information
xhr.responseType = "arraybuffer"; // Set the returned type to arraybuffer
xhr.onload = function () {
resolve({
index: i, // file block index
buffer: xhr.response,
});
};
xhr.send();
} catch (err) {
reject(new Error(err));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment