mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-08-03 03:13:05 -04:00
get rid of file variant in CachedData
This commit is contained in:
@@ -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);
|
||||
|
||||
7
src/network/cache/Cache.zig
vendored
7
src/network/cache/Cache.zig
vendored
@@ -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 }),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user