Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to fetch a specific byte range ? #629

Open
jamesst20 opened this issue Dec 5, 2020 · 0 comments
Open

[Question] How to fetch a specific byte range ? #629

jamesst20 opened this issue Dec 5, 2020 · 0 comments

Comments

@jamesst20
Copy link

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant