1pub use opendal_core as opendal;
8pub use opendal_core::{Buffer, Error, ErrorKind, Metadata, Operator, Result};
9
10#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
11pub use opendal_service_fs::{Fs, FsConfig};
12#[cfg(feature = "s3")]
13pub use opendal_service_s3::{S3, S3Config};
14
15#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
17pub fn filesystem(root: &str) -> Result<Operator> {
18 Operator::new(Fs::default().root(root))
19}
20
21#[cfg(feature = "s3")]
24pub fn s3(builder: S3) -> Result<Operator> {
25 s3_with_transport(
26 builder,
27 opendal::HttpTransporter::new(opendal_http_transport_reqwest::ReqwestTransport::default()),
28 )
29}
30
31#[cfg(feature = "s3")]
34pub fn s3_with_transport(builder: S3, transport: opendal::HttpTransporter) -> Result<Operator> {
35 let context = opendal::OperationContext::new().with_http_transport(transport);
36 #[cfg(target_arch = "wasm32")]
37 let context = context.with_executor(opendal::Executor::with(WasmExecutor));
38 Ok(Operator::new(builder)?.with_context(context))
39}
40
41#[cfg(all(feature = "s3", target_arch = "wasm32"))]
44#[derive(Debug)]
45struct WasmExecutor;
46
47#[cfg(all(feature = "s3", target_arch = "wasm32"))]
48impl opendal::Execute for WasmExecutor {
49 fn execute(&self, task: opendal::raw::BoxedStaticFuture<()>) {
50 wasm_bindgen_futures::spawn_local(task);
51 }
52}