io.streams.(limited,throwing): read-unsafe methods

db4
Joe Groff 2011-10-12 12:31:43 -07:00
parent 01419b3e6b
commit 055196d4b7
2 changed files with 18 additions and 1 deletions

View File

@ -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 )

View File

@ -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 ;