{ "4:spam" } [ "spam" >bencode ] unit-test
{ "3:\x01\x02\x03" } [ B{ 1 2 3 } >bencode ] unit-test
+{ "\x01\x02\x03" } [ B{ 51 58 1 2 3 } bencode> ] unit-test
{ { "spam" 42 } } [ "l4:spami42ee" bencode> ] unit-test
USING: arrays assocs byte-arrays combinators io
-io.streams.string kernel linked-assocs math math.parser
-sequences strings ;
+io.encodings.binary io.streams.byte-array io.streams.string
+kernel linked-assocs math math.parser sequences strings ;
IN: bencode
GENERIC: >bencode ( obj -- bencode )
[ read-string ]
} case ;
-: bencode> ( bencode -- obj )
+GENERIC: bencode> ( bencode -- obj )
+
+M: byte-array bencode>
+ binary [ read-bencode ] with-byte-reader ;
+
+M: string bencode>
[ read-bencode ] with-string-reader ;