Confusion with ARGF#readpartial

From the doc:
http://www.rubydoc.info/stdlib/core/ARGF#readpartial-instance_method

readpartial is designed for streams such as pipes, sockets, and ttys. It
blocks only when no data is immediately available. This means that it
blocks only when following all conditions hold:

The byte buffer in the IO object is empty.

The content of the stream is empty.

The stream has not reached EOF.

When readpartial blocks, it waits for data or EOF. If some data is
read, readpartial returns with the data
.If EOF is reached,
readpartial raises an EOFError.

When readpartial doesn’t block, it returns or raises immediately. If
the byte buffer is not empty, it returns the data in the
buffer
.Otherwise, if the stream has some content, it returns the
data in the stream
.If the stream reaches EOF an EOFError is
raised.

Could anyone help me to understand how ARGF#readpartial is coded for
each of the above ** marked lines?

Thanks

2013/3/27 Pritam D. [email protected]:

Could anyone help me to understand how ARGF#readpartial is coded for
each of the above ** marked lines?

It seems the document is just copied from IO#readpartial and doesn’t
describe ARGF specific behavior.

Since ARGF is a concatenation of multiple files,
read system call notify EOF for each file.

ARGF#readpartial returns empty string for EOF on the files except last
one.
ARGF#readpartial raises EOFError for EOF on the last file.

% echo foo > foo
% ruby -e ‘loop { p ARGF.readpartial(4096) }’ foo foo foo
“foo\n”
“”
“foo\n”
“”
“foo\n”
-e:1:in readpartial': end of file reached (EOFError) from -e:1:inblock in ’
from -e:1:in loop' from -e:1:in

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs