MCPcopy Create free account
hub / github.com/apache/avro / seek

Method seek

lang/php/lib/IO/AvroStringIO.php:153–183  ·  view source on GitHub ↗

* @returns boolean true if successful * @throws AvroIOException if the seek failed. */

($offset, $whence = self::SEEK_SET)

Source from the content-addressed store, hash-verified

151 * @throws AvroIOException if the seek failed.
152 */
153 public function seek($offset, $whence = self::SEEK_SET): bool
154 {
155 if (!is_int($offset)) {
156 throw new AvroIOException('Seek offset must be an integer.');
157 }
158 // Prevent seeking before BOF
159 switch ($whence) {
160 case self::SEEK_SET:
161 if (0 > $offset) {
162 throw new AvroIOException('Cannot seek before beginning of file.');
163 }
164 $this->current_index = $offset;
165 break;
166 case self::SEEK_CUR:
167 if (0 > $this->current_index + $whence) {
168 throw new AvroIOException('Cannot seek before beginning of file.');
169 }
170 $this->current_index += $offset;
171 break;
172 case self::SEEK_END:
173 if (0 > $this->length() + $offset) {
174 throw new AvroIOException('Cannot seek before beginning of file.');
175 }
176 $this->current_index = $this->length() + $offset;
177 break;
178 default:
179 throw new AvroIOException(sprintf('Invalid seek whence %d', $whence));
180 }
181
182 return true;
183 }
184
185 /**
186 * @returns int

Callers

nothing calls this directly

Calls 1

lengthMethod · 0.95

Tested by

no test coverage detected