mod path;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
mod handle;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
mod lock;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
mod protocol;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
mod vfs_impl;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
pub use handle::OpfsFile;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
pub use lock::OpfsLockHandle;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
pub use vfs_impl::OpfsVfs;
#[cfg(all(target_arch = "wasm32", feature = "opfs"))]
pub const OPFS_WORKER_JS: &str = include_str!("opfs_worker.js");
#[cfg(not(all(target_arch = "wasm32", feature = "opfs")))]
pub use shim::OpfsVfs;
#[cfg(not(all(target_arch = "wasm32", feature = "opfs")))]
mod shim {
use crate::Result;
use crate::errors::PagedbError;
use crate::vfs::traits::{Vfs, VfsFile};
use crate::vfs::types::{OpenMode, ReadReq, WriteReq};
pub struct OpfsVfs {
_private: (),
}
impl OpfsVfs {
pub fn new(_worker_url: &str) -> Result<Self> {
Err(PagedbError::Unsupported)
}
pub fn with_root(_worker_url: &str, _root: &str) -> Result<Self> {
Err(PagedbError::Unsupported)
}
}
pub struct OpfsFileShim;
impl VfsFile for OpfsFileShim {
async fn read_at(&self, _offset: u64, _buf: &mut [u8]) -> Result<usize> {
Err(PagedbError::Unsupported)
}
async fn read_at_vectored(&self, _reqs: &mut [ReadReq<'_>]) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn write_at(&mut self, _offset: u64, _buf: &[u8]) -> Result<usize> {
Err(PagedbError::Unsupported)
}
async fn write_at_vectored(&mut self, _reqs: &[WriteReq<'_>]) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn sync(&mut self) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn truncate(&mut self, _len: u64) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn len(&self) -> Result<u64> {
Err(PagedbError::Unsupported)
}
async fn is_empty(&self) -> Result<bool> {
Err(PagedbError::Unsupported)
}
fn supports_direct_io(&self) -> bool {
false
}
}
pub struct OpfsLockHandleShim(());
impl Vfs for OpfsVfs {
type File = OpfsFileShim;
type LockHandle = OpfsLockHandleShim;
async fn open(&self, _path: &str, _mode: OpenMode) -> Result<Self::File> {
Err(PagedbError::Unsupported)
}
async fn remove(&self, _path: &str) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn rename(&self, _from: &str, _to: &str) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn list_dir(&self, _path: &str) -> Result<Vec<String>> {
Err(PagedbError::Unsupported)
}
async fn mkdir_all(&self, _path: &str) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn sync_dir(&self, _path: &str) -> Result<()> {
Err(PagedbError::Unsupported)
}
async fn lock_exclusive(&self, _path: &str) -> Result<Self::LockHandle> {
Err(PagedbError::Unsupported)
}
async fn lock_shared(&self, _path: &str) -> Result<Self::LockHandle> {
Err(PagedbError::Unsupported)
}
}
}