]> gitweb.factorcode.org Git - factor.git/commitdiff
io: Make stream-contents call stream-contents* and do the disposal in the top-level...
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Aug 2012 00:03:51 +0000 (17:03 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Aug 2012 00:03:51 +0000 (17:03 -0700)
basis/delegate/protocols/protocols.factor
core/io/encodings/encodings.factor
core/io/io-docs.factor
core/io/io.factor

index c496979dc206b599fc379a799eef88290935dc3d..eb2434cf0fe00fd8974db0f6a52fa1012d0b7ac6 100644 (file)
@@ -14,7 +14,7 @@ delete-at clear-assoc new-assoc assoc-like ;
 
 PROTOCOL: input-stream-protocol
 stream-read1 stream-read-unsafe stream-read-partial-unsafe
-stream-readln stream-read-until stream-contents ;
+stream-readln stream-read-until stream-contents* ;
 
 PROTOCOL: output-stream-protocol
 stream-flush stream-write1 stream-write stream-nl ;
index aa5d3af93e0e7ba47b6778991a4edeea93882599..b0b5ff7f7e4d94306d56b345226d3ea6b7c71b57 100644 (file)
@@ -93,8 +93,8 @@ M: decoder stream-read-unsafe
         ] [ 2drop 2drop 0 ] if*
     ] if ; inline
 
-M: decoder stream-contents
-    (stream-contents-by-element) ;
+M: decoder stream-contents*
+    (stream-contents-by-element) ; inline
 
 : line-ends/eof ( stream str -- str ) f like swap cr- ; inline
 
index bfa16e4ed728e485835d0a159608cc99c9a66bfe..38002bed77ed1a9404fe6d7be9fe9f67d1257825 100644 (file)
@@ -307,7 +307,7 @@ HELP: each-block
 
 HELP: stream-contents
 { $values { "stream" "an input stream" } { "seq" { $or string byte-array } } }
-{ $description "Reads all elements in the given stream until the stream is exhausted. The type of the sequence depends on the stream's element type." }
+{ $description "Reads all elements in the given stream until the stream is exhausted. The type of the sequence depends on the stream's element type. The stream is closed after completion." }
 $io-error ;
 
 HELP: contents
index 20d3b491b3f04109e856349ab0c6f63a8d766551..248571616529546a56b7e335464b9305bd91a272 100644 (file)
@@ -13,7 +13,8 @@ GENERIC: stream-read-unsafe ( n buf stream -- count )
 GENERIC: stream-read-until ( seps stream -- seq sep/f )
 GENERIC: stream-read-partial-unsafe ( n buf stream -- count )
 GENERIC: stream-readln ( stream -- str/f )
-GENERIC: stream-contents ( stream -- seq )
+GENERIC: stream-contents* ( stream -- seq )
+: stream-contents ( stream -- seq ) [ stream-contents* ] with-disposal ;
 
 GENERIC: stream-write1 ( elt stream -- )
 GENERIC: stream-write ( data stream -- )
@@ -183,16 +184,13 @@ CONSTANT: each-block-size 65536
     input-stream get swap each-stream-block ; inline
 
 : (stream-contents-by-length) ( stream len -- seq )
-    dup rot [
-        [ (new-sequence-for-stream) ]
-        [ [ stream-read-unsafe ] curry keep resize ] bi
-    ] with-disposal ; inline
+    dup rot
+    [ (new-sequence-for-stream) ]
+    [ [ stream-read-unsafe ] curry keep resize ] bi ; inline
 
 : (stream-contents-by-block) ( stream -- seq )
-    [
-        [ [ ] collector [ each-stream-block ] dip { } like ]
-        [ stream-exemplar concat-as ] bi
-    ] with-disposal ; inline
+    [ [ ] collector [ each-stream-block ] dip { } like ]
+    [ stream-exemplar concat-as ] bi ; inline
 
 : (stream-contents-by-length-or-block) ( stream -- seq )
     dup stream-length
@@ -238,7 +236,7 @@ M: input-stream stream-read-partial-unsafe stream-read-unsafe ; inline
 M: input-stream stream-read-until read-until-loop ; inline
 M: input-stream stream-readln
     "\n" swap stream-read-until drop ; inline
-M: input-stream stream-contents (stream-contents-by-length-or-block) ; inline
+M: input-stream stream-contents* (stream-contents-by-length-or-block) ; inline
 M: input-stream stream-seekable? drop f ; inline
 M: input-stream stream-length drop f ; inline
 
@@ -253,7 +251,7 @@ M: f stream-read-unsafe 3drop 0 ; inline
 M: f stream-read-until 2drop f f ; inline
 M: f stream-read-partial-unsafe 3drop 0 ; inline
 M: f stream-readln drop f ; inline
-M: f stream-contents drop f ; inline
+M: f stream-contents* drop f ; inline
 
 M: f stream-write1 2drop ; inline
 M: f stream-write 2drop ; inline