bencodex/bencodex

Bencodex reader/writer for PHP

0.1.0 2021-10-19 12:46 UTC

This package is auto-updated.

Last update: 2022-01-20 02:11:06 UTC


README

Packagist Version MIT License GitHub Actions Status

This package implements Bencodex serialization format which extends Bencoding. Complianet with Bencodex 1.2.

php > echo Bencodex\encode(['foo' => 123, 'bar' => [true, false]]);
du3:barltfeu3:fooi123ee
php > var_dump(Bencodex\decode('du3:barltfeu3:fooi123ee'));
object(stdClass)#4 (2) {
  ["bar"]=>
  array(2) {
    [0]=>
    bool(true)
    [1]=>
    bool(false)
  }
  ["foo"]=>
  int(123)
}

Requirements

PHP Version Requirement

  • PHP 5.4 or later
  • iconv extension (--with-iconv)

Type correspondences

PHP Bencodex
Null Null
Boolean Boolean
Integer Integer
Double Integer (truncated)
Numeric string Integer ≥ PHP_INT_MAX
String which can be decoded as Unicode Text
String otherwise Binary
List-like array List
Map-like array Dictionary
Object Dictionary

† One-way types only available for encoding.

‡ One-way types only available for decoding.

※ Determined by array_is_list() function.

Usage

The above APIs are merely façade, and optional parameters are omitted. See the complete API docs as well.