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)
55 $newOffset = $this->offset;
58 $newOffset += $offset;
62 $newOffset = $this->size() + $offset;
76 $this->offset = $newOffset;
81 * checks whether pointer is at end of file
87 return $this->size() <= $this->offset;
91 * writes an amount of data
94 * @return amount of written bytes
96 public function write($data)
98 $dataLength = strlen($data);
99 $this->doWrite($data, $this->offset, $dataLength);
100 $this->offset += $dataLength;
105 * actual writing of data with specified length at given offset
107 * @param string $data
111 protected abstract function doWrite($data, $offset, $length);
114 * for backwards compatibility with vfsStreamFile::bytesRead()
119 public function bytesRead()
121 return $this->offset;
125 * for backwards compatibility with vfsStreamFile::readUntilEnd()
130 public function readUntilEnd()
132 return substr($this->content(), $this->offset);