use crate::op::file::read::read_op::{ReadOp, ReadOpInner};
#[cfg(feature = "r2")]
use crate::R2Path;
use crate::{Error, FilePath, LocalPath, Operation, Reason};
impl FilePath {
pub fn read(&self) -> Result<ReadOp, Error> {
if let Some(read) = self.read_if_exists()? {
Ok(read)
} else {
Err(Error::new(
self.clone(),
Operation::Read,
Reason::FileNotFound,
))
}
}
pub fn read_if_exists(&self) -> Result<Option<ReadOp>, Error> {
if let Some(path) = LocalPath::new(self.path()) {
return path.read_if_exists().map(|op| {
op.map(|op| ReadOp {
inner: ReadOpInner::Local(op),
})
});
}
#[cfg(feature = "r2")]
if let Some(path) = R2Path::new(self.path()) {
return path.read_if_exists().map(|op| {
op.map(|op| ReadOp {
inner: ReadOpInner::R2(op),
})
});
}
Err(Error::new(
self.clone(),
Operation::Read,
Reason::UnknownFileSystem,
))
}
}