bencode.scm: BitTorrent Bencode Decoding in Scheme

bencode.scm parses the bencoding format of the BitTorrent network protocol into basic Scheme data types (and currently PLT-specific byte strings). This is useful for inspecting .torrent files, and might later be used in the implementation of a BitTorrent client or protocol analyzer.

The format interpretation is based on the undated BitTorrent protocol documentation Web page as viewed on 2005-04-17. The mapping from those bencoding types to Scheme types is:

String
PLT byte string.
Integer
Scheme integer.
List
Scheme list.
Dictionary
Scheme list with the symbol dictionary as its head, and an association list as its tail.

For example, a parse of a certain real-world .torrent file:

(unbencode (open-input-file "debian.torrent")))
⇒
((dictionary
  (#"announce"      . #"http://cdimage.debian.org:6969/announce")
  (#"comment"       . #"Debian CD from cdimage.debian.org")
  (#"creation date" . 1105009474)
  (#"info"
   dictionary
   (#"length"       . 600158208)
   (#"name"         . #"debian-30r4-i386-binary-1.iso")
   (#"piece length" . 524288)
   (#"pieces"       . [...large byte string...]))))

bencode.scm is currently specific to PLT 299/3xx, due to the need for byte I/O and some representation for byte sequences. Otherwise, the code has been written to require only R5RS, SRFI-6, and SRFI-23.

See documentation for more info...

To be added to the moderated scheme-announce email list, ask neil@neilvandyke.org .

The current version of bencode.scm is 0.1 (2005-04-17).

You can download file bencode.scm, Scheme source code.

You can download file bencode.html, documentation in HTML format.

You can download file bencode.pdf, documentation in PDF format.

You can download file bencode.plt, a packaging for PLT Scheme.

Site © 1994-2008 Neil Van Dyke   neil@neilvandyke.org    XHTML 1.0 Strict  CSS2    Legal