hew.storage.s3
Actor-owned S3-compatible object storage with typed errors and byte-exact values
Use version 0.3.0
hew add hew.storage.s3 --version 0.3.0
- Declared Hew requirement
- >=0.6.1, <0.7.0
- Licence
- MIT OR Apache-2.0
- Published
- 2026-10-17T05:38:36.237Z
Dependencies
No package dependencies.
Package README
# hew.storage.s3
An actor-owned S3-compatible object storage client with typed errors, exact
byte payloads, explicit missing-object outcomes, paginated listings, and
automatic native cleanup.
## Example
Start an S3-compatible service and create `hew-example`, then save this as
`main.hew` in a project depending on `hew.storage.s3 = "0.7.1"`:
```hew
import hew.storage.s3;
import std.encoding.utf8;
fn main() {
let store = spawn s3.Bucket { options: s3.Options {
endpoint: "http://127.0.0.1:9000",
region: "us-east-1",
bucket: "hew-example",
access_key: "<ACCESS_KEY>",
secret_key: "<SECRET_KEY>",
} };
match store.put("hello.txt", "hello".to_bytes(), "text/plain") {
.Ok(_) => println("uploaded"),
.Err(.Failed(error)) => println(s3.error_message(error)),
.Err(_) => println("S3 actor stopped before replying"),
}
match store.get("hello.txt") {
.Ok(.Found(body)) => println(utf8.decode_lossy(body)),
.Ok(.Missing) => println("object is missing"),
.Err(.Failed(error)) => println(s3.error_message(error)),
.Err(_) => println("S3 actor stopped before replying"),
}
stop(store);
stopped(store);
}
```
Each call replies `Result<T, ActorError<S3Error>>`: `.Ok(value)` on success,
`.Err(.Failed(error))` for an S3 failure, and another `.Err` variant when the
actor could not answer (for example `.Dead` after it stopped).
The checked example at [`examples/basic.hew`](examples/basic.hew) is the same
program, plus a test that runs it, against the MinIO service in
`docker-compose.yml`. Run it from the
ecosystem checkout:
```sh
docker compose up --detach --wait minio
hew run --pkg-path . storage/s3/examples/basic.hew
```
It prints `uploaded example/hello.txt` and then `hello`.
## API surface
`spawn s3.Bucket { options: config }` connects and returns the actor handle.
`Options` fields: `endpoint`, `region`, `bucket`, `access_key`, `secret_key`
(all `string`).
Every operation below is `receive fn`, called as `store.<name>(...)`,
and declares `fails S3Error`:
- `put(key: string, body: bytes, content_type: string) fails S3Error`
— upload exact bytes under `key`.
- `get(key: string) -> ObjectLookup fails S3Error` — download exact bytes.
`ObjectLookup` is `.Missing` or `.Found(bytes)`; a missing object is distinct
from a present empty one.
- `delete(key: string) fails S3Error` — deleting an absent key is
successful S3 behaviour, not an error.
- `list(prefix: string) -> Vec<ObjectInfo> fails S3Error` — every object
under `prefix`, following continuation tokens. `ObjectInfo` has `key:
string` and `size: i64`.
- `exists(key: string) -> bool fails S3Error`.
- `presign(key: string, method: string, expires_seconds: i64) -> string fails
S3Error` — a signed URL for `"GET"`, `"PUT"`, `"DELETE"`, or `"HEAD"`.
- `stop(store); stopped(store);` — stop the actor and wait for native client cleanup.
`s3.error_message(error: S3Error) -> string` returns the diagnostic carried by
any `S3Error` variant (`Connection`, `InvalidInput`, `NotFound`,
`AccessDenied`, `Throttled`, `ServerError(i64, string)`, `Network`,
`HttpStatus(i64, string)`, `Decode`, `Closed`, `Internal`).