Skip to content

Commit e667884

Browse files
committed
std.net.Stream.Reader: init size_err
This code knows in advance that stat() should never be called. closes #24754
1 parent e25168d commit e667884

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/std/fs/File.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,15 @@ pub const Reader = struct {
11221122
/// position, use `logicalPos`.
11231123
pos: u64 = 0,
11241124
size: ?u64 = null,
1125-
size_err: ?GetEndPosError = null,
1125+
size_err: ?SizeError = null,
11261126
seek_err: ?Reader.SeekError = null,
11271127
interface: std.Io.Reader,
11281128

1129+
pub const SizeError = std.os.windows.GetFileSizeError || StatError || error{
1130+
/// Occurs if, for example, the file handle is a network socket and therefore does not have a size.
1131+
Streaming,
1132+
};
1133+
11291134
pub const SeekError = File.SeekError || error{
11301135
/// Seeking fell back to reading, and reached the end before the requested seek position.
11311136
/// `pos` remains at the end of the file.

lib/std/net.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,7 @@ pub const Stream = struct {
20642064
.file = .{ .handle = net_stream.handle },
20652065
.mode = .streaming,
20662066
.seek_err = error.Unseekable,
2067+
.size_err = error.Streaming,
20672068
},
20682069
};
20692070
}

0 commit comments

Comments
 (0)