Module stream [Preloaded]

Streams can have a couple of properties. The if-modified-since date property can be supplied by the open options. It causes the open primitive to throw a not-modified exception when the source has not been modified since the given date. The last-modified and expiration date properties can be retrieved via the open options.

Text streams have further the character set encoding property. For remote sources with a mime type this property defaults to the character set property of the mime type. Otherwise the property defaults to UTF-8. Incoming CR LF sequences or CR characters are automatically compressed respectively translated to LF characters.

If a text stream belongs to the file schema and is opened for read with the byte order mark detection on, this detection will try to determine the default encoding. The detection can currently detect UTF-8, UTF-16LE and UTF-16BE. If a mark is detected the initial read position is placed after the mark.

The following stream control predicates are provided:

current_input(S): [ISO 8.11.1]
The predicate succeeds when S unifies with the standard input stream.
current_output(S): [ISO 8.11.2]
The predicate succeeds when S unifies with the standard output stream.
current_error(S):
The predicate succeeds when S unifies with the standard error stream.
set_input(S): [ISO 8.11.3]
The predicate sets the standard input stream to the source S.
set_output(S): [ISO 8.11.4]
The predicate sets the standard output stream to the sink S.
set_error(S):
The predicate sets the standard error stream to the sink S.
open(P, M, S): [ISO 8.11.5.4]
open(P, M, S, O): [ISO 8.11.5.4]
The ternary predicate succeeds when S unifies with the new stream associated with the path or socket P and the access mode M (read, write or append). The quaternary predicate additionally recognizes the following open options:
type(T): [ISO] T is the type (text or binary), default value is text.
alias(A): [ISO] A is the alias.
bom(B): B is the byte order mark detection and generation flag.
use_caches(B): B is the use caches flag for the connection.
encoding(C): C is the character set encoding for the text stream.
buffer(S): S is the buffer size, or 0 if no buffer is required.
if_modified_since(D): D is the if-modified-since date for the connection.
If_none_match(V): V is the if-none-match tag for the connection.
reposition(B): [ISO] B is the reposition (false or true), default value is false.
newline(S): S is the newline character sequence to use in writing.
close(S): [ISO 8.11.6]
close(S, O): [ISO 8.11.6]
The unary predicate closes the closable S. The binary predicate additionally recognizes the following close options.
force(F): [ISO] F is the force flag, default is false.
stream_property(S, P): [ISO 8.11.8]
The predicate succeeds with all the properties of the stream S that unify with P. The following stream properties are supported:
mode(M): [ISO] M is the mode (read, write or append).
type(T): [ISO] T is the type (text or binary).
bom(B): B is the byte order mark.
encoding(C): C is the character set encoding of the text stream.
buffer(S): S is the buffer size, or 0 if no buffer is present.
last_modified(D): D is the last-modified date of the stream.
version_tag(V): V is the version tag of the stream.
expiration(D): D is the expiration date of the stream.
date(D): D is the request date of the stream.
max_age(M): M is the max age cache control of the stream.
mime_type(M): M is the mime type of the stream.
line_no(N): N is the line number of the text stream.
reposition(B): [ISO] B is the reposition (false or true).
position(P): [ISO] P is the actual file position.
length(L): L is the actual file length.
file_name(F): [ISO] F is the absolute path of the stream.
input: [ISO] The stream is an input stream.
output: [ISO] The stream is an output stream.
An undefined encoding/1 property is returned as a zero length atom. An undefined buffer property is returned as the value 0. The last_modified/, the expiration/1 and the date/1 properties are given in milliseconds since January 1, 1970 GMT. An undefined last_modified/1, expiration/1 or date/1 property is returned as the value 0.

The version tag is an atom that starts and ends with double quotes (“). An undefined version tag is returned as a zero length atom. The line_no/1 of a source starts with 1. The position/1 and length/1 properties are measured in bytes, starting with 0 and are available when reposition(true) holds.

An undefined file_name/1 is returned as a zero length atom. The mime_type/1 property is an atom of the form <type>/<subtype> or otherwise a zero length atom.

set_stream_position(S, P): [ISO 8.11.9]
The predicate sets the file position of the stream S to P.
set_stream_length(S, L):
The predicate sets the file length of the stream S to L.
open_resource(P, S):
open_resource(P, S, O):
The predicate succeeds when S unifies with the new resource stream associated with the path P. The ternary predicate additionally recognizes the following open options.

The following Prolog flags for stream control are provided:

sys_cur_input:
The legal value is a text or binary input stream. It is the current input of the current interpreter. Default value is the current input of the parent interpreter. The value can be changed.
sys_cur_output:
The legal value is a text or binary output stream. It is the current output of the current interpreter. Default value is the current output of the parent interpreter. The value can be changed.
sys_cur_error:
The legal value is a text or binary output stream. It is the current error of the current interpreter. Default value is the current error of the parent interpreter. The value can be changed.
sys_tool_input:
The legal value is a text or binary input stream. It is the current input of the current toolkit. Default value is the current input of the process environment. The value can be changed.
sys_tool_output:
The legal value is a text or binary output stream. It is the current output of the current toolkit. Default value is the current output of the process environment. The value can be changed.
sys_tool_error:
The legal value is a text or binary output stream. It is the current error of the current toolkit. Default value is the current error of the process environment. The value can be changed.

Comments