MoonBit bindings for Apache OpenDAL
| Track | Services and API | Native hosts |
|---|---|---|
| Current Eric-Song-Nop/opendal@0.2.0 | standard profile: memory, fs, typed s3, complete Phase 5A-E API, and Browser JS | Apple silicon macOS 11+, x86-64 and arm64 glibc Linux 2.35+ |
| Legacy Eric-Song-Nop/opendal@0.1.0 | local profile: memory, fs, synchronous Phase 1-4 API | Apple silicon macOS 11+, x86-64 glibc Linux 2.35+ |
moon add Eric-Song-Nop/opendal@0.2.0moon add Eric-Song-Nop/opendal@0.1.0supported_targets = "+native+js"
import {
"Eric-Song-Nop/opendal",
}make moon-deps
make test-profile NATIVE_SERVICE_PROFILE=standardmoon run --target js --release src/browser_demosupported_targets = "js"
import {
"Eric-Song-Nop/opendal",
"moonbitlang/async",
}///|
async fn browser_round_trip() {
let storage = @opendal.AsyncOperator::new("memory")
defer storage.close()
storage.write("hello.txt", b"hello from Chrome") |> ignore
assert_eq(storage.read("hello.txt"), b"hello from Chrome")
}///|
#cfg(target="native")
test "README: memory round trip" {
let operator = @opendal.Operator::new("memory")
operator.write("hello.txt", b"hello from MoonBit") |> ignore
assert_eq(operator.read("hello.txt"), b"hello from MoonBit")
}///|
#cfg(target="native")
test "README: typed storage error" {
let operator = @opendal.Operator::new("memory")
try operator.read("missing.txt") catch {
error => {
assert_true(error.kind() is NotFound)
assert_true(error.info().operation is Read)
assert_eq(error.info().path, Some("missing.txt"))
}
} noraise {
_ => fail("expected a missing-object error")
}
}///|
async test "README: async memory round trip" {
let async_operator = @opendal.AsyncOperator::new("memory")
defer async_operator.close()
async_operator.write("whole.txt", b"whole object") |> ignore
assert_eq(async_operator.read("whole.txt"), b"whole object")
let writer = async_operator.open_writer("async.txt")
writer.write(b"hello ")
writer.write(b"asynchronously")
writer.finish() |> ignore
assert_eq(async_operator.read("async.txt"), b"hello asynchronously")
}| Track | Services and API | Native hosts |
|---|---|---|
| Current Eric-Song-Nop/opendal@0.2.0 | standard profile: memory, fs, typed s3, complete Phase 5A-E API, and Browser JS | Apple silicon macOS 11+, x86-64 and arm64 glibc Linux 2.35+ |
| Legacy Eric-Song-Nop/opendal@0.1.0 | local profile: memory, fs, synchronous Phase 1-4 API | Apple silicon macOS 11+, x86-64 glibc Linux 2.35+ |
moon add Eric-Song-Nop/opendal@0.2.0moon add Eric-Song-Nop/opendal@0.1.0supported_targets = "+native+js"
import {
"Eric-Song-Nop/opendal",
}make moon-deps
make test-profile NATIVE_SERVICE_PROFILE=standardmoon run --target js --release src/browser_demosupported_targets = "js"
import {
"Eric-Song-Nop/opendal",
"moonbitlang/async",
}///|
async fn browser_round_trip() {
let storage = @opendal.AsyncOperator::new("memory")
defer storage.close()
storage.write("hello.txt", b"hello from Chrome") |> ignore
assert_eq(storage.read("hello.txt"), b"hello from Chrome")
}///|
#cfg(target="native")
test "README: memory round trip" {
let operator = @opendal.Operator::new("memory")
operator.write("hello.txt", b"hello from MoonBit") |> ignore
assert_eq(operator.read("hello.txt"), b"hello from MoonBit")
}///|
#cfg(target="native")
test "README: typed storage error" {
let operator = @opendal.Operator::new("memory")
try operator.read("missing.txt") catch {
error => {
assert_true(error.kind() is NotFound)
assert_true(error.info().operation is Read)
assert_eq(error.info().path, Some("missing.txt"))
}
} noraise {
_ => fail("expected a missing-object error")
}
}///|
async test "README: async memory round trip" {
let async_operator = @opendal.AsyncOperator::new("memory")
defer async_operator.close()
async_operator.write("whole.txt", b"whole object") |> ignore
assert_eq(async_operator.read("whole.txt"), b"whole object")
let writer = async_operator.open_writer("async.txt")
writer.write(b"hello ")
writer.write(b"asynchronously")
writer.finish() |> ignore
assert_eq(async_operator.read("async.txt"), b"hello asynchronously")
}impl Show for OpenDalErrorpub struct AsyncOperator {
// private fields
}async fn AsyncOperator::open_read_stream(self : AsyncOperator, path : StringView, range? : ByteRange, chunk_size? : Int, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> AsyncReadStreamasync fn AsyncOperator::open_writer(self : AsyncOperator, path : StringView, append? : Bool, content_type? : StringView, content_disposition? : StringView, content_encoding? : StringView, cache_control? : StringView, if_match? : StringView, if_none_match? : StringView) -> AsyncWriterasync fn AsyncOperator::read(self : AsyncOperator, path : StringView, range? : ByteRange, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> Bytesasync fn AsyncOperator::write(self : AsyncOperator, path : StringView, data : BytesView, append? : Bool, content_type? : StringView, content_disposition? : StringView, content_encoding? : StringView, cache_control? : StringView, if_match? : StringView, if_none_match? : StringView) -> Metadatapub struct AsyncReadStream {
// private fields
}pub struct AsyncWriter {
// private fields
}pub type Capabilitypub struct Copier {
// private fields
}pub struct ErrorInfo {
kind : ErrorKind
status : ErrorStatus
message : String
operation : Operation
path : String?
destination_path : String?
} derive(Eq, Debug)pub struct Lister {
// private fields
}pub struct Metadata {
mode : EntryMode
content_length : UInt64
is_current : Bool?
is_deleted : Bool
cache_control : String?
content_disposition : String?
content_encoding : String?
content_md5 : String?
content_type : String?
etag : String?
last_modified : Timestamp?
version : String?
} derive(Eq, Debug)pub type Operatorfn Operator::copy(self : Operator, source : StringView, destination : StringView) -> Metadata raise OpenDalErrorfn Operator::delete(self : Operator, path : StringView, version? : StringView, recursive? : Bool) -> Unit raise OpenDalErrorfn Operator::list(self : Operator, path : StringView, recursive? : Bool, limit? : UInt64, start_after? : StringView) -> Array[Entry] raise OpenDalErrorfn Operator::open_copier(self : Operator, source : StringView, destination : StringView) -> Copier raise OpenDalErrorfn Operator::open_lister(self : Operator, path : StringView, recursive? : Bool, limit? : UInt64, start_after? : StringView) -> Lister raise OpenDalErrorfn Operator::open_read_stream(self : Operator, path : StringView, range? : ByteRange, chunk_size? : Int, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> ReadStream raise OpenDalErrorfn Operator::open_reader(self : Operator, path : StringView, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> Reader raise OpenDalErrorfn Operator::open_writer(self : Operator, path : StringView, append? : Bool, content_type? : StringView, content_disposition? : StringView, content_encoding? : StringView, cache_control? : StringView, if_match? : StringView, if_none_match? : StringView) -> Writer raise OpenDalErrorfn Operator::presign_read(self : Operator, path : StringView, expires_in_seconds~ : UInt64, range? : ByteRange, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> PresignedRequest raise OpenDalErrorfn Operator::presign_stat(self : Operator, path : StringView, expires_in_seconds~ : UInt64, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> PresignedRequest raise OpenDalErrorfn Operator::presign_write(self : Operator, path : StringView, expires_in_seconds~ : UInt64, append? : Bool, content_type? : StringView, content_disposition? : StringView, content_encoding? : StringView, cache_control? : StringView, if_match? : StringView, if_none_match? : StringView) -> PresignedRequest raise OpenDalErrorfn Operator::read(self : Operator, path : StringView, range? : ByteRange, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> Bytes raise OpenDalErrorfn Operator::rename(self : Operator, source : StringView, destination : StringView) -> Unit raise OpenDalErrorfn Operator::s3(bucket : StringView, region~ : StringView, root? : StringView, endpoint? : StringView, auth? : S3Auth, virtual_host_style? : Bool) -> Operator raise OpenDalErrorfn Operator::stat(self : Operator, path : StringView, version? : StringView, if_match? : StringView, if_none_match? : StringView) -> Metadata raise OpenDalErrorfn Operator::with_concurrency_limit(self : Operator, operation_limit~ : UInt, http_request_limit? : UInt) -> Operator raise OpenDalErrorfn Operator::with_retry(self : Operator, max_retries~ : UInt, min_delay_millis? : UInt64, max_delay_millis? : UInt64, jitter? : Bool) -> Operator raise OpenDalErrorfn Operator::with_timeout(self : Operator, operation_timeout_millis~ : UInt64, io_timeout_millis~ : UInt64) -> Operator raise OpenDalErrorfn Operator::write(self : Operator, path : StringView, data : BytesView, append? : Bool, content_type? : StringView, content_disposition? : StringView, content_encoding? : StringView, cache_control? : StringView, if_match? : StringView, if_none_match? : StringView) -> Metadata raise OpenDalErrorpub struct PresignedRequest {
http_method : String
uri : String
headers : Array[PresignedHeader]
} derive(Eq)pub struct ReadStream {
// private fields
}pub struct Reader {
// private fields
}pub struct S3Auth {
// private fields
}fn S3Auth::assume_role(role_arn~ : StringView, source? : S3CredentialSource, external_id? : StringView, role_session_name? : StringView, duration_seconds? : UInt64) -> S3Auth raise OpenDalErrorfn S3Auth::static_credentials(access_key_id~ : StringView, secret_access_key~ : StringView, session_token? : StringView) -> S3Auth raise OpenDalErrorpub struct S3CredentialSource {
// private fields
}fn S3CredentialSource::static_credentials(access_key_id~ : StringView, secret_access_key~ : StringView, session_token? : StringView) -> S3CredentialSource raise OpenDalErrorpub struct Writer {
// private fields
}