Crates.io | zio-sendfile |
lib.rs | zio-sendfile |
version | 0.2.0 |
source | src |
created_at | 2019-01-05 20:53:57.109637 |
updated_at | 2019-01-18 15:05:30.078989 |
description | zero-copy I/O for Linux, supporting stable rustc versions |
homepage | |
repository | https://github.com/pop-os/zio-sendfile |
max_upload_size | |
id | 105729 |
size | 7,889 |
Rust crate to provide a higher level abstraction over Linux's zero-copy I/O syscall:
sendfile. This provides a significantly
faster variant of io::copy(&mut source, &mut dest)
, which only works on Linux -- the platform of
choice for the discerning programmer.
If you're simply copying a file to a different file descriptor, the copy function can be used:
extern crate zio_sendfile;
let mut source = File::open("source_path").unwrap();
let mut dest = File::create("dest_path").unwrap();
let bytes_per_write = 100 * 1024 * 1024;
zio_sendfile::copy(&mut source, &mut dest, bytes_per_write);
Note that the source and destination does not need to be a File
, but can be any type which implements AsRawFd
.
If you need a more elaborate configuration, the builder pattern is possible using the SendFile
type:
extern crate zio_sendfile;
let mut source = File::open("source_path").unwrap();
SendFile::new(&mut source, 100 * 1024 * 1024)
.offset(bytes_to_offset)
.send(&mut File::create("dest_path").unwrap()).unwrap();
Each write will update the offset integer stored within the SendFile
, so it can be
used to track the progress of a copy.