PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / IncrementalBackup / FileReader.php

FileReader.php in ManageWP Worker 4.9.25, at src/MWP/IncrementalBackup/FileReader.php

80 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_IncrementalBackup_FileReader
12 {
13
14 /**
15 * @var int
16 */
17 private $chunkByteSize = 4096;
18
19 /**
20 * @return int
21 */
22 public function getChunkByteSize()
23 {
24 return $this->chunkByteSize;
25 }
26
27 /**
28 * @param int $chunkByteSize
29 */
30 public function setChunkByteSize($chunkByteSize)
31 {
32 $this->chunkByteSize = $chunkByteSize;
33 }
34
35 /**
36 *
37 *
38 * @param string $realPath
39 * @param int $offset
40 * @param int $limit
41 *
42 * @return mixed
43 */
44 public function readFileContents($realPath, $offset = 0, $limit = 0)
45 {
46 if (!file_exists($realPath)) {
47 return null;
48 }
49
50 $handle = fopen($realPath, "rb");
51 if (!$handle) {
52 return null;
53 }
54
55 $contentLength = 0;
56 $buffer = '';
57
58 if ($limit === 0) {
59 $limit = filesize($realPath) - $offset;
60 }
61
62 if ($offset !== 0) {
63 fseek($handle, $offset);
64 }
65
66 while ($limit > 0) {
67 $chunkSize = $limit > $this->chunkByteSize ? $this->chunkByteSize : $limit;
68 $limit = $limit - $chunkSize;
69 $contentLength = $contentLength + $chunkSize;
70
71 $contents = fread($handle, $chunkSize);
72 $buffer = $buffer.$contents;
73 }
74
75 fclose($handle);
76
77 return array($buffer, $contentLength);
78 }
79 }
80