| ... | ... | @@ -58,3 +58,14 @@ pub fn writeStruct(self: Self, value: anytype) anyerror!void { |
| 58 | 58 | comptime assert(@typeInfo(@TypeOf(value)).Struct.layout != .Auto); |
| 59 | 59 | return self.writeAll(mem.asBytes(&value)); |
| 60 | 60 | } |
| 61 | |
| 62 | pub fn writeFile(self: Self, file: std.fs.File) anyerror!void { |
| 63 | // TODO: figure out how to adjust std lib abstractions so that this ends up |
| 64 | // doing sendfile or maybe even copy_file_range under the right conditions. |
| 65 | var buf: [4000]u8 = undefined; |
| 66 | while (true) { |
| 67 | const n = try file.readAll(&buf); |
| 68 | try self.writeAll(buf[0..n]); |
| 69 | if (n < buf.len) return; |
| 70 | } |
| 71 | } |