Bencodex

Reader

An interface to read a byte string (which can be quite long) in separated multiple chunks.

Table of Contents

read()  : string
Reads a chunk of bytes.
seek()  : void
Fast-forwards or rewinds the offset.
tell()  : int
Gets the current offset in the buffer.

Methods

read()

Reads a chunk of bytes.

public read(int $size) : string
Parameters
$size : int

The size of bytes to request. Zero or negative integers reads nothing and an empty string is returned.

Tags
throws
TypeError

Thrown when the requested size is not an integer.

Return values
string

The read bytes. It may be shorter than the requested size if there is not enough bytes to read.

seek()

Fast-forwards or rewinds the offset.

public seek(int $offset) : void
Parameters
$offset : int

The number of bytes to move the offset pointer. Negative integers rewind and positive integers fast-forward. (Zero is no-op.) If the destination is less than zero or greater than the entire length, the offset is set to zero or the end of the entire buffer.

Tags
throws
TypeError

Thrown when the size is not an integer.

Return values
void

tell()

Gets the current offset in the buffer.

public tell() : int
Return values
int

The current offset.

Search results