Skip to main content

FileWriter

Struct FileWriter 

Source
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>

Source

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).

Source

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.

Source

pub fn write(&mut self, buf: &[u8]) -> Result<usize>

Write data to the file.

Allocates new clusters as needed.

Source

pub fn bytes_written(&self) -> usize

Get the total number of bytes written.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a, DATA: Read + Write + Seek> Drop for FileWriter<'a, DATA>

Available on crate feature write only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a, DATA> !RefUnwindSafe for FileWriter<'a, DATA>

§

impl<'a, DATA> !Send for FileWriter<'a, DATA>

§

impl<'a, DATA> !Sync for FileWriter<'a, DATA>

§

impl<'a, DATA> !UnwindSafe for FileWriter<'a, DATA>

§

impl<'a, DATA> Freeze for FileWriter<'a, DATA>

§

impl<'a, DATA> Unpin for FileWriter<'a, DATA>

§

impl<'a, DATA> UnsafeUnpin for FileWriter<'a, DATA>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybePod for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.