3 * This file is part of vfsStream.
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
8 * @package org\bovigo\vfs
10 namespace org\bovigo\vfs\content;
12 * Default implementation for file contents based on simple strings.
16 abstract class SeekableFileContent implements FileContent
19 * current position within content
26 * reads the given amount of bytes from content
31 public function read($count)
33 $data = $this->doRead($this->offset, $count);
34 $this->offset += $count;
39 * actual reading of given byte count starting at given offset
44 protected abstract function doRead($offset, $count);
47 * seeks to the given offset
53 public function seek($offset, $whence)
57 $this->offset += $offset;
61 $this->offset = $this->size() + $offset;
65 $this->offset = $offset;
76 * checks whether pointer is at end of file
82 return $this->size() <= $this->offset;
86 * writes an amount of data
89 * @return amount of written bytes
91 public function write($data)
93 $dataLength = strlen($data);
94 $this->doWrite($data, $this->offset, $dataLength);
95 $this->offset += $dataLength;
100 * actual writing of data with specified length at given offset
102 * @param string $data
106 protected abstract function doWrite($data, $offset, $length);
109 * for backwards compatibility with vfsStreamFile::bytesRead()
114 public function bytesRead()
116 return $this->offset;
120 * for backwards compatibility with vfsStreamFile::readUntilEnd()
125 public function readUntilEnd()
127 return substr($this->content(), $this->offset);