{"id":13507471,"url":"https://github.com/folz/bento","last_synced_at":"2025-07-02T01:32:21.491Z","repository":{"id":45012245,"uuid":"54678680","full_name":"folz/bento","owner":"folz","description":":bento: A fast, correct, pure-Elixir library for reading and writing Bencoded metainfo (.torrent) files.","archived":false,"fork":false,"pushed_at":"2024-01-22T20:28:22.000Z","size":339,"stargazers_count":98,"open_issues_count":5,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-19T19:11:23.598Z","etag":null,"topics":["bencode","bencoding","bento","bittorrent","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/folz.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-24T22:36:36.000Z","updated_at":"2025-05-19T17:15:49.000Z","dependencies_parsed_at":"2024-05-01T16:19:33.496Z","dependency_job_id":"c8cb3949-7fe3-417c-a08b-0da407747763","html_url":"https://github.com/folz/bento","commit_stats":{"total_commits":88,"total_committers":7,"mean_commits":"12.571428571428571","dds":0.25,"last_synced_commit":"ba47414ac0e3dd8c80a1bd5da73e3daefd9f574c"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/folz/bento","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fbento","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fbento/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fbento/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fbento/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/folz","download_url":"https://codeload.github.com/folz/bento/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fbento/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263059917,"owners_count":23407426,"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":["bencode","bencoding","bento","bittorrent","elixir"],"created_at":"2024-08-01T02:00:34.483Z","updated_at":"2025-07-02T01:32:21.462Z","avatar_url":"https://github.com/folz.png","language":"Elixir","readme":"# Bento [![ci](https://img.shields.io/github/actions/workflow/status/folz/bento/build-test.yml?label=CI\u0026logo=github\u0026style=flat-square)](https://github.com/folz/bento/actions/workflows/build-test.yml？style=flat-square) [![hex.pm](https://img.shields.io/hexpm/v/bento.svg?label=Hex\u0026style=flat-square)](https://hex.pm/packages/bento)\n\nBento is a new [Bencoding](https://en.wikipedia.org/wiki/Bencode) library for Elixir focusing on incredibly fast **speed** without sacrificing **simplicity**, **completeness**, or **correctness**.\n\nIt takes inspiration from [Poison](https://github.com/devinus/poison), a pure-Elixir JSON library, and uses several techniques found there to achieve this speed:\n\n- Extensive [sub-binary matching](http://erlang.org/euc/07/papers/1700Gustafsson.pdf).\n- A hand-rolled **parser** using several techniques [known to benefit HiPE](http://erlang.org/workshop/2003/paper/p36-sagonas.pdf) for native compilation.\n- [IO list](http://jlouisramblings.blogspot.com/2013/07/problematic-traits-in-erlang.html) encoding.\n- **Single-pass** decoding.\n\nAdditionally, and unlike some other Elixir bencoding libraries, Bento will also reject all malformed input. This guarantees you're working with a well-formed bencoded file.\n\nPreliminary [benchmarking](#benchmarking) shows that Bento performs over 2x faster when encoding, and at least as fast when decoding, compared to other existing Elixir libraries.\n\n## Documentation\n\nDocumentation is [available on Hexdocs](https://hexdocs.pm/bento).\n\n## Installation\n\nBento is [available in Hex](https://hex.pm/packages/bento). The package can be installed by:\n\n1. Add bento to your list of dependencies in `mix.exs`:\n\n```elixir\n{:bento, \"~\u003e 1.0\"}\n```\n\n2. Then, update your dependencies.\n\n```shell\n$ mix do deps.get + deps.compile\n```\n\n## Usage\n\nEncoding an Elixir data type:\n\n```elixir\niex\u003e Bento.encode([1, \"two\", [3]])\n{:ok, \"li1e3:twoli3eee\"}\niex\u003e Bento.encode!(%{\"foo\" =\u003e [\"bar\", \"baz\"], \"qux\" =\u003e \"norf\"})\n\"d3:fool3:bar3:baze3:qux4:norfe\"\n```\n\nDecoding a bencoded string:\n\n```elixir\niex\u003e Bento.decode(\"li1e3:twoli3eee\")\n{:ok, [1, \"two\", [3]]}\niex\u003e Bento.decode!(\"d3:fool3:bar3:baze3:qux4:norfe\")\n%{\"foo\" =\u003e [\"bar\", \"baz\"], \"qux\" =\u003e \"norf\"}\n```\n\nBento is also metainfo-aware and comes with a `*.torrent` decoder out of the box:\n\n```elixir\niex\u003e File.read!(\"./test/_data/ubuntu-14.04.4-desktop-amd64.iso.torrent\") |\u003e Bento.torrent!()\n%Bento.Metainfo.Torrent{\n  info: %Bento.Metainfo.SingleFile{\n    length: 1069547520,\n    md5sum: nil,\n    \"piece length\": 524288,\n    pieces: \u003c\u003c109, 235, 143, 234, 36, 25, 142, 36, 20, 3, 227, 227, 134, 136,\n      205, 130, 176, 104, 192, 33, 45, 230, 152, 2, 239, 131, 240, 217, 180,\n      251, 153, 170, 31, 127, 175, 166, 9, 254, 133, 8, 42, 229, 43, 139, 86,\n      ...\u003e\u003e,\n    private: 0,\n    name: \"ubuntu-14.04.4-desktop-amd64.iso\"\n  },\n  announce: \"http://torrent.ubuntu.com:6969/announce\",\n  \"announce-list\": [\n    [\"http://torrent.ubuntu.com:6969/announce\"],\n    [\"http://ipv6.torrent.ubuntu.com:6969/announce\"]\n  ],\n  \"creation date\": ~U[2016-02-18 20:12:51Z],\n  comment: \"Ubuntu CD releases.ubuntu.com\",\n  \"created by\": nil,\n  encoding: nil\n}\n```\n\nIn addition to parsing torrents via `Bento.torrent!/1`, It's also available decoding any bencoded data into any struct you choose, like so:\n\n```elixir\ndefmodule Name do\n  defstruct [:family, :given]\nend\n\niex\u003e Bento.decode!(\"d6:family4:Folz5:given6:Rodneye\", as: %Name{})\n%Name{family: \"Folz\", given: \"Rodney\"}\n```\n\n## Benchmarking\n\n```shell\n$ MIX_ENV=bench mix bench\n```\n\nWe currently benchmark against: [Bento](https://github.com/folz/bento) (this project), [bencode](https://github.com/gausby/bencode), [Bencodex](https://github.com/patrickgombert/Bencodex), and [bencoder](https://github.com/alehander42/bencoder).\n\nWe are aware of, but unable to benchmark against: [exbencode](https://github.com/antifuchs/exbencode) (build errors), and [elixir_bencode](https://github.com/AntonFagerberg/elixir_bencode) (module name conflicts with Bencode).\n\nPRs that add libraries to the benchmarks are greatly appreciated!\n\n## License\n\nSee [LICENSE](./LICENSE).\n","funding_links":[],"categories":["Bittorrent"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolz%2Fbento","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffolz%2Fbento","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolz%2Fbento/lists"}