pub use opendal_core as opendal;
pub use opendal_core::{Buffer, Error, ErrorKind, Metadata, Operator, Result};
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
pub use opendal_service_fs::{Fs, FsConfig};
#[cfg(feature = "s3")]
pub use opendal_service_s3::{S3, S3Config};
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
pub fn filesystem(root: &str) -> Result<Operator> {
Operator::new(Fs::default().root(root))
}
#[cfg(feature = "s3")]
pub fn s3(builder: S3) -> Result<Operator> {
s3_with_transport(
builder,
opendal::HttpTransporter::new(opendal_http_transport_reqwest::ReqwestTransport::default()),
)
}
#[cfg(feature = "s3")]
pub fn s3_with_transport(builder: S3, transport: opendal::HttpTransporter) -> Result<Operator> {
let context = opendal::OperationContext::new().with_http_transport(transport);
#[cfg(target_arch = "wasm32")]
let context = context.with_executor(opendal::Executor::with(WasmExecutor));
Ok(Operator::new(builder)?.with_context(context))
}
#[cfg(all(feature = "s3", target_arch = "wasm32"))]
#[derive(Debug)]
struct WasmExecutor;
#[cfg(all(feature = "s3", target_arch = "wasm32"))]
impl opendal::Execute for WasmExecutor {
fn execute(&self, task: opendal::raw::BoxedStaticFuture<()>) {
wasm_bindgen_futures::spawn_local(task);
}
}