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