stream-read-partial-unsafe ( n buf stream -- count )
Factor handbook » Input and output » Streams » Stream protocol

Prev:stream-read-until ( seps stream -- seq sep/f )
Next:stream-read ( n stream -- seq/f )


na non-negative integer
bufa c-ptr or a string
streaman input stream

countan integer

Generic word contract
Reads up to n elements from the stream without blocking. If no data is available immediately on the stream, blocks until data is available. The data is stored directly into the buffer provided by buf, which must be a string (in the case of a character stream), or a byte array, specialized array, or other pointer to memory (in the case of a byte stream). There must be space in the buffer for at least n elements. Returns the number of elements read from the stream, or zero if the end of the stream was reached.

This word does not perform bounds checking on buf. Most code should use stream-read-partial or stream-read-partial-into instead.

Throws an error if the I/O operation fails.


GENERIC: stream-read-partial-unsafe ( n buf stream -- count )


M:: counting-stream stream-read-partial-unsafe
( n buf stream -- count )
n buf stream stream>> stream-read-partial-unsafe
:> count stream [ count + ] change-in-count drop count ;