Update Encryption.php
Signed-off-by: martink-p <47943787+martink-p@users.noreply.github.com>
This commit is contained in:
parent
452d7696ff
commit
4b9675df6c
|
@ -315,6 +315,23 @@ class Encryption extends Wrapper {
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stream_read wrapper to read complete requested block
|
||||||
|
*/
|
||||||
|
private function stream_read_block($blockSize) {
|
||||||
|
$remaining = $blockSize;
|
||||||
|
$data = "";
|
||||||
|
|
||||||
|
do {
|
||||||
|
$chunk = parent::stream_read($remaining);
|
||||||
|
$chunk_len = strlen($chunk);
|
||||||
|
$data .= $chunk;
|
||||||
|
$remaining -= $chunk_len;
|
||||||
|
} while ( ($remaining > 0) && ($chunk_len > 0) );
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
public function stream_write($data) {
|
public function stream_write($data) {
|
||||||
$length = 0;
|
$length = 0;
|
||||||
|
@ -470,7 +487,7 @@ class Encryption extends Wrapper {
|
||||||
// don't try to fill the cache when trying to write at the end of the unencrypted file when it coincides with new block
|
// don't try to fill the cache when trying to write at the end of the unencrypted file when it coincides with new block
|
||||||
if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) {
|
if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) {
|
||||||
// Get the data from the file handle
|
// Get the data from the file handle
|
||||||
$data = parent::stream_read($this->util->getBlockSize());
|
$data = $this->stream_read_block($this->util->getBlockSize());
|
||||||
$position = (int)floor($this->position/$this->unencryptedBlockSize);
|
$position = (int)floor($this->position/$this->unencryptedBlockSize);
|
||||||
$numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize);
|
$numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize);
|
||||||
if($numberOfChunks === $position) {
|
if($numberOfChunks === $position) {
|
||||||
|
@ -495,7 +512,7 @@ class Encryption extends Wrapper {
|
||||||
* read first block to skip the header
|
* read first block to skip the header
|
||||||
*/
|
*/
|
||||||
protected function skipHeader() {
|
protected function skipHeader() {
|
||||||
parent::stream_read($this->headerSize);
|
$this->stream_read_block($this->headerSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue