pub struct FileSource { /* private fields */ }sync and unstable-streaming and write only.Expand description
File contents that are read from a reader while the image is written.
An InputEntryKind::File holds its contents in memory. A FileSource holds
only the length and a way to open a reader, so a large file is streamed into the
image in fixed-size chunks and never has to fit in memory. The writer opens the
reader once per file, in image order, and reads exactly len bytes from it: a
reader that ends early fails the write with ErrorKind::UnexpectedEof, and
bytes beyond len are never read.
The reader is a blocking std::io::Read in both the sync and the async writer;
the async writer awaits only its output.
Requires the unstable-streaming feature, which is outside the V2 API
stability promise: this type and InputEntryKind::Source may change in any
release.
Implementations§
Source§impl FileSource
impl FileSource
Sourcepub fn new<F>(len: u64, open: F) -> Self
pub fn new<F>(len: u64, open: F) -> Self
A source of len bytes that open produces a reader for.
Sourcepub fn from_path(path: impl Into<PathBuf>) -> Result<Self>
pub fn from_path(path: impl Into<PathBuf>) -> Result<Self>
A source that streams the file at path, whose length is taken now.
The file is opened when the image is written; its length must not change in between.
use hadris_iso::write::FileSource;
let path = std::env::temp_dir().join("hadris-iso-file-source-doc.bin");
std::fs::write(&path, b"streamed")?;
let source = FileSource::from_path(&path)?;
assert_eq!(source.len(), 8);
let mut contents = Vec::new();
source.open()?.read_to_end(&mut contents)?;
assert_eq!(contents, b"streamed");