{ "4:spam" } [ "spam" >bencode ] unit-test
+{ "3:\x01\x02\x03" } [ B{ 1 2 3 } >bencode ] unit-test
+
{ { "spam" 42 } } [ "l4:spami42ee" bencode> ] unit-test
{ LH{ { "bar" "spam" } { "foo" 42 } } } [
-USING: arrays assocs combinators io io.encodings.ascii
-io.encodings.string io.streams.string kernel linked-assocs math
-math.parser sequences strings ;
+USING: arrays assocs byte-arrays combinators io
+io.streams.string kernel linked-assocs math math.parser
+sequences strings ;
IN: bencode
GENERIC: >bencode ( obj -- bencode )
M: string >bencode
[ length number>string ":" ] keep 3append ;
+M: byte-array >bencode "" like >bencode ;
+
M: sequence >bencode
[ >bencode ] map concat "l" "e" surround ;