Zig 0.16: Update util.LineReader

Lazy, minimal changes
This commit is contained in:
LN Liberda 2026-05-22 19:26:04 +02:00
parent 44b4eeaf24
commit cb0aa4f03c

View file

@ -203,31 +203,11 @@ pub fn expanduser(path: []const u8, alloc: std.mem.Allocator) ![:0]u8 {
// Silly abstraction to read a file one line at a time. Only exists to help
// with supporting both Zig 0.14 and 0.15, can be removed once 0.14 support is
// dropped.
pub const LineReader = if (@hasDecl(std.io, "bufferedReader")) struct {
rd: std.io.BufferedReader(4096, std.fs.File.Reader),
fbs: std.io.FixedBufferStream([]u8),
pub const LineReader = struct {
rd: std.Io.File.Reader,
pub fn init(f: std.fs.File, buf: []u8) @This() {
return .{
.rd = std.io.bufferedReader(f.reader()),
.fbs = std.io.fixedBufferStream(buf),
};
}
pub fn read(s: *@This()) !?[]u8 {
s.fbs.reset();
s.rd.reader().streamUntilDelimiter(s.fbs.writer(), '\n', s.fbs.buffer.len) catch |err| switch (err) {
error.EndOfStream => if (s.fbs.getPos() catch unreachable == 0) return null,
else => |e| return e,
};
return s.fbs.getWritten();
}
} else struct {
rd: std.fs.File.Reader,
pub fn init(f: std.fs.File, buf: []u8) @This() {
return .{ .rd = f.readerStreaming(buf) };
pub fn init(io: std.Io, f: std.Io.File, buf: []u8) @This() {
return .{ .rd = f.readerStreaming(io, buf) };
}
pub fn read(s: *@This()) !?[]u8 {