DoxigAlpha

seekBy

Function parameters

Parameters

#
self:*Self
amt:i64

Deprecated in favor of `std.Io.Reader.fixed` and `std.Io.Writer.fixed`.

Functions

#
FixedBufferStream
Deprecated in favor of `std.Io.Reader.fixed` and `std.Io.Writer.fixed`.

Source

Implementation

#
pub fn seekBy(self: *Self, amt: i64) SeekError!void {
    if (amt < 0) {
        const abs_amt = @abs(amt);
        const abs_amt_usize = std.math.cast(usize, abs_amt) orelse std.math.maxInt(usize);
        if (abs_amt_usize > self.pos) {
            self.pos = 0;
        } else {
            self.pos -= abs_amt_usize;
        }
    } else {
        const amt_usize = std.math.cast(usize, amt) orelse std.math.maxInt(usize);
        const new_pos = std.math.add(usize, self.pos, amt_usize) catch std.math.maxInt(usize);
        self.pos = @min(self.buffer.len, new_pos);
    }
}