.htaccess
1 year ago
ChunkedDownload.php
1 year ago
ChunkedUpload.php
1 year ago
DirIterator.php
1 year ago
Local.php
1 year ago
index.html
1 year ago
web.config
1 year ago
ChunkedDownload.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Destination\Vendors\Local; |
| 4 | |
| 5 | use JetBackup\Destination\Integration\DestinationChunkedDownload; |
| 6 | |
| 7 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 8 | |
| 9 | class ChunkedDownload implements DestinationChunkedDownload { |
| 10 | |
| 11 | private $_source; |
| 12 | private $_destination; |
| 13 | |
| 14 | public function __construct($source, $destination) { |
| 15 | $this->_source = fopen($source, 'r'); |
| 16 | $this->_destination = fopen($destination, 'a'); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @return string |
| 21 | */ |
| 22 | public function download(int $start, int $end):int { |
| 23 | fseek($this->_source, $start); |
| 24 | |
| 25 | $readed = 0; |
| 26 | $left = $end - $start; |
| 27 | |
| 28 | while($left && !feof($this->_source)) { |
| 29 | $read = fread($this->_source, min($left, 1024 * 1024)); |
| 30 | fwrite($this->_destination, $read); |
| 31 | $left -= strlen($read); |
| 32 | $readed += strlen($read); |
| 33 | } |
| 34 | |
| 35 | return $readed; |
| 36 | } |
| 37 | } |