public function stream_seek($offset, $whence = SEEK_SET) { $return = false; switch ($whence) { case SEEK_SET: $newPosition = $offset; break; case SEEK_CUR: $newPosition = $this->position + $offset; break; case SEEK_END: $newPosition = $this->unencryptedSize + $offset; break; default: return $return; } if ($newPosition > $this->unencryptedSize || $newPosition < 0) { return $return; } $newFilePosition = floor($newPosition / $this->unencryptedBlockSize) * $this->util->getBlockSize() + $this->headerSize; $oldFilePosition = parent::stream_tell(); if ($this->parentStreamSeek($newFilePosition)) { $this->parentStreamSeek($oldFilePosition); $this->flush(); $this->parentStreamSeek($newFilePosition); $this->position = $newPosition; $return = true; } return $return; }
/** * 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 = ''; }