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) β integer?
(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?