[−][src]Function snedfile::send_file
pub fn send_file(file: &mut File, stream: &mut TcpStream) -> Result<()>
Sends the entire contents of a file to a TCP stream.
The file must be opened for reading.
Depending on the backend, a more efficient method is used which prevents copying all data to userspace. See the module documentation for more.
This function is optimized in a way that it only needs to be called once on a file and stream.
Trivial errors are handled and the native sendfile()
is used as much as possible.
If the file has a length of 0
, this function returns successfully without doing additional work.
This function does not guarantee respecting the file offset, if it already has been changed by using Seek
or Read
.
Example
use snedfile::send_file; // somewhere in a server for static files fn serve_static(file: &mut File, stream: &mut TcpStream) -> io::Result<()> { send_file(file, stream) }