| ... | ... | @@ -1189,7 +1189,7 @@ pub const Reader = struct { |
| 1189 | 1189 | pub fn seekBy(r: *Reader, offset: i64) Reader.SeekError!void { |
| 1190 | 1190 | switch (r.mode) { |
| 1191 | 1191 | .positional, .positional_reading => { |
| 1192 | | setPosAdjustingBuffer(r, @intCast(@as(i64, @intCast(r.pos)) + offset)); |
| 1192 | setLogicalPos(r, @intCast(@as(i64, @intCast(logicalPos(r))) + offset)); |
| 1193 | 1193 | }, |
| 1194 | 1194 | .streaming, .streaming_reading => { |
| 1195 | 1195 | if (posix.SEEK == void) { |
| ... | ... | @@ -1198,7 +1198,7 @@ pub const Reader = struct { |
| 1198 | 1198 | } |
| 1199 | 1199 | const seek_err = r.seek_err orelse e: { |
| 1200 | 1200 | if (posix.lseek_CUR(r.file.handle, offset)) |_| { |
| 1201 | | setPosAdjustingBuffer(r, @intCast(@as(i64, @intCast(r.pos)) + offset)); |
| 1201 | setLogicalPos(r, @intCast(@as(i64, @intCast(logicalPos(r))) + offset)); |
| 1202 | 1202 | return; |
| 1203 | 1203 | } else |err| { |
| 1204 | 1204 | r.seek_err = err; |
| ... | ... | @@ -1222,16 +1222,16 @@ pub const Reader = struct { |
| 1222 | 1222 | pub fn seekTo(r: *Reader, offset: u64) Reader.SeekError!void { |
| 1223 | 1223 | switch (r.mode) { |
| 1224 | 1224 | .positional, .positional_reading => { |
| 1225 | | setPosAdjustingBuffer(r, offset); |
| 1225 | setLogicalPos(r, offset); |
| 1226 | 1226 | }, |
| 1227 | 1227 | .streaming, .streaming_reading => { |
| 1228 | | if (offset >= r.pos) return Reader.seekBy(r, @intCast(offset - r.pos)); |
| 1228 | if (offset >= r.pos) return Reader.seekBy(r, @intCast(offset - logicalPos(r))); |
| 1229 | 1229 | if (r.seek_err) |err| return err; |
| 1230 | 1230 | posix.lseek_SET(r.file.handle, offset) catch |err| { |
| 1231 | 1231 | r.seek_err = err; |
| 1232 | 1232 | return err; |
| 1233 | 1233 | }; |
| 1234 | | setPosAdjustingBuffer(r, offset); |
| 1234 | setLogicalPos(r, offset); |
| 1235 | 1235 | }, |
| 1236 | 1236 | .failure => return r.seek_err.?, |
| 1237 | 1237 | } |
| ... | ... | @@ -1241,7 +1241,7 @@ pub const Reader = struct { |
| 1241 | 1241 | return r.pos - r.interface.bufferedLen(); |
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | | fn setPosAdjustingBuffer(r: *Reader, offset: u64) void { |
| 1244 | fn setLogicalPos(r: *Reader, offset: u64) void { |
| 1245 | 1245 | const logical_pos = logicalPos(r); |
| 1246 | 1246 | if (offset < logical_pos or offset >= r.pos) { |
| 1247 | 1247 | r.interface.seek = 0; |
| ... | ... | @@ -1804,7 +1804,7 @@ pub const Writer = struct { |
| 1804 | 1804 | return error.EndOfStream; |
| 1805 | 1805 | } |
| 1806 | 1806 | const consumed = io_w.consume(@intCast(sbytes)); |
| 1807 | | file_reader.seekTo(file_reader.pos + consumed) catch return error.ReadFailed; |
| 1807 | file_reader.seekBy(@intCast(consumed)) catch return error.ReadFailed; |
| 1808 | 1808 | return consumed; |
| 1809 | 1809 | } |
| 1810 | 1810 | |
| ... | ... | @@ -1865,7 +1865,7 @@ pub const Writer = struct { |
| 1865 | 1865 | return error.EndOfStream; |
| 1866 | 1866 | } |
| 1867 | 1867 | const consumed = io_w.consume(@bitCast(len)); |
| 1868 | | file_reader.seekTo(file_reader.pos + consumed) catch return error.ReadFailed; |
| 1868 | file_reader.seekBy(@intCast(consumed)) catch return error.ReadFailed; |
| 1869 | 1869 | return consumed; |
| 1870 | 1870 | } |
| 1871 | 1871 | |
| ... | ... | @@ -1998,7 +1998,7 @@ pub const Writer = struct { |
| 1998 | 1998 | reader_buffered: []const u8, |
| 1999 | 1999 | ) std.Io.Writer.FileError!usize { |
| 2000 | 2000 | const n = try drain(io_w, &.{reader_buffered}, 1); |
| 2001 | | file_reader.seekTo(file_reader.pos + n) catch return error.ReadFailed; |
| 2001 | file_reader.seekBy(@intCast(n)) catch return error.ReadFailed; |
| 2002 | 2002 | return n; |
| 2003 | 2003 | } |
| 2004 | 2004 | |