See section 4.2 for an overview of supported character representations.
userand the cursor is not at the left margin.
user. See also flush_output/[0,1].
This predicate is intended for efficient unbuffered copying and
filtering of input coming from network connections or devices. It also
enables the library
library(pure_input), which processes
input from files and streams using a DCG.
The following code fragment realises efficient non-blocking copying of data from an input to an output stream. The at_end_of_stream/1 call checks for end-of-stream and fills the input buffer. Note that the use of a get_code/2 and put_code/2 based loop requires a flush_output/1 call after each put_code/2. The copy_stream_data/2 does not allow for inspection of the copied data and suffers from the same buffering issues.
copy(In, Out) :- repeat, fill_buffer(In), read_pending_codes(In, Chars, Tail), \+ \+ ( Tail = , format(Out, '~s', [Chars]), flush_output(Out) ), ( Tail ==  -> ! ; fail ).