Javascript Fetch API with multiple range request get binary Float32Array data

I am using a range query to read a large 32 bit float from a large binary, unfortunately the plugin I need from this file is in a different part of the file, so I need to make a range query with multiple ranges

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);
    });

      

Due to multiple ranges, I have to use text instead of arrayBuffer and when I print out the response, I get

--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--

      

As you can see the binary data is in different parts, I tried using Blob and FileReader to rotate the data into an arrayBuffer and wrap it with Float32Array, but with no success. May I ask how do I get the 32 bit float value from multiparts? Thank you so much for your help.

+3


source to share





All Articles