Zig 0.16: File is not a File.Reader

This commit is contained in:
LN Liberda 2026-05-23 00:19:52 +02:00
parent 9344dee1aa
commit ffa44be7a4

View file

@ -37,11 +37,11 @@ const ZstdReader = struct {
main.allocator.destroy(r);
}
fn read(r: *ZstdReader, f: std.Io.File, out: []u8) !usize {
fn read(r: *ZstdReader, f: *std.Io.File.Reader, out: []u8) !usize {
while (true) {
if (r.in.size == r.in.pos) {
r.in.pos = 0;
r.in.size = try f.read(&r.inbuf);
r.in.size = try f.interface.readSliceShort(&r.inbuf);
if (r.in.size == 0) {
if (r.lastret == 0) return 0;
return error.ZstdDecompressError; // Early EOF
@ -63,7 +63,7 @@ const ZstdReader = struct {
// strings.
const Parser = struct {
rd: std.Io.File,
rd: std.Io.File.Reader,
zstd: ?*ZstdReader = null,
rdoff: usize = 0,
rdsize: usize = 0,
@ -84,9 +84,7 @@ const Parser = struct {
fn fill(p: *Parser) void {
p.rdoff = 0;
p.rdsize = (if (p.zstd) |z| z.read(p.rd, &p.buf) else p.rd.read(&p.buf)) catch |e| switch (e) {
error.IsDir => p.die("not a file"), // should be detected at open() time, but no flag for that...
error.SystemResources => p.die("out of memory"),
p.rdsize = (if (p.zstd) |z| z.read(&p.rd, &p.buf) else p.rd.interface.readSliceShort(&p.buf)) catch |e| switch (e) {
error.ZstdDecompressError => p.die("decompression error"),
else => p.die("I/O error"),
};
@ -532,7 +530,8 @@ pub fn import(fd: std.Io.File, head: []const u8) void {
const sink_threads = sink.createThreads(1);
defer sink.done();
var p = Parser{.rd = fd};
var rbuf: [1024]u8 = undefined;
var p = Parser{.rd = fd.reader(main.io, &rbuf)};
defer if (p.zstd) |z| z.destroy();
if (head.len >= 4 and std.mem.eql(u8, head[0..4], "\x28\xb5\x2f\xfd")) {