{"id":19601425,"url":"https://github.com/acgrid/php-ext-bencode","last_synced_at":"2025-04-27T17:31:59.573Z","repository":{"id":41156336,"uuid":"50231205","full_name":"acgrid/php-ext-bencode","owner":"acgrid","description":"A PHP7 renewal for the legacy but simple bencode extension cg_bcode","archived":false,"fork":false,"pushed_at":"2022-02-18T17:15:58.000Z","size":22,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-02-27T11:02:49.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/acgrid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-23T08:57:16.000Z","updated_at":"2022-09-10T05:45:00.000Z","dependencies_parsed_at":"2022-09-09T21:32:43.784Z","dependency_job_id":null,"html_url":"https://github.com/acgrid/php-ext-bencode","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acgrid%2Fphp-ext-bencode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acgrid%2Fphp-ext-bencode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acgrid%2Fphp-ext-bencode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acgrid%2Fphp-ext-bencode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acgrid","download_url":"https://codeload.github.com/acgrid/php-ext-bencode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224076151,"owners_count":17251699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T09:18:23.030Z","updated_at":"2024-11-11T09:18:24.087Z","avatar_url":"https://github.com/acgrid.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Extension for Bencode Encoding and Decoding\nThis PHP extension is a pure C implementation for mapping PHP variable to Bencode string vice versa.\n\nIt is inspired from [this](https://github.com/acgrid/php-bencode-extension) by unknown original author.\n\nThe original extension name and function names are kept at this moment.\n\n## Installation\n\n### Requirement\n\n*SUPPORT PHP7,8 ONLY*, no external libraries are needed.\n\n### *NIX\n```bash\nphpize\n./configure\nmake\nmake test\nsudo make install\n```\n\n### Windows\nFollow [this instruction](https://wiki.php.net/internals/windows/stepbystepbuild) for preparing a complete building environment for PHP. It is worthy to spend some time on.\n\nI have done this with VS2015 community edition.\n\nThen checkout the repo to your `php-sdk\\phpdev\\vc14\\x64\\pecl\\` (you should mkdir `pecl` manually, in the same level of the php sources like \n`php-7.0.2-src`.\n\nRun the VS2015 x64 native prompt (Do not follow the instruction above except that you need just a x86 build) and do the same things\ntill run the batch file `bin\\phpsdk_setvars.bat`. \n\nChange work directory to `php-sdk\\phpdev\\vc14\\x64\\pecl\\php-7.x.y-src` during developing and building from now on.\n\n- Run `buildconf` for a `configure.bat` with all pecl stuff included\n- Run `configure --disable-all --disable-zts --enable-cli --enable-cg_bcode=shared` for a minimal PHP build to save time. Remove `--disable-zts` for ZTS build.\n- Run `nmake` to start building\n- Run `nmake test TESTS=../pecl/php-ext-bencode/tests/*.phpt` for testing the extension only (optional)\n- Run `nmake build-dist` for packing everything useful up officially or just copy the built DLL file under `x64\\Release` (it differs according to build arch, debug and ZTS)\n\n## Usage\n\n### `bencode()`\n\nVery simple with recognition of PHP variable types. No additional type specifitions are need to create a bencode element.\n\nDictionary keys are sorted automatically without affecting input array.\n\nInteger-like strings are bencoded to integer even it is bigger than `PHP_INT_MAX`.\n\n```php\nbencode([]); // le\nbencode(new StdClass); // de\nbencode('10000000000000'); // i10000000000000e\nbencode(['b' =\u003e 1, 'a' =\u003e 2]); // d1:ai2e1:bi1ee\n```\n\n### `bdecode()`\n\nThe type information is mapped to PHP type as well.\n\nNote that `de` and `le` are both converted to `[]` at this moment.\n\n```php\nbencode('i1e'); // int(1)\nbdecode('li2e3:123i0ee'); // [2, '123', 0]\nbdecode('d1:a3:1231:bi3e1:cl1:x1:y1:zee'); // ['a' =\u003e '123', 'b' =\u003e 3, 'c' =\u003e ['x', 'y', 'z']]\n```\n\n## Bencode syntax standard\n\nThe syntax for testing and QA is described [here](https://wiki.theory.org/BitTorrentSpecification#Bencoding).\n\nIt *does not* support parsing becoded dict with non-string key like `di0e3:fooe`.\n\n## Discuss\n\n- Rewrite the decoder with scanner `re2c` and parser `bison`, which PHP officially like ext/json\n- Globally last error reporting like ext/json and return null silently on failure\n\nThis extension is aimed to boost performance for client codes that make use of everything of the bencoded data, or exporting a structure to bencoded string. It do not provide extra functionality.\n\nIt consumes memory to some extent because maps all data to userspace, which is not suit for some tasks like editing `resume.dat`, when only part of data is needed to be read and written. [This extension](https://github.com/Frederick888/php-bencode) may be more suitable for such applications.\n\n## Todos\n\n- Encode string qualified to be an integer as `int`\n- INI setting to raise error in exception or warning\n- INI setting/function parameter to specify decode `dict` as object\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facgrid%2Fphp-ext-bencode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facgrid%2Fphp-ext-bencode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facgrid%2Fphp-ext-bencode/lists"}