Bencodex

Bencodex

Interfaces, Classes, Traits and Enums

Reader
An interface to read a byte string (which can be quite long) in separated multiple chunks.
Writer
An interface to write a byte string (which can be quite long) in separated multiple chunks.
Decoder
DecodingError
The exception thrown when a Bencodex data is invalid so that it cannot be decoded into a PHP value.
Encoder
Encodes PHP values into corresponding Bencodex data.
TextEncodingError
The exception thrown when the configured text encoding is invalid or unsupported by iconv.
TextEncodingError
The exception thrown when the configured text encoding is invalid or unsupported by iconv.
MemoryReader
A reader that holds an in-memory buffer.
StreamReader
A stream reader, which usually refers to a file.
MemoryWriter
A writer that copies the given byte string into an in-memory buffer and allows to get the written byte string from the buffer.
StreamWriter
A writer that put the given byte string into a stream, which usually refers to a file.

Table of Contents

validateTextEncoding()  : bool
Validates if the given text encoding is valid and supported by iconv.
array_is_list()  : mixed
encode()  : string
Encodes the given value into Bencodex data.
decode()  : mixed
Decodes the given Bencodex data into a PHP value.

Functions

validateTextEncoding()

Validates if the given text encoding is valid and supported by iconv.

validateTextEncoding(string $textEncoding) : bool
Parameters
$textEncoding : string

A text encoding name to check.

Return values
bool

True if the given text encoding is valid.

array_is_list()

array_is_list(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>
Return values
mixed

encode()

Encodes the given value into Bencodex data.

encode(mixed $value[, string|null $textEncoding = 'utf-8' ][, string|null $keyEncoding = 'utf-8' ][, bool $byteOrderMark = false ]) : string

This is a facade of Encoder class.

Parameters
$value : mixed

The value to be encoded in Bencodex.

$textEncoding : string|null = 'utf-8'

Determines what text encoding the PHP strings you want to encode are in. If the PHP strings are binary data and not Unicode text, then this should be set to null. UTF-8 by default.

$keyEncoding : string|null = 'utf-8'

Determines what text encoding the string keys of the PHP arrays you want to encode are in. If the PHP string keys are binary keys and not Unicode keys, they should be set to null. UTF-8 by default.

$byteOrderMark : bool = false

Whether to respect BOMs (byte order marks). If turned on, strings without BOMs are considered as binary and BOMs are stripped after encoding. If turned off (default), there's no special treatment for BOM.

Tags
throws
TextEncodingError

Thrown when the given text encoding is invalid or unsupported by iconv.

Return values
string

The encoded Bencodex data.

decode()

Decodes the given Bencodex data into a PHP value.

decode(string $bencodex[, string $textEncoding = 'utf-8' ][, bool $byteOrderMark = false ]) : mixed

This is a facade of Decoder class.

Parameters
$bencodex : string

The Bencodex data to decode.

$textEncoding : string = 'utf-8'

Determines what text encoding Bencodex text values are decoded to PHP strings in.

$byteOrderMark : bool = false

Whether to prepend BOMs (byte order marks). If turned on, Bencodex text values are decoded to PHP strings with BOMs whether the original text has BOM or not. If turned off (default), BOM is added to the decoded PHP string if and only if the original Bencodex text has BOM.

Return values
mixed

A decoded value.

Search results