Module "byte" [Preloaded]

Bytes can be written to binary streams or read from binary streams. Binary streams can be obtained by the to open/3 and open/4 system predicates documented in the stream control section. The standard input, output and error might also point to binary streams.

Text streams and binary streams share the notion of flushing and end of stream. Therefore the system predicates flush_output/[0,1] and at_end_of_stream/[0,1] apply to both text streams and binary streams. If the stream can be repositioned, irrespective of the stream type, further two stream properties position/1 and length/1 are provided.

It should be noted that our at_end_of_stream/[0,1] is not as powerful as the C-call feof(), so it cannot be used to distinguish an interrupted stream from an end of file. Further, we do not pro-vide the information as a stream property end_of_stream/1. Other stream properties that are also not supported are alias/1 and eof_action/1.

The following byte input/output predicates are provided:

put_byte(B): [ISO 8.13.3]
put_byte(H, B): [ISO 8.13.3]
The unary predicate writes the byte B to the standard output. The binary predicate takes an additional binary stream sink as argument.
get_byte(B): [ISO 8.13.1]
get_byte(H, B): [ISO 8.13.1]
The predicate reads a byte from the standard input. The predicate succeeds when B unifies with the read byte or the integer -1 when the end of the stream has been reached.The binary predicate takes an additional binary stream source as argument.
peek_byte(B): [ISO 8.13.2]
peek_byte(H, B): [ISO 8.13.2]
The predicate reads a byte from the standard input and puts it back. The predicate succeeds when B unifies with the read byte or the integer -1 when the end of the stream has been reached. The binary predicate takes an additional binary stream source as argument.
flush_output: [ISO 8.11.7]
flush_output(S): [ISO 8.11.7]
The predicate without arguments flushes the standard output. The unary predicate takes an additional text or binary stream sink as argument.
at_end_of_stream: [ISO 8.11.8]
at_end_of_stream(S): [ISO 8.11.8]
The predicate without arguments checks whether we are at the end of the standard input. The unary predicate takes an additional text or binary stream sink as argument.

The following stream properties for byte input/output are provided:

type(T): [ISO 7.10.2.13]
The property indicates the type of the stream. Possibly values are "binary" and "text". The property cannot be changed, it is determined during the creation of a stream.
output: [ISO 7.10.2.13]
The property indicates that the stream is an input stream. The property cannot be changed, it is determined during the creation of a stream.
input: [ISO 7.10.2.13]
The property indicates that the stream is an input stream. The property cannot be changed, it is determined during the creation of a stream.
reposition(R): [ISO 7.10.2.13]
The property indicates whether the stream can be repositioned. Possibly values are "false" and true". The property cannot be changed, it is determined during the creation of a stream.
position(B): [ISO 7.10.2.13]
This property is available if the stream can be repositioned. The property then indicates the current stream position. The property can be changed.
length(L):
This property is available if the stream can be repositioned. The property then indicates the current stream length. The property can be changed.
buffer(B):
This property indicates the buffer size of the stream. If the stream is a text stream, it indicates the buffer size of the underlying binary stream. The property cannot be changed, it is determined during the creation of a stream.
mode(M): [ISO 7.10.2.13]
This property indicates the mode of the stream. Possible values are "read", "write" and "append". The property cannot be changed, it is determined during the creation of a stream.
file_name(N): [ISO 7.10.2.13]
This property indicates the file name of the stream. The file name term is an URI atom that was canonized and is not ASCII encoded. The property cannot be changed, it is determined during the creation of a stream.

Comments