Skip to main content
zerotal

Documentation


Documentation / @zerotal/core / storage / S3Driver

Class: S3Driver

Defined in: storage/drivers/S3Driver.ts:38

S3-compatible storage driver — works with AWS S3, Cloudflare R2, MinIO, etc. Powered by Bun's native s3() client: zero npm dependencies, automatic SigV4 signing, connection reuse, and built-in retry/backoff.

Example

StorageConfig({
  disks: {
    r2: {
      driver:   's3',
      key:      Bun.env.R2_KEY!,
      secret:   Bun.env.R2_SECRET!,
      region:   'auto',
      bucket:   'my-bucket',
      endpoint: `https://${Bun.env.CF_ACCOUNT_ID}.r2.cloudflarestorage.com`,
    },
  },
});

Implements

Constructors

Constructor

new S3Driver(key, secret, region, bucket, endpoint?, urlBase?): S3Driver

Defined in: storage/drivers/S3Driver.ts:45

Parameters

key

string

secret

string

region

string

bucket

string

endpoint?

string

urlBase?

string

Returns

S3Driver

Methods

put()

put(path, content, options?): Promise<void>

Defined in: storage/drivers/S3Driver.ts:66

Parameters

path

string

content

string | Blob | Uint8Array<ArrayBufferLike>

options?

PutOptions

Returns

Promise<void>

Implementation of

StorageDriver.put


append()

append(_path, _content): Promise<void>

Defined in: storage/drivers/S3Driver.ts:76

Append to the end of a file, creating it when absent.

Only a filesystem can do this. An object store rewrites the whole object on every write, so emulating an append there would quietly turn one line of a log into a full download-and-upload of the day's file — S3Driver throws UnsupportedOperationError rather than pretend. Use it for things that are genuinely local and line-oriented, like the log trail.

Parameters

_path

string

_content

string | Uint8Array<ArrayBufferLike>

Returns

Promise<void>

Implementation of

StorageDriver.append


get()

get(path): Promise<string | null>

Defined in: storage/drivers/S3Driver.ts:83

Parameters

path

string

Returns

Promise<string | null>

Implementation of

StorageDriver.get


getBuffer()

getBuffer(path): Promise<Uint8Array<ArrayBufferLike> | null>

Defined in: storage/drivers/S3Driver.ts:92

Parameters

path

string

Returns

Promise<Uint8Array<ArrayBufferLike> | null>

Implementation of

StorageDriver.getBuffer


exists()

exists(path): Promise<boolean>

Defined in: storage/drivers/S3Driver.ts:101

Parameters

path

string

Returns

Promise<boolean>

Implementation of

StorageDriver.exists


delete()

delete(path): Promise<void>

Defined in: storage/drivers/S3Driver.ts:111

Parameters

path

string

Returns

Promise<void>

Implementation of

StorageDriver.delete


url()

url(path): string

Defined in: storage/drivers/S3Driver.ts:115

Return a public URL for the given path.

Parameters

path

string

Returns

string

Implementation of

StorageDriver.url


copy()

copy(source, destination): Promise<void>

Defined in: storage/drivers/S3Driver.ts:122

Copy a file within the same disk.

Parameters

source

string

destination

string

Returns

Promise<void>

Implementation of

StorageDriver.copy


move()

move(source, destination): Promise<void>

Defined in: storage/drivers/S3Driver.ts:128

Move (rename) a file within the same disk.

Parameters

source

string

destination

string

Returns

Promise<void>

Implementation of

StorageDriver.move


size()

size(path): Promise<number | null>

Defined in: storage/drivers/S3Driver.ts:133

Return the file size in bytes, or null if not found.

Parameters

path

string

Returns

Promise<number | null>

Implementation of

StorageDriver.size


lastModified()

lastModified(path): Promise<number | null>

Defined in: storage/drivers/S3Driver.ts:143

Return the last-modified timestamp (ms since epoch), or null if not found.

Parameters

path

string

Returns

Promise<number | null>

Implementation of

StorageDriver.lastModified


temporaryUrl()

temporaryUrl(path, expiresInSeconds): Promise<string>

Defined in: storage/drivers/S3Driver.ts:154

Return a temporary URL valid for expiresInSeconds seconds. For local driver this is a signed token URL; for S3 it is a presigned URL.

Parameters

path

string

expiresInSeconds

number

Returns

Promise<string>

Implementation of

StorageDriver.temporaryUrl