| Crates.io | snedfile |
| lib.rs | snedfile |
| version | 0.1.0 |
| created_at | 2019-09-13 16:26:10.172296+00 |
| updated_at | 2019-09-13 16:26:10.172296+00 |
| description | Cross-platform sendfile() abstractions |
| homepage | |
| repository | https://github.com/Draphar/snedfile |
| max_upload_size | |
| id | 164608 |
| size | 30,108 |
Natively supported using sendfile() are Linux, Android, MacOS, iOS, FreeBSD and DragonFlyBSD,
and every other std-platform using a fallback.
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)
}