You are here

abstract class SeekableFileContent in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/content/SeekableFileContent.php \org\bovigo\vfs\content\SeekableFileContent

Default implementation for file contents based on simple strings.

@since 1.3.0

Hierarchy

Expanded class hierarchy of SeekableFileContent

File

vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/content/SeekableFileContent.php, line 16

Namespace

org\bovigo\vfs\content
View source
abstract class SeekableFileContent implements FileContent {

  /**
   * current position within content
   *
   * @type  int
   */
  private $offset = 0;

  /**
   * reads the given amount of bytes from content
   *
   * @param   int     $count
   * @return  string
   */
  public function read($count) {
    $data = $this
      ->doRead($this->offset, $count);
    $this->offset += $count;
    return $data;
  }

  /**
   * actual reading of given byte count starting at given offset
   *
   * @param  int  $offset
   * @param  int  $count
   */
  protected abstract function doRead($offset, $count);

  /**
   * seeks to the given offset
   *
   * @param   int   $offset
   * @param   int   $whence
   * @return  bool
   */
  public function seek($offset, $whence) {
    switch ($whence) {
      case SEEK_CUR:
        $this->offset += $offset;
        return true;
      case SEEK_END:
        $this->offset = $this
          ->size() + $offset;
        return true;
      case SEEK_SET:
        $this->offset = $offset;
        return true;
      default:
        return false;
    }
    return false;
  }

  /**
   * checks whether pointer is at end of file
   *
   * @return  bool
   */
  public function eof() {
    return $this
      ->size() <= $this->offset;
  }

  /**
   * writes an amount of data
   *
   * @param   string  $data
   * @return  amount of written bytes
   */
  public function write($data) {
    $dataLength = strlen($data);
    $this
      ->doWrite($data, $this->offset, $dataLength);
    $this->offset += $dataLength;
    return $dataLength;
  }

  /**
   * actual writing of data with specified length at given offset
   *
   * @param   string  $data
   * @param   int     $offset
   * @param   int     $length
   */
  protected abstract function doWrite($data, $offset, $length);

  /**
   * for backwards compatibility with vfsStreamFile::bytesRead()
   *
   * @return  int
   * @deprecated
   */
  public function bytesRead() {
    return $this->offset;
  }

  /**
   * for backwards compatibility with vfsStreamFile::readUntilEnd()
   *
   * @return  string
   * @deprecated
   */
  public function readUntilEnd() {
    return substr($this
      ->content(), $this->offset);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileContent::content public function returns actual content 2
FileContent::size public function returns size of content 2
FileContent::truncate public function Truncates a file to a given length 2
SeekableFileContent::$offset private property current position within content
SeekableFileContent::bytesRead public function for backwards compatibility with vfsStreamFile::bytesRead()
SeekableFileContent::doRead abstract protected function actual reading of given byte count starting at given offset 2
SeekableFileContent::doWrite abstract protected function actual writing of data with specified length at given offset 2
SeekableFileContent::eof public function checks whether pointer is at end of file Overrides FileContent::eof
SeekableFileContent::read public function reads the given amount of bytes from content Overrides FileContent::read
SeekableFileContent::readUntilEnd public function for backwards compatibility with vfsStreamFile::readUntilEnd()
SeekableFileContent::seek public function seeks to the given offset Overrides FileContent::seek
SeekableFileContent::write public function writes an amount of data Overrides FileContent::write