Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/MWP/Incremen...
File: FileReader.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_IncrementalBackup_FileReader
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var int
[14] Fix | Delete
*/
[15] Fix | Delete
private $chunkByteSize = 4096;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @return int
[19] Fix | Delete
*/
[20] Fix | Delete
public function getChunkByteSize()
[21] Fix | Delete
{
[22] Fix | Delete
return $this->chunkByteSize;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @param int $chunkByteSize
[27] Fix | Delete
*/
[28] Fix | Delete
public function setChunkByteSize($chunkByteSize)
[29] Fix | Delete
{
[30] Fix | Delete
$this->chunkByteSize = $chunkByteSize;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
*
[35] Fix | Delete
*
[36] Fix | Delete
* @param string $realPath
[37] Fix | Delete
* @param int $offset
[38] Fix | Delete
* @param int $limit
[39] Fix | Delete
*
[40] Fix | Delete
* @return mixed
[41] Fix | Delete
*/
[42] Fix | Delete
public function readFileContents($realPath, $offset = 0, $limit = 0)
[43] Fix | Delete
{
[44] Fix | Delete
if (!file_exists($realPath)) {
[45] Fix | Delete
return null;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$handle = fopen($realPath, "rb");
[49] Fix | Delete
if (!$handle) {
[50] Fix | Delete
return null;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
$contentLength = 0;
[54] Fix | Delete
$buffer = '';
[55] Fix | Delete
[56] Fix | Delete
if ($limit === 0) {
[57] Fix | Delete
$limit = filesize($realPath) - $offset;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
if ($offset !== 0) {
[61] Fix | Delete
fseek($handle, $offset);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
while ($limit > 0) {
[65] Fix | Delete
$chunkSize = $limit > $this->chunkByteSize ? $this->chunkByteSize : $limit;
[66] Fix | Delete
$limit = $limit - $chunkSize;
[67] Fix | Delete
$contentLength = $contentLength + $chunkSize;
[68] Fix | Delete
[69] Fix | Delete
$contents = fread($handle, $chunkSize);
[70] Fix | Delete
$buffer = $buffer.$contents;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
fclose($handle);
[74] Fix | Delete
[75] Fix | Delete
return array($buffer, $contentLength);
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function