Skip to main content

oxideav_source/
file.rs

1//! Built-in `file://` driver and bare-path fallback.
2
3use std::fs::File;
4
5use oxideav_container::ReadSeek;
6use oxideav_core::{Error, Result};
7
8use crate::uri;
9
10/// Open a local file as a `Box<dyn ReadSeek>`. Accepts:
11/// - bare paths: `/abs/path`, `rel/path`, `Cargo.toml`
12/// - `file:///abs/path`
13/// - `file:relative`
14pub fn open_file(uri_str: &str) -> Result<Box<dyn ReadSeek>> {
15    let (scheme, rest) = uri::split(uri_str);
16    if scheme != "file" {
17        return Err(Error::invalid(format!(
18            "file driver invoked on non-file URI: {uri_str}"
19        )));
20    }
21    let f = File::open(rest)?;
22    Ok(Box::new(f))
23}