Function copyRangeAll [src]

Returns the number of bytes copied. If the number read is smaller than buffer.len, it means the in file reached the end. Reaching the end of a file is not an error condition.

Prototype

pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64

Parameters

in: Filein_offset: u64out: Fileout_offset: u64len: u64

Possible Errors

AccessDenied ReadError

In WASI, this error occurs when the file descriptor does not hold the required rights to read from it.

BrokenPipe ReadError
Canceled ReadError

reading a timerfd with CANCEL_ON_SET will lead to this error when the clock goes through a discontinuous change

ConnectionResetByPeer WriteError

Connection reset by peer.

ConnectionTimedOut ReadError
CorruptedData CopyFileRangeError
DeviceBusy WriteError
DiskQuota WriteError
FileTooBig CopyFileRangeError
FilesOpenedWithWrongFlags CopyFileRangeError

fd_in is not open for reading; or fd_out is not open for writing; or the APPEND flag is set for fd_out.

InputOutput CopyFileRangeError
InvalidArgument WriteError
IsDir CopyFileRangeError
LockViolation ReadError

Unable to read file due to lock.

MessageTooBig WriteError

The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible. The message is not transmitted.

NoDevice WriteError

This error occurs when a device gets disconnected before or mid-flush while it's being written to - errno(6): No such device or address.

NoSpaceLeft CopyFileRangeError
NotOpenForReading ReadError
NotOpenForWriting WriteError
OperationAborted ReadError
OutOfMemory CopyFileRangeError
PermissionDenied CopyFileRangeError
ProcessNotFound ReadError

This error occurs in Linux if the process to be read from no longer exists.

SocketNotConnected ReadError
SwapFile CopyFileRangeError
SystemResources ReadError
Unexpected UnexpectedError

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.

Unseekable CopyFileRangeError
WouldBlock ReadError

This error occurs when no global event loop is configured, and reading from the file descriptor would block.

Source

pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { var total_bytes_copied: u64 = 0; var in_off = in_offset; var out_off = out_offset; while (total_bytes_copied < len) { const amt_copied = try copyRange(in, in_off, out, out_off, len - total_bytes_copied); if (amt_copied == 0) return total_bytes_copied; total_bytes_copied += amt_copied; in_off += amt_copied; out_off += amt_copied; } return total_bytes_copied; }