pub enum FileSource {
Path(PathBuf),
SeekableStream {
reader: Box<dyn SeekableReader>,
len: u64,
},
Stream(Box<dyn AsyncRead + Send + Unpin>),
}Expand description
Where a file response’s bytes come from.
This mirrors the sources ASP.NET Core accepts for File(...):
a physical path, a stream, or an in-memory buffer. Pick the one you already
have — none of them require materialising the content first.
Variants§
Path(PathBuf)
A file on disk.
Streamed in 64 KiB chunks; the host opens it once and reads length and validators from the same handle.
SeekableStream
An async reader whose length is known and which can seek, so Range
requests can be served.
Use this for object-storage handles, database LOB readers, archive entries — anything that can jump to a byte offset.
Fields
reader: Box<dyn SeekableReader>The reader. Consumed when the response is sent.
Stream(Box<dyn AsyncRead + Send + Unpin>)
An async reader of unknown length.
Sent with chunked transfer encoding and no Content-Length; Range
requests receive the full body. Use this for pipes, live producers and
compressed/encrypted streams where the final size is not known up front.