{ B{ 0 1 2 3 4 5 6 7 8 9 10 11 12 } f }
[ up-to-13-reader new [ 20 swap stream-read ] [ 20 swap stream-read ] bi ] unit-test
+{
+ T{ slice f 0 8 B{ 0 1 2 3 4 5 6 7 } }
+ T{ slice f 0 5 B{ 8 9 10 11 12 205 206 207 } }
+ f
+} [
+ up-to-13-reader new
+ [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ]
+ [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ]
+ [ B{ 200 201 202 203 204 205 206 207 } swap stream-read-into ] tri
+] unit-test
{
B{ 0 1 2 3 4 5 6 7 8 } 9
: (new-sequence-for-stream) ( n stream -- seq )
stream-exemplar new-sequence ; inline
-: (read-into-new) ( n stream quot -- byte-array/f )
+: (read-into-new) ( n stream quot: ( n buf stream -- count ) -- seq/f )
[ 2dup (new-sequence-for-stream) swap ] dip curry keep
over 0 = [ 2drop f ] [ resize ] if ; inline
+: (read-into) ( buf stream quot: ( n buf stream -- count ) -- buf-slice/f )
+ [ dup length over ] 2dip call
+ [ drop f ] [ head-slice ] if-zero ; inline
+
PRIVATE>
: stream-read ( n stream -- seq/f )
: stream-read-partial ( n stream -- seq/f )
[ stream-read-partial-unsafe ] (read-into-new) ; inline
+ERROR: invalid-read-buffer buf stream ;
+
+
+: stream-read-into ( buf stream -- buf-slice/f )
+ [ stream-read-unsafe ] (read-into) ; inline
+: stream-read-partial-into ( buf stream -- buf-slice/f )
+ [ stream-read-partial-unsafe ] (read-into) ; inline
+
: read ( n -- seq ) input-stream get stream-read ; inline
: read-partial ( n -- seq ) input-stream get stream-read-partial ; inline
+: read-into ( buf -- buf-slice )
+ input-stream get stream-read-into ; inline
+: read-partial-into ( buf -- buf-slice )
+ input-stream get stream-read-partial-into ; inline
: each-stream-line ( ... stream quot: ( ... line -- ... ) -- ... )
swap [ stream-readln ] curry each-morsel ; inline
combinators.short-circuit destructors io io.encodings.ascii
io.encodings.binary io.private io.streams.byte-array
io.streams.peek io.streams.string kernel locals make math
-sequences tools.test vectors ;
+sequences tools.test vectors io.streams.memory ;
IN: io.streams.peek.tests
[ CHAR: a ]