PluginProbe
JetBackup – Backup, Restore & Migrate / 3.1.21.3
JetBackup – Backup, Restore & Migrate v3.1.21.3
3.1.23.6 3.1.23.5 3.1.23.3 3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 All 82 releases
backup / src / JetBackup / Web / File / FileChunkIterator.php
FileChunkIterator.php
55 lines 1010 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 *
4 * JetBackup @ package
5 * Created By Idan Ben-Ezra
6 *
7 * Copyrights @ JetApps
8 * https://www.jetapps.com
9 *
10 **/
11 namespace JetBackup\Web\File;
12
13 use JetBackup\Exception\IOException;
14
15 defined( '__JETBACKUP__' ) or die( 'Restricted access' );
16
17 class FileChunkIterator {
18
19 private FileStream $_file;
20 private int $_chunk_size;
21
22 /**
23 * @param FileStream $file
24 * @param int $chunk_size
25 */
26 public function __construct(FileStream $file, int $chunk_size=FileChunk::CHUNK_SIZE) {
27 $this->_file = $file;
28 $this->_chunk_size = $chunk_size;
29 }
30
31 /**
32 * @return void
33 */
34 public function rewind():void {
35 $this->_file->seek(0);
36 }
37
38 /**
39 * @return bool
40 */
41 public function hasNext():bool {
42 return $this->_file->tell() < $this->_file->getSize();
43 }
44
45 /**
46 * @return FileChunk|null
47 * @throws IOException
48 */
49 public function next():?FileChunk {
50 if(!$this->hasNext()) return null;
51 $chunk = new FileChunk($this->_file, $this->_chunk_size);
52 if(!$chunk->getSize()) return null;
53 return $chunk;
54 }
55 }