1 unstable release

0.1.0 Sep 13, 2019

#10 in #send-file

Download history 6/week @ 2024-03-27 9/week @ 2024-04-03 5/week @ 2024-05-08 78/week @ 2024-05-15 1/week @ 2024-05-22 3/week @ 2024-05-29 88/week @ 2024-06-05 12/week @ 2024-06-12

100 downloads per month

MIT license

24KB
471 lines

snedfile - Rust cross-platform sendfile() abstractions

travis-badge appveyor-badge crates.io-badge docs-badge license-badge

Natively supported using sendfile() are Linux, Android, MacOS, iOS, FreeBSD and DragonFlyBSD, and every other std-platform using a fallback.

Usage

This library is designed to make transmitting files as easy as possible. If you have a file and a TCP stream, all you have to do is

use snedfile::send_file;

fn transmit(path: impl AsRef<Path>, stream: TcpStream) -> io::Result<()> {
    let file = File::open(path)?;

    send_file(&mut file, &mut stream)
}

Trivial errors as well as optimally using the native system capabilities are handled by the implementation.

Alternatively, there is a more low-level solution:

use snedfile::send_exact;

fn transmit(path: impl AsRef<Path>, stream: TcpStream) -> io::Result<()> {
    let file = File::open(path)?;

    send_exact(&mut file, &mut stream, file.metadata()?.len(), 0)
}

Dependencies

~43KB