snedfile 0.1.0

Cross-platform sendfile() abstractions
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 2 items with examples
  • Size
  • Source code size: 33.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.41 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Draphar/snedfile
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Draphar

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)
}