]> gitweb.factorcode.org Git - factor.git/commitdiff
base64 now deals with byte arrays instead of strings
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 6 Mar 2009 20:10:53 +0000 (14:10 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 6 Mar 2009 20:10:53 +0000 (14:10 -0600)
basis/base64/base64-tests.factor
basis/base64/base64.factor

index dcc4aa5240cd9757455d9ae378242def89deed1f..ddefff35bb653a57356a502a5d997e4859bdabbc 100644 (file)
@@ -1,25 +1,26 @@
-USING: kernel tools.test base64 strings sequences  ;
+USING: kernel tools.test base64 strings sequences
+io.encodings.string io.encodings.ascii ;
 IN: base64.tests
 
-[ "abcdefghijklmnopqrstuvwxyz" ] [ "abcdefghijklmnopqrstuvwxyz" >base64 base64> >string
+[ "abcdefghijklmnopqrstuvwxyz" ] [ "abcdefghijklmnopqrstuvwxyz" ascii encode >base64 base64> ascii decode
 ] unit-test
-[ "" ] [ "" >base64 base64> >string ] unit-test
-[ "a" ] [ "a" >base64 base64> >string ] unit-test
-[ "ab" ] [ "ab" >base64 base64> >string ] unit-test
-[ "abc" ] [ "abc" >base64 base64> >string ] unit-test
-[ "abcde" ] [ "abcde" >base64 3 cut "\r\n" swap 3append base64> >string ] unit-test
+[ f ] [ "" ascii encode >base64 base64> ascii decode ] unit-test
+[ "a" ] [ "a" ascii encode >base64 base64> ascii decode ] unit-test
+[ "ab" ] [ "ab" ascii encode >base64 base64> ascii decode ] unit-test
+[ "abc" ] [ "abc" ascii encode >base64 base64> ascii decode ] unit-test
+[ "abcde" ] [ "abcde" ascii encode >base64 3 cut "\r\n" swap 3append base64> ascii decode ] unit-test
 
 ! From http://en.wikipedia.org/wiki/Base64
 [ "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ]
 [
     "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."
-    >base64 >string
+    ascii encode >base64 >string
 ] unit-test
 
 [ "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\r\nIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\r\ndGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\r\ndWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\r\nZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ]
 [
     "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."
-    >base64-lines >string
+    ascii encode >base64-lines >string
 ] unit-test
 
 \ >base64 must-infer
index 7f96e1943085bd55ea57b4ce8136df30a60a1ef1..c51d871bb5996009d8a3b226c81bc29901b5cef3 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: combinators io io.binary io.encodings.binary
-io.streams.byte-array io.streams.string kernel math namespaces
+io.streams.byte-array kernel math namespaces
 sequences strings io.crlf ;
 IN: base64
 
@@ -75,10 +75,10 @@ PRIVATE>
     } case ;
 
 : >base64 ( seq -- base64 )
-    binary [ [ encode-base64 ] with-string-reader ] with-byte-writer ;
+    binary [ binary [ encode-base64 ] with-byte-reader ] with-byte-writer ;
 
 : base64> ( base64 -- seq )
-    [ binary [ decode-base64 ] with-byte-reader ] with-string-writer ;
+    binary [ binary [ decode-base64 ] with-byte-reader ] with-byte-writer ;
 
 : >base64-lines ( seq -- base64 )
-    binary [ [ encode-base64-lines ] with-string-reader ] with-byte-writer ;
+    binary [ binary [ encode-base64-lines ] with-byte-reader ] with-byte-writer ;