I need to fetch multiple 32-bit float values from different parts of a large binary file using range requests. This requires specifying multiple ranges in the request.
fetch("http://example.com/largeBinaryFile.bin", {
headers: {
'content-type': 'multipart/byteranges',
'range': 'bytes=2-5,10-13',
},
})
.then(response => {
if (response.ok) {
return response.text();
}
})
.then(response => {
console.log(response);
});
Because I am fetching multiple ranges, I have to use text instead of arrayBuffer. When I print out the response, I see that the binary data is divided into different parts.
--00000000000000000002
Content-Type: application/octet-stream
Content-Range: bytes 2-5/508687874
1ȹC
--00000000000000000002
Content-Type: application/octet-stream
Content-Range: bytes 10-13/508687874
þC
--00000000000000000002--
The challenge now is how to extract the 32-bit float value from these multipart responses. I've attempted using Blob and FileReader to convert the data to arrayBuffer and then wrap it with Float32Array without success. Any advice on how to achieve this would be greatly appreciated. Thank you!