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!
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
Bencode is defined as part of the BitTorrent specifications. Useful
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
4.1 Reading Bencoded data
Reads and returns a single Bencoded term from the given input-port, or
if the end-of-file is reached before any other
data appears on the input-port. An error is signalled if a syntax
error or unexpected end-of-file is detected.
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.
returns as many Bencoded terms as are available on the given input
port. Once end-of-file is reached, returns the terms as a list in the
order they were read from the port. Errors are otherwise signalled as
, but takes input from the supplied
byte-vector instead of from an input-port.
A parameter. Retrieves or sets the current limit on strings read by
any of the other Bencode-reading functions defined in this library.
4.2 Writing Bencoded data
single term (which must be a Racket datum as specified in
Representation of Terms
) to the given output-port.
Returns a byte-vector
containing a Bencoded representation of the given list of terms, in
the order they appear in the list. Note that it encodes a list of
terms, not a single term, and so it is roughly an inverse of