pub struct FileWriter<'a, DATA: Read + Write + Seek> { /* private fields */ }Expand description
A writer for file content in a FAT filesystem.
Implementations§
Source§impl<'a, DATA: Read + Write + Seek> FileWriter<'a, DATA>
impl<'a, DATA: Read + Write + Seek> FileWriter<'a, DATA>
Sourcepub fn new(fs: &'a FatVolume<DATA>, entry: &FileEntry) -> Result<Self>
pub fn new(fs: &'a FatVolume<DATA>, entry: &FileEntry) -> Result<Self>
Create a new FileWriter for a file entry.
The entry must be a file (not a directory).
Sourcepub fn new_append(fs: &'a FatVolume<DATA>, entry: &FileEntry) -> Result<Self>
pub fn new_append(fs: &'a FatVolume<DATA>, entry: &FileEntry) -> Result<Self>
Create a FileWriter positioned at the end of the file for appending.
Walks the FAT chain to find the last cluster and positions the
writer at the file’s current end. Subsequent writes append data
and finish() updates the size to include both existing and new data.
Sourcepub fn write(&mut self, buf: &[u8]) -> Result<usize>
pub fn write(&mut self, buf: &[u8]) -> Result<usize>
Write data to the file.
Allocates new clusters as needed.
Sourcepub fn bytes_written(&self) -> usize
pub fn bytes_written(&self) -> usize
Get the total number of bytes written.
Sourcepub fn set_modified(&mut self, dt: FatDateTime) -> &mut Self
pub fn set_modified(&mut self, dt: FatDateTime) -> &mut Self
Override the modified timestamp written by finish.
Without this call, finish() stamps “now” via the configured
TimeProvider. Useful for preserving the
original mtime when copying files between volumes, or for
reproducible-image builds.
Sourcepub fn set_accessed(&mut self, date: u16) -> &mut Self
pub fn set_accessed(&mut self, date: u16) -> &mut Self
Override the access date written by finish.
FAT does not store an access time — only a date. Pass the raw
FAT-encoded date (year-1980)<<9 | month<<5 | day.
Sourcepub fn set_created(&mut self, dt: FatDateTime) -> &mut Self
pub fn set_created(&mut self, dt: FatDateTime) -> &mut Self
Override the creation timestamp written by finish.
Most filesystems write creation time only at file-create. This setter lets writers retroactively patch it, useful when re-imaging or migrating data with timestamps from another source.
Sourcepub fn finish(self) -> Result<()>
pub fn finish(self) -> Result<()>
Finish writing and update the directory entry with the new size.
This must be called after writing to persist the file size. On FAT32 it
also flushes the FSInfo sector so its free_count matches the FAT —
without this, fsck.fat rejects the image after writes.
With the dirty-file-panic feature enabled, dropping the writer
without calling finish panics — the most common cause of “the file
I just wrote shows up as zero bytes” bugs.