chan seek

Moves the place of the next read or write of a channel.

chan seek CHAN OFFSET ?ORIGIN?

Description

Moves the place of CHAN to OFFSET bytes from ORIGIN: start (the default), current, or end. A negative OFFSET moves back from current or end. A seek empties the buffers of the channel.

Arguments

ArgumentTypeDefaultDescription
CHANchannelrequiredThe channel.
OFFSETintegerrequiredThe count of bytes to move.
ORIGINstart, current, or endstartThe place that OFFSET counts from.

Values: start, current, end.

Returns

An empty string.

Examples

% set f [open a.txt w]; chan puts $f hello; chan close $f
> set f [open a.txt]
> chan seek $f 2
> set d [chan read $f]
> chan close $f
> set d
llo


% set f [open a.txt]
> chan seek $f -2 end
> set d [chan read $f]
> chan close $f
> set d
o

Errors

% set f [open a.txt]
> catch {chan seek $f x} m
> chan close $f
> error $m
expected integer but got "x"
-errorcode NONE

Facts

Capability
channels. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also