]> gitweb.factorcode.org Git - factor.git/commitdiff
io: get variables out of stream-copy loop
authorJoe Groff <arcata@gmail.com>
Fri, 14 Oct 2011 03:25:53 +0000 (20:25 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 18 Oct 2011 04:23:07 +0000 (21:23 -0700)
core/io/io-tests.factor
core/io/io.factor

index c604faf9638a256d72c5f6c0284f8132de6ee93d..970eef0e34ac5d06b242cfbad1dbda3de02197bb 100644 (file)
@@ -1,4 +1,5 @@
-USING: accessors io kernel math parser tools.test words ;
+USING: accessors io io.streams.string kernel math parser sbufs
+sequences tools.test words ;
 IN: io.tests
 
 { f } [
@@ -62,3 +63,6 @@ M: dumb-writer stream-write1 vector>> push ; inline
     [ stream-nl ]
     [ vector>> ] tri
 ] unit-test
+
+{ SBUF" asdf" }
+[ "asdf" <string-reader> 4 <sbuf> [ stream-copy ] keep ] unit-test
index 59d019954dfc30d192b4bcfe3246b1e8effcc8ea..d5151ba6da950e067ab078592469e1a3c6654e06 100644 (file)
@@ -149,9 +149,11 @@ PRIVATE>
 : contents* ( -- seq )
     input-stream get stream-contents* ; inline
 
+: stream-copy* ( in out -- )
+    [ stream-write ] curry each-stream-block ; inline
+
 : stream-copy ( in out -- )
-    [ [ [ write ] each-block ] with-output-stream ]
-    curry with-input-stream ;
+    [ [ stream-copy* ] with-disposal ] curry with-disposal ;
 
 ! Default implementations of stream operations in terms of read1/write1