Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bencode

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bencode

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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 P2P file sharing system.

It contains only four data types, namely:

  • byte strings
  • integers
  • lists
  • dictionaries

Examples

Encoding objects is as simple as calling #bencode on them:

"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:

irb(main):007:0> stream = BEncode::Parser.new(StringIO.new "d3:foo3:bared3:baz3:quxe")
=> #<BEncode::Parser:0x007fbe6b008c88 @stream=#<StringIO:0x007fbe6b008cd8>>
irb(main):008:0> stream.parse!
=> {"foo"=>"bar"}
irb(main):009:0> stream.parse!
=> {"baz"=>"qux"}

License

Released under the MIT license.

Contributors

FAQs

Package last updated on 12 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc