io: Make stream-contents call stream-contents* and do the disposal in the top-level. Fixes #645.
parent
2b9f4668b6
commit
6c4043bb25
|
@ -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 ;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue