Exemplo n.º 1
0
 /**
  * write block to file
  * @param string $positionPrefix
  */
 protected function flush($positionPrefix = '')
 {
     // write to disk only when writeFlag was set to 1
     if ($this->writeFlag) {
         // Disable the file proxies so that encryption is not
         // automatically attempted when the file is written to disk -
         // we are handling that separately here and we don't want to
         // get into an infinite loop
         $position = (int) floor($this->position / $this->unencryptedBlockSize);
         $encrypted = $this->encryptionModule->encrypt($this->cache, $position . $positionPrefix);
         $bytesWritten = parent::stream_write($encrypted);
         $this->writeFlag = false;
         // Check whether the write concerns the last block
         // If so then update the encrypted filesize
         // Note that the unencrypted pointer and filesize are NOT yet updated when flush() is called
         // We recalculate the encrypted filesize as we do not know the context of calling flush()
         $completeBlocksInFile = (int) floor($this->unencryptedSize / $this->unencryptedBlockSize);
         if ($completeBlocksInFile === (int) floor($this->position / $this->unencryptedBlockSize)) {
             $this->size = $this->util->getBlockSize() * $completeBlocksInFile;
             $this->size += $bytesWritten;
             $this->size += $this->headerSize;
         }
     }
     // always empty the cache (otherwise readCache() will not fill it with the new block)
     $this->cache = '';
 }
Exemplo n.º 2
0
 /**
  * write block to file
  */
 protected function flush()
 {
     // write to disk only when writeFlag was set to 1
     if ($this->writeFlag) {
         // Disable the file proxies so that encryption is not
         // automatically attempted when the file is written to disk -
         // we are handling that separately here and we don't want to
         // get into an infinite loop
         $encrypted = $this->encryptionModule->encrypt($this->cache);
         parent::stream_write($encrypted);
         $this->writeFlag = false;
         $this->size = max($this->size, parent::stream_tell());
     }
     // always empty the cache (otherwise readCache() will not fill it with the new block)
     $this->cache = '';
 }