authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 16:40:41-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 19:58:56-08:00
log28810f5e3d41597116773b2eb6686f3d8e272b36
tree87c1a297912197f9dc4937d432f2290697f5db2c
parentf160d5f979c9f2bcc98ef0169a879a76d0234ed2

std.Io.File: add readStreaming

I resisted adding this because it's generally better to create a File.Reader instead, but we do need a simple wrapper around the vtable function, and there are use cases for it such as std.Progress.

1 files changed, 8 insertions(+), 0 deletions(-)

lib/std/Io/File.zig+8
...@@ -499,6 +499,14 @@ pub fn setTimestampsNow(file: File, io: Io) SetTimestampsError!void {...@@ -499,6 +499,14 @@ pub fn setTimestampsNow(file: File, io: Io) SetTimestampsError!void {
499 return io.vtable.fileSetTimestampsNow(io.userdata, file);499 return io.vtable.fileSetTimestampsNow(io.userdata, file);
500}500}
501501
502/// Returns 0 on stream end or if `buffer` has no space available for data.
503///
504/// See also:
505/// * `reader`
506pub fn readStreaming(file: File, io: Io, buffer: []const []u8) Reader.Error!usize {
507 return io.vtable.fileReadStreaming(io.userdata, file, buffer);
508}
509
502pub const ReadPositionalError = Reader.Error || error{Unseekable};510pub const ReadPositionalError = Reader.Error || error{Unseekable};
503511
504/// Returns 0 on stream end or if `buffer` has no space available for data.512/// Returns 0 on stream end or if `buffer` has no space available for data.