authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-10 17:38:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-10 17:38:46-07:00
loge667884f9ba21c7cdec7581d89b9a9f622c5ffb9
treed118f31cf814fe86838f950ecbbf629b67be0fc0
parente25168d01be35bea2c8e811fb5fddab847ae6938

std.net.Stream.Reader: init size_err

This code knows in advance that stat() should never be called. closes #24754

2 files changed, 7 insertions(+), 1 deletions(-)

lib/std/fs/File.zig+6-1
...@@ -1122,10 +1122,15 @@ pub const Reader = struct {...@@ -1122,10 +1122,15 @@ pub const Reader = struct {
1122 /// position, use `logicalPos`.1122 /// position, use `logicalPos`.
1123 pos: u64 = 0,1123 pos: u64 = 0,
1124 size: ?u64 = null,1124 size: ?u64 = null,
1125 size_err: ?GetEndPosError = null,1125 size_err: ?SizeError = null,
1126 seek_err: ?Reader.SeekError = null,1126 seek_err: ?Reader.SeekError = null,
1127 interface: std.Io.Reader,1127 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
1129 pub const SeekError = File.SeekError || error{1134 pub const SeekError = File.SeekError || error{
1130 /// Seeking fell back to reading, and reached the end before the requested seek position.1135 /// Seeking fell back to reading, and reached the end before the requested seek position.
1131 /// `pos` remains at the end of the file.1136 /// `pos` remains at the end of the file.
lib/std/net.zig+1
...@@ -2064,6 +2064,7 @@ pub const Stream = struct {...@@ -2064,6 +2064,7 @@ pub const Stream = struct {
2064 .file = .{ .handle = net_stream.handle },2064 .file = .{ .handle = net_stream.handle },
2065 .mode = .streaming,2065 .mode = .streaming,
2066 .seek_err = error.Unseekable,2066 .seek_err = error.Unseekable,
2067 .size_err = error.Streaming,
2067 },2068 },
2068 };2069 };
2069 }2070 }