bencode: alloe bencode of byte-arrays.

flac
John Benediktsson 2020-01-08 17:33:11 -08:00 committed by Steve Ayerhart
parent 55a69c492a
commit 1adabc3168
No known key found for this signature in database
GPG Key ID: 5BFD39C5359E967D
2 changed files with 7 additions and 3 deletions

View File

@ -6,6 +6,8 @@ USING: bencode linked-assocs tools.test ;
{ "4:spam" } [ "spam" >bencode ] unit-test { "4:spam" } [ "spam" >bencode ] unit-test
{ "3:\x01\x02\x03" } [ B{ 1 2 3 } >bencode ] unit-test
{ { "spam" 42 } } [ "l4:spami42ee" bencode> ] unit-test { { "spam" 42 } } [ "l4:spami42ee" bencode> ] unit-test
{ LH{ { "bar" "spam" } { "foo" 42 } } } [ { LH{ { "bar" "spam" } { "foo" 42 } } } [

View File

@ -1,6 +1,6 @@
USING: arrays assocs combinators io io.encodings.ascii USING: arrays assocs byte-arrays combinators io
io.encodings.string io.streams.string kernel linked-assocs math io.streams.string kernel linked-assocs math math.parser
math.parser sequences strings ; sequences strings ;
IN: bencode IN: bencode
GENERIC: >bencode ( obj -- bencode ) GENERIC: >bencode ( obj -- bencode )
@ -11,6 +11,8 @@ M: integer >bencode
M: string >bencode M: string >bencode
[ length number>string ":" ] keep 3append ; [ length number>string ":" ] keep 3append ;
M: byte-array >bencode "" like >bencode ;
M: sequence >bencode M: sequence >bencode
[ >bencode ] map concat "l" "e" surround ; [ >bencode ] map concat "l" "e" surround ;