| Crates.io | seekable-async-file |
| lib.rs | seekable-async-file |
| version | 0.12.0 |
| created_at | 2023-01-30 06:33:26.941185+00 |
| updated_at | 2023-07-13 10:33:04.917993+00 |
| description | Async pread and pwrite, with optional delayed sync and metrics |
| homepage | https://github.com/wilsonzlin/seekable-async-file |
| repository | https://github.com/wilsonzlin/seekable-async-file.git |
| max_upload_size | |
| id | 771496 |
| size | 20,023 |
This library will provide a SeekableAsyncFile struct that is designed to be similar in function to tokio::fs::File. It provides async read_at and write_at methods, which aren't currently available with Tokio.
Add it to your project like:
cargo add seekable-async-file
View the documentation for usage guides.
The write_at_with_delayed_sync method is provided to call write and fdatasync, but the sync call will be made at some future time. The returned future won't resolve until the sync call is made and completes successfully. This is a performance optimisation to try to batch multiple writes with a single sync, but still keep the semantics where the call completes only when successfully written to disk.
If this is used, make sure to also execute the start_delayed_data_sync_background_loop method in the background, such as using tokio::spawn or tokio::join!.
Metrics will be populated via the SeekableAsyncFileMetrics struct. All values are atomic, so it's possible to read them at any time from any thread safely using the provided getter methods. This is designed for use inside a larger system (e.g. database, object storage, cache) or I/O subsystem.
By default, a memory map is created on the file. This means that all platforms that support mmap can be targeted, instead of only Unix platforms with pread and pwrite.
Enabling the tokio_file feature will cause pread and pwrite on standard file descriptors to be used instead of mmap. Ensure to disable the mmap feature, which is enabled by default.
The target platform must support std::os::unix::fs::FileExt.
For experimental purposes, there are other Cargo features that can be toggled:
pread and pwrite.pread and pwrite with tokio::spawn_blocking.