Created
July 25, 2022 10:27
-
-
Save semlinker/5ea7914995f805d659a99f034c9b3745 to your computer and use it in GitHub Desktop.
Get Binary Content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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