feat(io-core): add truthful buffered io aliases (#4032)

This commit is contained in:
Zhengchao An
2026-06-29 10:01:59 +08:00
committed by GitHub
parent 1e6f20912a
commit 5fc25eccb3
4 changed files with 91 additions and 31 deletions
+15 -3
View File
@@ -82,7 +82,7 @@ impl From<io::Error> for DirectIoError {
/// # Platform Support
///
/// Only available on Linux (uses `FileExt::read_at`). On other platforms,
/// use `ZeroCopyObjectReader` with memory mapping instead.
/// use `BytesBufferedReader` instead.
///
/// # Alignment Requirements
///
@@ -94,11 +94,11 @@ impl From<io::Error> for DirectIoError {
/// # Example
///
/// ```ignore
/// use rustfs_io_core::DirectIoReader;
/// use rustfs_io_core::AlignedPreadReader;
///
/// // Linux only
/// #[cfg(target_os = "linux")]
/// let reader = DirectIoReader::new(file, offset, size)?;
/// let reader = AlignedPreadReader::new(file, offset, size)?;
/// ```
#[cfg(target_os = "linux")]
pub struct DirectIoReader {
@@ -263,6 +263,12 @@ impl std::fmt::Debug for DirectIoReader {
}
}
/// Preferred name for aligned pread errors.
pub type AlignedPreadError = DirectIoError;
/// Preferred name for the aligned pread-based reader.
pub type AlignedPreadReader = DirectIoReader;
#[cfg(test)]
mod tests {
use super::*;
@@ -275,6 +281,12 @@ mod tests {
let file = std::fs::File::open("/dev/zero").unwrap();
assert!(DirectIoReader::new(file, 0, 512).is_ok(), "Should succeed with aligned offset and size");
let file = std::fs::File::open("/dev/zero").expect("open /dev/zero for alias");
assert!(
AlignedPreadReader::new(file, 0, 512).is_ok(),
"Should succeed through aligned pread alias"
);
// Invalid offset
let file = std::fs::File::open("/dev/zero").unwrap();
assert!(DirectIoReader::new(file, 1, 512).is_err(), "Should fail with unaligned offset");