Function writeFile [src]
Prototype
pub fn writeFile( w: *Writer, sub_path: []const u8, file_reader: *std.fs.File.Reader, stat_mtime: i128, ) WriteFileError!void Parameters
w: *Writersub_path: []const u8file_reader: *std.fs.File.Readerstat_mtime: i128 Possible Errors
In WASI, this error may occur when the file descriptor does not hold the required rights to get its filestat information.
Reached the end of the file being read.
Detailed diagnostics are found on the File.Reader struct.
Occurs if, for example, the file handle is a network socket and therefore does not have a size.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
Indicates the caller should do its own file reading; the callee cannot offer a more efficient implementation.
Source
pub fn writeFile(
w: *Writer,
sub_path: []const u8,
file_reader: *std.fs.File.Reader,
stat_mtime: i128,
) WriteFileError!void {
const size = try file_reader.getSize();
const mtime: u64 = @intCast(@divFloor(stat_mtime, std.time.ns_per_s));
var header: Header = .{};
try w.setPath(&header, sub_path);
try header.setSize(size);
try header.setMtime(mtime);
try header.updateChecksum();
try w.underlying_writer.writeAll(@ptrCast((&header)[0..1]));
_ = try w.underlying_writer.sendFileAll(file_reader, .unlimited);
try w.writePadding64(size);
}