pub struct MmapDiskWriter { /* private fields */ }Expand description
A disk writer that uses memory-mapped I/O for high-performance reads/writes.
Falls back to PositionedDiskWriter (positioned pwrite/seek_write)
when mmap cannot be created (e.g., zero-length file) or after truncate
is called (remapping after resize is not supported in v1).
§Example
use aria2_core::filesystem::mmap_disk_writer::MmapDiskWriter;
use aria2_core::filesystem::disk_writer::SeekableDiskWriter;
let mut writer = MmapDiskWriter::new(std::path::Path::new("output.bin"), Some(4096));
writer.open().await?;
writer.write_at(0, b"hello mmap").await?;
writer.flush().await?;Implementations§
Source§impl MmapDiskWriter
impl MmapDiskWriter
Sourcepub fn new(path: &Path, total_size: Option<u64>) -> Self
pub fn new(path: &Path, total_size: Option<u64>) -> Self
Create a new MmapDiskWriter 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 is
required for mmap since a zero-length file cannot be mapped.
Trait Implementations§
Source§impl SeekableDiskWriter for MmapDiskWriter
impl SeekableDiskWriter for MmapDiskWriter
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,
Write Bytes to the mmap region.
For the mmap variant, a memory copy is unavoidable — Bytes is an
Arc-backed buffer that cannot be “injected” into the mmap region.
For the fallback variant, this is zero-copy (pwrite takes &data).
Source§fn close<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn close<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Close the writer, releasing the file handle and memory mapping.
After close, the writer can be reopened with open().