Storage API

Piko's storage service wraps object-storage backends (local disk, S3-compatible, GCS) behind one fluent builder. Uploads and reads flow through optional stream transformers that compress or encrypt content in-line. For task recipes see the assets how-to. Source of truth: wdk/storage/facade.go.

Service

FunctionReturns
storage.NewService(defaultProviderName string, opts ...ServiceOption) ServiceConstructs a new service with a named default provider.
storage.GetDefaultService() (Service, error)Returns the service the bootstrap built from WithStorageProvider options.

Builders

func NewUploadBuilder(service Service, reader io.Reader) (*UploadBuilder, error)
func NewUploadBuilderFromDefault(reader io.Reader) (*UploadBuilder, error)
func NewRequestBuilder(service Service, repository, key string) (*RequestBuilder, error)
func NewRequestBuilderFromDefault(repository, key string) (*RequestBuilder, error)

Both builders share .Provider(name) and .Transformer(name, options...) and clone via .Clone(). The two surfaces diverge in their fluent vocabulary and terminal calls.

UploadBuilder

UploadBuilder is for PUT operations. Configure with .Key(key), .Repository(repo), .ContentType(mime), .Size(bytes), .Metadata(map), .CAS(algorithm, expectedHash...), .Multipart(config), .Transformer(name, options...), and .Dispatch() for asynchronous queuing. Execute with .Do(ctx). Use .Build() to obtain a reusable PutObjectSpec for batch uploads.

RequestBuilder

RequestBuilder is for read, stat, remove, and hash operations on a (repository, key) pair fixed at construction. Configure with .ByteRange(start, end), .Transformer(name, options), and .DispatchRemove() for asynchronous deletion. Terminal methods are:

MethodReturns
Get(ctx)(io.ReadCloser, error). Caller closes the stream.
Stat(ctx)(*ObjectInfo, error). Metadata only.
Remove(ctx)error. Deletes the object.
Hash(ctx)(string, error). Returns the content hash.

RequestBuilder does not expose .Key(...), .ContentType(...), or .Do(ctx). Those belong to UploadBuilder.

Types

TypePurpose
ServiceEntry point. Manages providers and resolves operations.
ProviderPortInterface a provider implements (GET, PUT, DELETE, PRESIGN).
DispatcherPortInterface for background upload dispatchers.
StreamTransformerPortInterface for pipeline transformers (compression, encryption).
UploadBuilderFluent builder for PUT operations.
RequestBuilderFluent builder for GET, DELETE, COPY, PRESIGN operations.
ObjectInfoMetadata returned by Stat and List.
BatchResult / BatchFailureReturned by PutMany, RemoveMany, Migrate.

Params structs: PutParams, GetParams, CopyParams, PresignParams, PresignDownloadParams, PutManyParams, RemoveManyParams, MigrateParams, MultipartUploadConfig, ByteRange.

Dispatcher and resilience

Upload bursts go through an optional dispatcher configured via DispatcherConfig. Retries, rate limits, and circuit breakers take their configuration from RetryConfig, ProviderRateLimitConfig, and CircuitBreakerConfig. Stats land in DispatcherStats.

Transformers

Sub-packageRole
storage_transformer_gzipGzip (DEFLATE) compression on upload; automatic decompression on read.
storage_transformer_zstdZstandard compression on upload; automatic decompression on read.
storage_transformer_cryptoAES encryption with envelope keying.

Attach transformers from a builder via .Transformer(name, options...). Each transformer reports its kind through TransformerType, with constants TransformerCompression, TransformerEncryption, and TransformerCustom.

Providers

Sub-packageBackend
storage_provider_diskLocal filesystem.
storage_provider_s3Generic S3-compatible (AWS S3, MinIO, any S3-API service).
storage_provider_r2Cloudflare R2 (dedicated bindings; use this in preference to the generic S3 provider when targeting R2).
storage_provider_gcsGoogle Cloud Storage.

Bootstrap options

OptionPurpose
piko.WithStorageProvider(name, provider)Registers a provider under a name.
piko.WithDefaultStorageProvider(name)Marks a registered provider as the default.
piko.WithStorageDispatcher(cfg)Enables the background dispatcher.
piko.WithStoragePresignBaseURL(url)Overrides the base URL for pre-signed download responses.
piko.WithStoragePublicBaseURL(url)Sets the public URL prefix for publicly readable objects.

Constants

NameValue
StorageNameDefaultName for the Piko default provider.
StorageNameSystemName reserved for system-managed storage.
StorageRepositoryDefaultDefault repository (bucket/directory) name.

See also