io.streams.(limited,throwing): read-unsafe methods
parent
01419b3e6b
commit
055196d4b7
|
@ -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 ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: (read-until) ( stream seps buf -- stream seps buf sep/f )
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2010 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors destructors io kernel locals namespaces
|
||||
sequences fry ;
|
||||
sequences fry math ;
|
||||
IN: io.streams.throwing
|
||||
|
||||
ERROR: stream-exhausted n stream word ;
|
||||
|
@ -28,6 +28,14 @@ M:: throws-on-eof-stream stream-read-partial ( n stream -- seq )
|
|||
n stream stream>> 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 ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue