diff --git a/basis/io/streams/limited/limited.factor b/basis/io/streams/limited/limited.factor index 929520edaa..0ab44bca04 100644 --- a/basis/io/streams/limited/limited.factor +++ b/basis/io/streams/limited/limited.factor @@ -77,6 +77,9 @@ ERROR: limit-exceeded n stream ; [ adjust-limited-read ] dip pick 0 <= [ 3drop f ] [ [ stream>> ] dip call ] if ; inline +:: maybe-read-unsafe ( n buf limited-stream quot: ( n buf stream -- count ) -- count ) + n limited-stream [| n' stream | n' buf stream quot call ] maybe-read ; inline + PRIVATE> M: limited-stream stream-read1 @@ -89,6 +92,12 @@ M: limited-stream stream-read M: limited-stream stream-read-partial [ stream-read-partial ] maybe-read ; +M: limited-stream stream-read-unsafe + [ stream-read-unsafe ] maybe-read-unsafe ; + +M: limited-stream stream-read-partial-unsafe + [ stream-read-partial-unsafe ] maybe-read-unsafe ; + > stream-read-partial [ n stream \ read-partial stream-exhausted ] unless* ; +M:: throws-on-eof-stream stream-read-unsafe ( n buf stream -- count ) + n buf stream stream>> stream-read-unsafe + dup n = [ n stream \ stream-read-unsafe stream-exhausted ] unless ; + +M:: throws-on-eof-stream stream-read-partial-unsafe ( n buf stream -- count ) + n buf stream stream>> stream-read-partial-unsafe + [ n stream \ stream-read-partial-unsafe stream-exhausted ] when-zero ; + M: throws-on-eof-stream stream-tell stream>> stream-tell ;