Function sendFile [src]
Prototype
pub fn sendFile(w: *Writer, file_reader: *File.Reader, limit: Limit) FileError!usize
Parameters
w: *Writer
file_reader: *File.Reader
limit: Limit
Possible Errors
Reached the end of the file being read.
Detailed diagnostics are found on the File.Reader
struct.
Indicates the caller should do its own file reading; the callee cannot offer a more efficient implementation.
See the Writer
implementation for detailed diagnostics.
Source
pub fn sendFile(w: *Writer, file_reader: *File.Reader, limit: Limit) FileError!usize {
if (File.Handle == void) return error.Unimplemented;
switch (builtin.zig_backend) {
else => {},
.stage2_aarch64 => return error.Unimplemented,
}
const d: *Discarding = @alignCast(@fieldParentPtr("writer", w));
d.count += w.end;
w.end = 0;
if (limit == .nothing) return 0;
if (file_reader.getSize()) |size| {
const n = limit.minInt64(size - file_reader.pos);
if (n == 0) return error.EndOfStream;
file_reader.seekBy(@intCast(n)) catch return error.Unimplemented;
w.end = 0;
d.count += n;
return n;
} else |_| {
// Error is observable on `file_reader` instance, and it is better to
// treat the file as a pipe.
return error.Unimplemented;
}
}