s3

    Download zip
    Version
    0.4.0
    License
    Apache-2.0
    Last updated
    21 hours ago
    Downloads
    7

    #hackwaly/s3

    ** Forked from hackwaly/s3 **

    Async S3 client for MoonBit, built on moonbitlang/async/http.

    ///|
    async fn example {
    let client = @s3.Client(
    @s3.Config("us-east-1", @s3.Credentials("AKIA...", "secret...")),
    )
    let object = client.get_object("my-bucket", "path/to/object.txt")
    let body = object.body.read_all().text()
    object.body.close()
    println(body)
    }

    For MinIO or other S3-compatible services, use a custom endpoint and path-style addressing:

    ///|
    let client = @s3.Client(
    @s3.Config(
    "us-east-1",
    @s3.Credentials("minioadmin", "minioadmin"),
    endpoint="http://127.0.0.1:9000",
    endpoint_style=@s3.Path,
    ),
    )

    Implemented operations:

    • get_object
    • put_object
    • head_object
    • delete_object
    • list_objects_v2
    • generate_presigned_get_url
    • generate_presigned_put_url

    ReadCloser

    pub(open) trait ReadCloser :
    Reader
    {
    fn close(Self) -> Unit
    }

    S3Error

    pub suberror S3Error {
    InvalidConfig(String)
    InvalidInput(String)
    InvalidResponse(String)
    ServiceError(
    Response
    , String)
    } derive(
    Debug
    )

    Client

    Client::Client

    fn Client::Client(config : Config) -> Client raise

    Client::delete_object

    async fn Client::delete_object(self : Client, bucket : String, key : String, options? : RequestOptions) ->
    Response

    Client::generate_presigned_get_url

    fn Client::generate_presigned_get_url(self : Client, bucket : String, key : String, expires_seconds? : Int) -> String raise

    Generate a presigned GET URL for an S3 object.

    :param bucket: Name of the S3 bucket :param key: Key (path) of the object within the bucket :param expires_seconds: Time in seconds for the URL to remain valid (default 1 hour, maximum 7 days) :return: Presigned URL as a string

    Client::generate_presigned_put_url

    fn Client::generate_presigned_put_url(self : Client, bucket : String, key : String, expires_seconds? : Int, content_type? : String) -> String raise

    Generate a presigned PUT URL for uploading an object directly to S3.

    :param bucket: Name of the S3 bucket :param key: Key (path) where the object will be stored :param expires_seconds: Time in seconds the URL remains valid (default 1 hour, maximum 7 days) :param content_type: Optional — if set, the client MUST send this exact Content-Type header when uploading, or S3 will reject it :return: Presigned URL as a string

    Client::get_object

    async fn Client::get_object(self : Client, bucket : String, key : String, options? : RequestOptions) -> ObjectResult

    Client::head_object

    async fn Client::head_object(self : Client, bucket : String, key : String, options? : RequestOptions) ->
    Response

    Client::list_objects_v2

    async fn Client::list_objects_v2(self : Client, bucket : String, prefix? : String, delimiter? : String, continuation_token? : String, max_keys? : Int, options? : RequestOptions) -> ListObjectsV2Result

    Client::put_object

    async fn Client::put_object(self : Client, bucket : String, key : String, body : &
    Data
    , options? : RequestOptions) ->
    Response

    Config

    Config::Config

    fn Config::Config(region : String, credentials : Credentials, endpoint? : String, endpoint_style? : EndpointStyle) -> Config

    Create an S3 client configuration.

    endpoint_style is optional and defaults based on the endpoint:
    • No endpoint (AWS default URL): VirtualHost, the AWS-standard bucket.s3.<region>.amazonaws.com addressing.
    • Custom endpoint (MinIO, R2, Ceph, Garage, ...): Path, since third-party S3-compatible services generally do not resolve <bucket>.<endpoint> subdomains. An explicit endpoint_style always wins.

    Credentials

    type Credentials derive(Eq)

    Credentials::Credentials

    fn Credentials::Credentials(access_key_id : String, secret_access_key : String, session_token? : String) -> Credentials

    EndpointStyle

    pub(all) enum EndpointStyle {
    VirtualHost
    Path
    } derive(Eq,
    Debug
    )

    ListObjectsV2Result

    pub struct ListObjectsV2Result {
    is_truncated : Bool
    next_continuation_token : String?
    contents : Array[ListedObject]
    common_prefixes : Array[String]
    } derive(Eq,
    Debug
    )

    ListedObject

    pub struct ListedObject {
    key : String
    size : Int64
    etag : String?
    } derive(Eq,
    Debug
    )

    ObjectResult

    pub struct ObjectResult {
    response :
    Response

    body : &ReadCloser
    }

    RequestOptions

    type RequestOptions derive(
    Debug
    )

    RequestOptions::RequestOptions

    fn RequestOptions::RequestOptions(headers? : Map[String, String], query? : Map[String, String], timestamp? : String, payload_hash? : String) -> RequestOptions