• Stars
    star
    95
  • Rank 354,083 (Top 7 %)
  • Language
    Elixir
  • License
    Mozilla Public Li...
  • Created over 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍱 A fast, correct, pure-Elixir library for reading and writing Bencoded metainfo (.torrent) files.

Bento ci hex.pm

Bento is a new Bencoding library for Elixir focusing on incredibly fast speed without sacrificing simplicity, completeness, or correctness.

It takes inspiration from Poison, a pure-Elixir JSON library, and uses several techniques found there to achieve this speed:

Additionally, 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.

Preliminary benchmarking shows that Bento performs over 2x faster when encoding, and at least as fast when decoding, compared to other existing Elixir libraries.

Documentation

Documentation is available on Hexdocs.

Installation

Bento is available in Hex. The package can be installed by:

  1. Add bento to your list of dependencies in mix.exs:
{:bento, "~> 1.0"}
  1. Then, update your dependencies.
$ mix do deps.get + deps.compile

Usage

Encoding an Elixir data type:

iex> Bento.encode([1, "two", [3]])
{:ok, "li1e3:twoli3eee"}
iex> Bento.encode!(%{"foo" => ["bar", "baz"], "qux" => "norf"})
"d3:fool3:bar3:baze3:qux4:norfe"

Decoding a bencoded string:

iex> Bento.decode("li1e3:twoli3eee")
{:ok, [1, "two", [3]]}
iex> Bento.decode!("d3:fool3:bar3:baze3:qux4:norfe")
%{"foo" => ["bar", "baz"], "qux" => "norf"}

Bento is also metainfo-aware and comes with a *.torrent decoder out of the box:

iex> File.read!("./test/_data/ubuntu-14.04.4-desktop-amd64.iso.torrent") |> Bento.torrent!()
%Bento.Metainfo.Torrent{
  info: %Bento.Metainfo.SingleFile{
    length: 1069547520,
    md5sum: nil,
    "piece length": 524288,
    pieces: <<109, 235, 143, 234, 36, 25, 142, 36, 20, 3, 227, 227, 134, 136,
      205, 130, 176, 104, 192, 33, 45, 230, 152, 2, 239, 131, 240, 217, 180,
      251, 153, 170, 31, 127, 175, 166, 9, 254, 133, 8, 42, 229, 43, 139, 86,
      ...>>,
    private: 0,
    name: "ubuntu-14.04.4-desktop-amd64.iso"
  },
  announce: "http://torrent.ubuntu.com:6969/announce",
  "announce-list": [
    ["http://torrent.ubuntu.com:6969/announce"],
    ["http://ipv6.torrent.ubuntu.com:6969/announce"]
  ],
  "creation date": ~U[2016-02-18 20:12:51Z],
  comment: "Ubuntu CD releases.ubuntu.com",
  "created by": nil,
  encoding: nil
}

In addition to parsing torrents via Bento.torrent!/1, It's also available decoding any bencoded data into any struct you choose, like so:

defmodule Name do
  defstruct [:family, :given]
end

iex> Bento.decode!("d6:family4:Folz5:given6:Rodneye", as: %Name{})
%Name{family: "Folz", given: "Rodney"}

Benchmarking

$ MIX_ENV=bench mix bench

We currently benchmark against: Bento (this project), bencode, Bencodex, and bencoder.

We are aware of, but unable to benchmark against: exbencode (build errors), and elixir_bencode (module name conflicts with Bencode).

PRs that add libraries to the benchmarks are greatly appreciated!

License

See LICENSE.

More Repositories

1

math

The missing Math module for Elixir.
Elixir
102
star
2

cleverbot.py

ARCHIVED - Use https://github.com/edwardslabs/cleverwrap.py instead.
Python
77
star
3

hydra-ts

A fork of ojack/hydra-synth in typescript, focusing on interoperability.
TypeScript
48
star
4

reaction-packs

Browser extensions to swap out Facebook's reactions for something a little more fun.
JavaScript
33
star
5

unsticker.me

unsticker.me
JavaScript
23
star
6

hiasynth

livecode visual synthesis environment
TypeScript
18
star
7

left_pad.ex

Pad a string to the left with any number of characters.
Elixir
12
star
8

hackers-new

Browser extension to show items from HN's /newest page on the front page.
JavaScript
11
star
9

Djitter

A Django Twitter clone built for Hackers @ Berkeley's Django talk
JavaScript
6
star
10

Genesis

Game + Game engine in Python using PyGame
Python
4
star
11

Museau

[Dead because of API changes] Listen to unlimited Pandora radio - no ads, listening limits, or (depending on your browser) plugins.
JavaScript
4
star
12

tractor

🚜 A fast and scalable pure-Elixir BitTorrent tracker. (On Hold)
JavaScript
4
star
13

broccoli-site

Old web site for broccolijs.com
HTML
4
star
14

Calculus-Blasters

Explode asteroids and solve calculus word problems the fun way!
Python
3
star
15

drop

Drop!
Python
2
star
16

folz

2
star
17

skill.ex

A skill-based ranking algorithms library for Elixir. Includes Elo and TrueSkill. (On Hold)
Elixir
2
star
18

Newsbrief

Teaching computers how to summarize the news.
Python
1
star
19

HackHackHack-backend

1
star
20

concerted

HackDFW hackathon project. Trigger events when enough people dance together.
Elixir
1
star
21

map

JavaScript
1
star
22

Fundamentals

A collection of fundamental algorithms and data structures in various languages.
JavaScript
1
star
23

wdd

wdd
Ruby
1
star
24

Eventually

JavaScript
1
star
25

buyc

JavaScript
1
star
26

GoogleForBulat

Could someone Google that for Bulat?
Python
1
star
27

lecturegauge

HackDuke '14 project. Realtime feedback tool for lecture.
JavaScript
1
star