[REBOL] Re: open/lines
From: holger:rebol at: 14-Jan-2001 15:26
On Sun, Jan 14, 2001 at 04:20:43PM -0600, Paul Tretter wrote:
> If I used open/line/direct/no-wait I get a block when doing a:
>
> copy port
>
> I get a string when I do:
>
> copy first port
>
> My question is how do I use copy port and convert it to get the same output that copy
first provides in a string format without generating a past-end error.
Here is the behavior for ports in line/direct/no-wait:
copy returns a block of all lines waiting to be read, and removes them from the port
buffer. Each element of the block is one line. If no lines are waiting then an empty
block is returned. If the other end has closed the connection then none is returned.
first port
is a shortcut for "pick port 1". It returns the next line and removes it from
the buffer. The result is none either if no data is pending (this will probably change
in the
next version) or if the end of the stream has been reached. You don't need to "copy"
the
result.
If you want to be able to distinguish between no data and eof, but still want only a
single
line returnd to you at a time, then use "copy/part port 1". If the returned value is
a block
then it is either empty or has exactly one item in it, which you can access using "first".
--
Holger Kruse
[holger--rebol--com]