seek(+Stream, +Offset, +Method, -NewLocation)

Seeks to an arbitrary byte position in Stream.


Stream stream_object
a valid Prolog stream
Offset integer
the offset in bytes to seek relative to Method specified.
Method one of [bof,current,eof]
specifies where to start seeking. It is one of the following.

Seek from beginning of the file stream.
Seek from current position of the file stream.
Seek from end of the file stream.

NewLocation integer
The byte offset from beginning of the file after seeking operation.


Sets the current position of the file stream Stream to a new position according to Offset and Method. If Method is

the new position is set to Offset bytes from beginning of the file stream.
the new position is Offset bytes plus the current position of Stream.
the new position is Offset bytes, a negative integer, plus the size of the file.

If Offset is 0, seek/4 returns the current position from the beginning of Stream and sets the position to the same location.

If Stream is an output stream permitting flushing output, the characters in the buffer of the stream are flushed before seek is performed. If the output stream Stream does not permit flushing output and there are characters remaining in the buffer, then a permission error is raised.

If Stream is an input stream, the characters in the input buffer of the stream are discarded before seek is performed. The input buffer is empty when the seek/4 call returns.


Stream errors (see ref-iou-sfh-est), plus:

Method is not one of bof, current or eof.

Offset is a negative value and Method is bof.

Offset is a positive value and Method is eof.

Offset or Method is not instantiated.
Stream is not a stream object.

Offset is not an integer type.

Method is not an atom type.

Stream names an open stream but the stream is not open with seek(byte) permission.

An error occurred while seeking in the file stream.

Flushing attempted but not permitted.

See Also

stream_position/[2,3], open/4, character_count/2, line_count/2, line_position/2. ref-iou