Module

x/s3_lite_client/mod.ts>S3Client

A lightweight but powerful S3 client for Deno
Latest
class S3Client
import { S3Client } from "https://dotland.deno.dev/x/s3_lite_client@0.7.0/mod.ts";

Constructors

new
S3Client(params: ClientOptions)

Properties

readonly
optional
accessKey: string
readonly
defaultBucket: string | undefined
readonly
host: string
readonly
pathStyle: boolean

Use path-style requests, e.g. https://endpoint/bucket/object-key instead of https://bucket/object-key

readonly
port: number
readonly
protocol: "https:" | "http:"
readonly
region: string
readonly
optional
sessionToken: string
readonly
userAgent: string

Methods

private
buildRequestOptions(options: { objectName: string; bucketName?: string; headers?: Headers; query?: string | Record<string, string>; }): { headers: Headers; host: string; path: string; }

Common code used for both "normal" requests and presigned UTL requests

protected
calculatePartSize(size: number | undefined)

Calculate part size given the object size. Part size will be at least this.partSize.

Per https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html we have to stick to the following rules:

  • part size between 5MB (this.maximumPartSize) and 5GB (this.maxObjectSize) (the final part can be smaller than 5MB however)
  • maximum of 10,000 parts per upload
  • maximum object size of 5TB
protected
getBucketName(options: undefined | { bucketName?: string; })
bucketExists(bucketName: string): Promise<boolean>
copyObject(
source: { sourceBucketName?: string; sourceKey: string; sourceVersionId?: string; },
objectName: string,
options?: { bucketName?: string; },
): Promise<CopiedObjectInfo>

Copy an object into this bucket

deleteObject(objectName: string, options?: { bucketName?: string; versionId?: string; governanceBypass?: boolean; })

Delete a single object.

You can also pass a versionId to delete a specific version of an object.

exists(objectName: string, options?: { bucketName?: string; versionId?: string; }): Promise<boolean>

Check if an object with the specified key exists.

getObject(objectName: string, options?: { metadata?: ObjectMetadata; bucketName?: string; versionId?: string; responseParams?: ResponseOverrideParams; }): Promise<Response>

Get an object.

Returns a standard HTTP Response object, which has many ways of consuming the response including .text(), .json(), .body (ReadableStream), .arrayBuffer(), and .blob().

getPartialObject(objectName: string, unnamed 1: { offset: number; length: number; metadata?: ObjectMetadata; bucketName?: string; versionId?: string; responseParams?: ResponseOverrideParams; }): Promise<Response>

Stream a partial object, starting from the specified offset in bytes, up to the specified length in bytes. A length of zero will return the rest of the object from the specified offset. Pass a version UUID as "versionId" to download a specific version.

Returns a standard HTTP Response object.

getPresignedUrl(
method:
| "GET"
| "PUT"
| "HEAD"
| "DELETE"
,
objectName: string,
options?: { bucketName?: string; parameters?: Record<string, string>; expirySeconds?: number; requestDate?: Date; },
): Promise<string>

Low-level method to generate a pre-signed URL.

listObjects(options?: { prefix?: string; bucketName?: string; maxResults?: number; pageSize?: number; }): AsyncGenerator<S3Object, void, undefined>

List objects in the bucket, optionally filtered by the given key prefix.

This returns a flat list; use listObjectsGrouped() for more advanced behavior.

listObjectsGrouped(options: { delimiter: string; prefix?: string; bucketName?: string; maxResults?: number; pageSize?: number; }): AsyncGenerator<S3Object | CommonPrefix, void, undefined>

List objects in the bucket, grouped based on the specified "delimiter".

See https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-prefixes.html

makeBucket(bucketName: string): Promise<void>
makeRequest(unnamed 0: { method:
| "POST"
| "GET"
| "PUT"
| "DELETE"
| string
; headers?: Headers; query?: string | Record<string, string>; objectName: string; bucketName?: string; statusCode?: number; payload?: Uint8Array | string; returnBody?: boolean; }
): Promise<Response>

Make a single request to S3

presignedGetObject(objectName: string, options?: { bucketName?: string; versionId?: string; responseParams?: ResponseOverrideParams; expirySeconds?: number; requestDate?: Date; })

Generate a pre-signed GET request URL.

Use options.expirySeconds to override the expiration time (default is 7 days)

putObject(
objectName: string,
streamOrData: ReadableStream<Uint8Array> | Uint8Array | string,
options?: { metadata?: ObjectMetadata; size?: number; bucketName?: string; partSize?: number; },
): Promise<UploadedObjectInfo>
removeBucket(bucketName: string): Promise<void>
statObject(objectName: string, options?: { bucketName?: string; versionId?: string; }): Promise<ObjectStatus>

Get detailed information about an object.