From 3523d24785b069e8a97b8bebef62cc478f5dd0a6 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 25 Mar 2011 13:58:16 -0700 Subject: [PATCH] io: implement "stream-contents" in terms of "each-stream-block". --- core/io/io.factor | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/io/io.factor b/core/io/io.factor index 0821cfff78..bd1bf27985 100644 --- a/core/io/io.factor +++ b/core/io/io.factor @@ -102,21 +102,21 @@ PRIVATE> : lines ( -- seq ) input-stream get stream-lines ; inline +: each-stream-block ( stream quot: ( ... block -- ... ) -- ) + swap 65536 swap [ stream-read-partial ] 2curry each-morsel ; inline + +: each-block ( quot: ( ... block -- ... ) -- ) + input-stream get swap each-stream-block ; inline + : stream-contents ( stream -- seq ) [ - [ [ 65536 swap stream-read-partial dup ] curry [ ] produce nip ] + [ [ ] collector [ each-stream-block ] dip { } like ] [ stream-element-exemplar concat-as ] bi ] with-disposal ; : contents ( -- seq ) input-stream get stream-contents ; inline -: each-stream-block ( stream quot: ( ... block -- ... ) -- ) - swap [ 8192 swap stream-read-partial ] curry each-morsel ; inline - -: each-block ( quot: ( ... block -- ... ) -- ) - input-stream get swap each-stream-block ; inline - : stream-copy ( in out -- ) [ [ [ write ] each-block ] with-output-stream ] curry with-input-stream ;