Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dasch/ruby-bencode
Ruby bindings for the bencode data serialization format
https://github.com/dasch/ruby-bencode
Last synced: 9 days ago
JSON representation
Ruby bindings for the bencode data serialization format
- Host: GitHub
- URL: https://github.com/dasch/ruby-bencode
- Owner: dasch
- License: mit
- Created: 2008-07-17T22:56:50.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2024-08-12T08:40:20.000Z (3 months ago)
- Last Synced: 2024-09-13T14:41:48.885Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 534 KB
- Stars: 78
- Watchers: 6
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Ruby bencode binding
====================This is a simple library for reading and writing bencoded data.
What is bencode?
----------------Bencode is a simple data serialization format used by the popular
[BitTorrent](http://bittorrent.org/) P2P file sharing system.It contains only four data types, namely:
- byte strings
- integers
- lists
- dictionariesExamples
--------Encoding objects is as simple as calling `#bencode` on them:
```ruby
"foo bar".bencode # => "7:foo bar"
42.bencode # => "i42e"
[1, 2, 3].bencode # => "li1ei2ei3ee"
{"foo" => 1, "bar" => -10}.bencode # => "d3:bari-10e3:fooi1ee"
```Decoding a complete data stream is as easy as calling `BEncode.load(data)`.
Decoding a data stream in chunks works as follows:
```ruby
irb(main):007:0> stream = BEncode::Parser.new(StringIO.new "d3:foo3:bared3:baz3:quxe")
=> #>
irb(main):008:0> stream.parse!
=> {"foo"=>"bar"}
irb(main):009:0> stream.parse!
=> {"baz"=>"qux"}
```License
-------Released under the MIT license.
Contributors
------------- Daniel Schierbeck ([dasch](https://github.com/dasch))
- Mike Hodgson ([mikehodgson](https://github.com/mikehodgson))
- Andrew Danforth
- Eric Himmelreich
- Allen Madsen ([blatyo](https://github.com/blatyo))
- Ian Levesque ([ianlevesque](https://github.com/ianlevesque))
- Dirk Geurs ([Dirklectisch](https://github.com/Dirklectisch))
- Xinyue Lu ([msg7086](https://github.com/msg7086))