- Documentation
- Reference manual
- Built-in Predicates
- Primitive character I/O
- nl/0
- nl/1
- put/1
- put/2
- put_byte/1
- put_byte/2
- put_char/1
- put_char/2
- put_code/1
- put_code/2
- tab/1
- tab/2
- flush_output/0
- flush_output/1
- ttyflush/0
- get_byte/1
- get_byte/2
- get_code/1
- get_code/2
- get_char/1
- get_char/2
- get0/1
- get0/2
- get/1
- get/2
- peek_byte/1
- peek_byte/2
- peek_code/1
- peek_code/2
- peek_char/1
- peek_char/2
- peek_string/3
- skip/1
- skip/2
- get_single_char/1
- with_tty_raw/1
- at_end_of_stream/0
- at_end_of_stream/1
- set_end_of_stream/1
- copy_stream_data/3
- copy_stream_data/2
- fill_buffer/1
- read_pending_codes/3
- read_pending_chars/3
- Primitive character I/O
- Built-in Predicates
- Packages
- Reference manual
Availability:built-in
[]
).
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 ).