Function getSize [src]
Prototype
pub fn getSize(r: *Reader) SizeError!u64 Parameters
r: *Reader Possible Errors
In WASI, this error may occur when the file descriptor does not hold the required rights to get its filestat information.
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.
Source
pub fn getSize(r: *Reader) SizeError!u64 {
return r.size orelse {
if (r.size_err) |err| return err;
if (is_windows) {
if (windows.GetFileSizeEx(r.file.handle)) |size| {
r.size = size;
return size;
} else |err| {
r.size_err = err;
return err;
}
}
if (posix.Stat == void) {
r.size_err = error.Streaming;
return error.Streaming;
}
if (stat(r.file)) |st| {
if (st.kind == .file) {
r.size = st.size;
return st.size;
} else {
r.mode = r.mode.toStreaming();
r.size_err = error.Streaming;
return error.Streaming;
}
} else |err| {
r.size_err = err;
return err;
}
};
}