Simple Object Storage
Dependencies
@sos the interface, the types, the path rules all targets
@sos/memory a Map all targets
@sos/fs a real directory tree native
@sos/idbcore the IndexedDB semantics, over a `Conn` all targets
@sos/indexeddb IndexedDB, reached by Promise js
@sos/idbwasm IndexedDB, reached by token and export wasm-gc *
@sos/testing one conformance suite, run by all of them all targetslet op = @sos.Operator::new(@memory.MemoryStore::new())
op.write("notes/march.md", b"# March")
op.read("notes/march.md") // Bytes
op.read("notes/march.md", range=@sos.Range::prefix(7L))
op.list("notes/", recursive=true) // Array[Entry]
op.delete("notes/", recursive=true)| memory | fs | both IndexedDB | |
|---|---|---|---|
| ranged reads | yes | yes | yes |
| append | yes | yes | no — two transactions would race |
| content type | yes | no — nowhere to keep one | yes |
| shared between processes | no | yes | yes |
// A store that never suspends, on any target, with no scheduler:
@testing.run_sync(@memory.MemoryStore::new())
// A store that does, under moonbitlang/async:
@testing.run(store)moon test --target nativemoon test --target wasm-gc -p marianoguerra/sos \
-p marianoguerra/sos/memory -p marianoguerra/sos/idbcoremoon check --target allmoon build --target js --release indexeddb/harness
python3 -m http.server 8731moon build --target wasm-gc --release idbwasm/harnessmoon run cmd/main --target nativepub(open) trait Store {
fn info(Self) -> StoreInfo
async fn read(Self, String, ReadOptions) -> Bytes raise SosError
async fn write(Self, String, Bytes, WriteOptions) -> Unit raise SosError
async fn stat(Self, String) -> Metadata raise SosError
async fn list(Self, String, ListOptions) -> Array[Entry] raise SosError
async fn delete(Self, String, DeleteOptions) -> Unit raise SosError
async fn create_dir(Self, String) -> Unit raise SosError
async fn copy(Self, String, String) -> Unit raise SosError = _
async fn rename(Self, String, String) -> Unit raise SosError = _
}pub(all) suberror SosError {
SosError(kind~ : ErrorKind, operation~ : String, path~ : String, message~ : String)
}pub(all) struct Capability {
read : Bool
read_with_range : Bool
write : Bool
write_can_append : Bool
write_with_content_type : Bool
write_with_if_not_exists : Bool
stat : Bool
list : Bool
list_with_recursive : Bool
list_with_limit : Bool
list_with_start_after : Bool
delete : Bool
delete_with_recursive : Bool
create_dir : Bool
copy : Bool
rename : Bool
shared : Bool
} derive(Eq, Debug)type Operatorpub(all) struct StoreInfo {
scheme : String
root : String
name : String
capability : Capability
} derive(Eq, Debug)fn basename(path : String) -> Stringfn depth(path : String) -> Intfn ensure_dir_path(path : String) -> Stringfn is_dir_path(path : String) -> Boolfn join(base : String, child : String) -> Stringfn normalize(path : String) -> Stringfn parent(path : String) -> Stringfn path_compare(a : String, b : String) -> Intfn path_lt(a : String, b : String) -> Boolfn strip_dir_path(path : String) -> StringInstall
Download zipSimple Object Storage
Dependencies