http icon indicating copy to clipboard operation
http copied to clipboard

[Question] How to fetch a specific byte range ?

Open jamesst20 opened this issue 5 years ago • 0 comments

Hi,

I'm currently migrating a project to rails, however, I can't seem to figure out how to fetch a specific byte range from a big file.

Let's say I have a very big file located to https://domain.com/myfile and that I'm only interesting in reading 20 bytes from the offset 0x50. How would I do that ?

This is how it would be done in PHP:

private function fetchData($url, $rangeStart, $rangeEnd)
{
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RANGE, $rangeStart . '-' . $rangeEnd);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        return curl_exec($ch);
}

jamesst20 avatar Dec 05 '20 20:12 jamesst20