basilisp.contrib.bencode¶
Support for bencode encoding and decoding.
- fn (decode data {:as opts, :keys [keywordize-keys key-fn]})[source]¶
Decode the first value in the bencoded
databytes according tooptsand return a[decoded* rest*]vector.The decoded* item in the vector is the decoded value of the first item in
datawhile rest* is the remaining unencoded values.If
datacannot be decoded (e.g. is incomplete or an error occurred), it returns a[nil data]vector.optsis a map with the following optional supported keys.- keyword
:keywordize-keys: if the decoded value is a map, keywordize its keys.
- keyword
:key-fn: a function which will be called for each key-in a map; cannot be specified if
:keywordize-keysis also specified- keyword
:string-fn: a function which will be called for each byte string which is not a map key; default is
basilisp.core/identity
- keyword
- fn (decode-all data)[source]¶
- fn (decode-all data opts)
Decode all values in the bencoded
databytes and return them as a[values* incomplete*]vector.The
values*item is a collection of thedatadecoded values, whileincomplete*is the rest of thedatabytes that could not be decoded ornil.optsis a map supporting the same keys asdecode.
- fn (encode d)[source]¶
Encode the object
dinto a byte string usingbencodeencoding.encodesupports encoding the following types:str, which is first decoded to UTF-8byteskeywords and symbols, which are first converted to strings (including namespace, separated by ‘/’) and then converted using the rules for
strsBasilisp lists, vectors, and maps
Mapping type keys must one of: keywords, symbols, or strings.
This function does not support
floatbecause thebencodespecification does not support non-integer numerics.Set types (including
frozenset,set, or Basilisp’s set types) are not supported due to the requirement that lists retain their original element ordering.