pub struct PositionedDiskWriter { /* private fields */ }Expand description
A disk writer that performs positioned (offset-based) I/O via OS-native
pwrite/seek_write syscalls.
The file descriptor is protected by a std::sync::Mutex held only for
the duration of each synchronous syscall — never across .await points.
This enables true concurrency for non-overlapping writes when multiple
writers reference the same file.
Uses std::fs::File (not tokio::fs::File) because FileExt::write_at
is a synchronous method available only on std::fs::File. Since pwrite
is a fast non-blocking syscall (it never waits on async I/O completion),
running it synchronously inside a tokio task is acceptable — it does not
stall the runtime for meaningful durations.
Implementations§
Source§impl PositionedDiskWriter
impl PositionedDiskWriter
Sourcepub fn new(path: &Path, total_size: Option<u64>) -> Self
pub fn new(path: &Path, total_size: Option<u64>) -> Self
Create a new PositionedDiskWriter for the given path.
If total_size is provided and the file is newly created (size 0), the
file is pre-allocated to total_size bytes on first open. This avoids
fragmentation and enables concurrent writes to arbitrary offsets
without per-write file extension.
Sourcepub fn total_size(&self) -> Option<u64>
pub fn total_size(&self) -> Option<u64>
Returns the configured total size, if any.
Sourcepub fn raw_fd(&self) -> Option<RawFd>
pub fn raw_fd(&self) -> Option<RawFd>
Returns the raw file descriptor of the underlying file, if open.
This is used by the Linux splice download path to obtain the file fd
for splice(2) zero-copy transfer. Returns None if the file has not
been opened yet (caller should call open() first).
The caller must ensure the writer is not dropped or closed while the returned fd is in use. The fd is valid only while the writer holds the file open.
Trait Implementations§
Source§impl SeekableDiskWriter for PositionedDiskWriter
impl SeekableDiskWriter for PositionedDiskWriter
Source§fn write_bytes_at<'life0, 'async_trait>(
&'life0 mut self,
offset: u64,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write_bytes_at<'life0, 'async_trait>(
&'life0 mut self,
offset: u64,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Zero-copy write: accepts Bytes directly. Since pwrite takes &[u8],
we simply dereference the Bytes (no copy — Bytes derefs to [u8]).