]> gitweb.factorcode.org Git - factor.git/commitdiff
bencode: alloe bencode of byte-arrays.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 9 Jan 2020 01:33:11 +0000 (17:33 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 9 Jan 2020 01:33:11 +0000 (17:33 -0800)
extra/bencode/bencode-tests.factor
extra/bencode/bencode.factor

index 2ef67966819cfbb8e139fb7fe950ab14f5b80541..b9a1bcb0b482e255e0db6d0c1d75add8ebd6e80e 100644 (file)
@@ -6,6 +6,8 @@ USING: bencode linked-assocs tools.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
 
 { LH{ { "bar" "spam" } { "foo" 42 } } } [
index 7173b93c12bf9a4d104a5eb23e0446854eb02845..b23ea09c7141f7e6fbcf352c18a05dd3d4297ed8 100644 (file)
@@ -1,6 +1,6 @@
-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 )
@@ -11,6 +11,8 @@ M: integer >bencode
 M: string >bencode
     [ length number>string ":" ] keep 3append ;
 
+M: byte-array >bencode "" like >bencode ;
+
 M: sequence >bencode
     [ >bencode ] map concat "l" "e" surround ;