Update Encryption.php

Signed-off-by: martink-p <47943787+martink-p@users.noreply.github.com>
This commit is contained in:
martink-p 2019-06-13 13:21:16 +02:00
parent 452d7696ff
commit 4b9675df6c

View file

@ -315,6 +315,23 @@ class Encryption extends Wrapper {
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) {
$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
if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) {
// 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);
$numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize);
if($numberOfChunks === $position) {
@ -495,7 +512,7 @@ class Encryption extends Wrapper {
* read first block to skip the header
*/
protected function skipHeader() {
parent::stream_read($this->headerSize);
$this->stream_read_block($this->headerSize);
}
/**