[][src]Function snedfile::send_exact

pub fn send_exact(
    file: &mut File,
    stream: &mut TcpStream,
    bytes: u64,
    offset: u64
) -> Result<u64>

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

The amount of bytes successfully sent is returned.

Implementation notes

If the offset is larger than the implementation can handle, an error of type ErrorKind::InvalidData is returned.

Exactly one system call is used, if available.

Regardless of the enabled features, the fallback of send_exact() always uses the bare io::copy().

The behaviour is not specified (but not undefined) if the offset goes beyond the end of the file.

No kinds of errors are handled.

Example

use snedfile::send_exact;

fn try_serve_static(mut file: File, mut stream: TcpStream) -> io::Result<u64> {
    let len = file.metadata()?.len();

    // the same as the example from `send_file`,
    // but with less automatic error handling
    send_exact(&mut file, &mut stream, len, 0)
}