get rid of file variant in CachedData

This commit is contained in:
Muki Kiboigo
2026-07-21 07:58:00 -07:00
parent d0d33871d6
commit 8082f2d701
2 changed files with 0 additions and 15 deletions

View File

@@ -2387,16 +2387,8 @@ pub const Transfer = struct {
// Serve a cache entry as this transfer's response. Takes ownership of
// `cached` (file-backed bodies are read into the arena and closed).
fn bufferCached(self: *Transfer, cached: Cache.CachedResponse) !void {
const arena = self.arena;
const body: []const u8 = switch (cached.data) {
.buffer => |b| b,
.file => |f| blk: {
defer f.file.close(lp.io);
const buf = try arena.alloc(u8, f.len);
const n = try f.file.readPositionalAll(lp.io, buf, f.offset);
break :blk buf[0..n];
},
};
self.setResponseHead(cached.metadata.status, cached.metadata.content_type);

View File

@@ -219,23 +219,16 @@ pub const RenewResponse = struct {
pub const CachedData = union(enum) {
buffer: []const u8,
file: struct {
file: std.Io.File,
offset: usize,
len: usize,
},
pub fn deinit(self: CachedData) void {
switch (self) {
.buffer => {},
.file => |*f| f.file.close(lp.io),
}
}
pub fn format(self: CachedData, writer: *std.Io.Writer) !void {
switch (self) {
.buffer => |buf| try writer.print("buffer({d} bytes)", .{buf.len}),
.file => |f| try writer.print("file(offset={d}, len={d} bytes)", .{ f.offset, f.len }),
}
}
};