Skip to content

Commit

Permalink
Add partial-download support for curl requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsweeney committed Jun 14, 2022
1 parent bb1ef65 commit 5abe328
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Helpers.php
Expand Up @@ -908,6 +908,14 @@ public static function getFileContent($uri, $context = null, $offset = 0, $maxle
curl_setopt($curl, CURLOPT_RESUME_FROM, $offset);
}

if ($maxlen > 0) {
curl_setopt($curl, CURLOPT_BUFFERSIZE, 128);
curl_setopt($curl, CURLOPT_NOPROGRESS, false);
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, function ($res, $download_size_total, $download_size, $upload_size_total, $upload_size) use ($maxlen) {
return ($download_size > $maxlen) ? 1 : 0;
});
}

$context_options = [];
if (!is_null($context)) {
$context_options = stream_context_get_options($context);
Expand Down

0 comments on commit 5abe328

Please sign in to comment.