[][src]Crate snedfile

Cross-platform abstractions for the sendfile() system call. Natively supported are Linux, android, MacOS, iOS, FreeBSD and DragonFlyBSD, and every other std-platform using a fallback.


All native implementation support a maximum file length of off_t::max_value().

All implementations handle WouldBlock and Interrupted errors.

Linux and android

The sendfile(2) system call is used.

The file length is required and the functions fails if file.metadata() fails.

MacOS and optionally iOS

The sendfile(2) system call is used.

The file length is only required after the maximum file length has been sent. Note that there are sparse reports of sendfile() being buggy on iOS, so if you prefer to use the fallback for target_os = "ios", disable the ios-sendfile feature which is enabled by default.

FreeBSD and DragonFlyBSD

The sendfile(2) system call is used.

The file length is not required.


There are two features to change the fallback behavior:

The fallback-bufreader feature is enabled by default. It sends the file using io::copy() after wrapping it in a BufReader. Interrupted errors are handled by the implementation.

If the fallback-buf feature is enabled, the entire contents of the file are loaded into a Vec first, which is then written to the stream at once. Only the first usize::max_value() may be transmitted.

If both features are disabled the file is transmitted by repeatedly using bare io::copy() until all bytes have been sent.

Large files

If you expected to send files larger than 2 gigabytes from a 32-bit system or files larger than 8192 petabytes from a 64-bit system, enable the large-files feature which supports all file sizes up to u64::max_value(), and if the files become to large for the native solutions a fallback is used.



Send a specific amount of bytes from a specific offset within a file.


Sends the entire contents of a file to a TCP stream.