bencode-codec
If you find that this library lacks some feature you need, or you have a suggestion for improving it, please don’t hesitate to get in touch with me!
1 Introduction
This library implements Bencode, "the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data." Quote from Wikipedia.
2 References
Bencode is defined as part of the BitTorrent specifications. Useful references include:
3 Representation of Terms
Bencode terms are represented as Racket data structures as follows:
- Bencode lists map to Racket lists 
- Bencode dictionaries map to Racket equal?-hashtables 
- Bencode integers map to Racket integers 
- Bencode strings map to Racket byte-vectors (bytes) 
In particular, Racket’s null value is the representation of the empty Bencode list.
4 What to require
All the functionality below can be accessed with a single require:
| (require bencode-codec) | package: bencode-codec | 
4.1 Reading Bencoded data
procedure
(bencode-read p) → (or/c any? eof-object?)
p : input-port? 
If a Bencoded string (Racket bytes) value appears on the input-port and has length in excess of bencode-bytes-limit’s current value, an error is signalled.
procedure
(bencode-read-to-end p) → list?
p : input-port? 
procedure
(bytes->bencode bs) → list?
bs : bytes? 
procedure
(bencode-bytes-limit new-limit) → void? new-limit : integer? 
4.2 Writing Bencoded data
procedure
(bencode-write term p) → void?
term : any? p : output-port? 
procedure
(bencode->bytes terms) → bytes?
terms : list?