Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

s3mini

> 开发工具
Open source

⚠️ Moved to Codeberg: https://codeberg.org/thinking_tools/s3mini - Tiny S3 client. Edge computing ready. No-dep. In Typescript.

1.3K stars0 likes2 views
WebsiteGitHub

About

⚠️ Moved to Codeberg: https://codeberg.org/thinking_tools/s3mini - Tiny S3 client. Edge computing ready. No-dep. In Typescript.

s3mini | Tiny & fast S3 client for node, bun and edge platforms.

s3mini is an ultra-lightweight Typescript client (~20 KB minified, ≈15 % more ops/s) for S3-compatible object storage. It runs on Node, Bun, Cloudflare Workers, and other edge platforms. It has been tested on Cloudflare R2, Backblaze B2, DigitalOcean Spaces, Ceph, Oracle, Garage and MinIO. (No Browser support!)

[code.nolog] [issues] [npm]

Features

  • Light and fast: ~20 KB (minified, not gzipped), up to 1.37x faster on Bun vs Node.
  • Zero dependencies; supports AWS SigV4, pre-signed URLs, and SSE-C headers (tested on Cloudflare)
  • Works on Cloudflare Workers; ideal for edge computing, Node, and Bun (no browser support).
  • Only the essential S3 APIs—improved list, put, get, delete, and a few more.
  • ️ Supports multipart uploads.
  • Tree-shakeable ES module.
  • TypeScript support with type definitions.
  • Documented with examples, tests and widely tested on various S3-compatible services! (Contributions welcome!)
  • BYOS3 — Bring your own S3-compatible bucket (tested on Cloudflare R2, Backblaze B2, DigitalOcean Spaces, MinIO, Garage, Micro/Ceph and Oracle Object Storage, Scaleway).

Tested On

and more ... Contributions welcome!

Dev: +

Bun vs Node

s3mini is tested on both Node and Bun. In our benchmarks against MinIO, Bun is roughly ~1.4x faster on most operations (median across ~40 tests). Blob multipart uploads see the largest gain (~20x) thanks to Bun's native Blob.slice(). Results are approximate and will vary by environment.

Table of Contents

  • Installation
  • Quick Start
  • Configuration
  • Uploading Objects
  • Downloading Objects
  • Listing Objects
  • Deleting Objects
  • Copy and Move
  • Conditional Requests
  • Pre-signed URLs
  • Server-Side Encryption (SSE-C)
  • API Reference
  • Error Handling
  • Cloudflare Workers
  • Supported Operations
  • Security Notes
  • Contributions welcomed!
  • License

Installation

bash
npm install s3mini
bash
yarn add s3mini
bash
pnpm add s3mini

Environment Variables

To use s3mini, you need to set up your environment variables for provider credentials and S3 endpoint. Create a .env file in your project root directory. Checkout the example.env file for reference.

bash
# On Windows, Mac, or Linux
mv example.env .env

⚠️ Environment Support Notice

This library is designed to run in environments like Node.js, Bun, and Cloudflare Workers. It does not support browser environments due to the use of Node.js APIs and polyfills.

Quick Start

typescript
import { S3mini } from 's3mini';

const s3 = new S3mini({
  accessKeyId: process.env.S3_ACCESS_KEY,
  secretAccessKey: process.env.S3_SECRET_KEY,
  endpoint: 'https://bucket.region.r2.cloudflarestorage.com',
  region: 'auto',
});

// Upload (auto-selects single PUT or multipart based on size)
await s3.putAnyObject('photos/vacation.jpg', fileBuffer, 'image/jpeg');

// Download
const data = await s3.getObject('photos/vacation.jpg');

// List
const objects = await s3.listObjects('/', 'photos/');

// Delete
await s3.deleteObject('photos/vacation.jpg');

Configuration

typescript
const s3 = new S3mini({
  // Required
  accessKeyId: string,
  secretAccessKey: string,
  endpoint: string, // Full URL: https://bucket.region.provider.com

  // Optional
  region: string, // Default: 'auto'
  minPartSize: number, // Default: 8MB — threshold for multipart
  requestSizeInBytes: number, // Default: 8MB — chunk size for range requests
  requestAbortTimeout: number, // Timeout in ms (undefined = no timeout)
  logger: Logger, // Custom logger with info/warn/error methods
  fetch: typeof fetch, // Custom fetch implementation
});

Endpoint formats:

typescript
// Path-style (bucket in path)
'https://s3.us-east-1.amazonaws.com/my-bucket';

// Virtual-hosted-style (bucket in subdomain)
'https://my-bucket.s3.us-east-1.amazonaws.com';

// Provider-specific
'https://my-bucket.nyc3.digitaloceanspaces.com';
'https://account-id.r2.cloudflarestorage.com/my-bucket';

Uploading Objects

putObject — Simple Upload

Direct single-request upload. Use for small files or when you need fine control.

typescript
const response = await s3.putObject(
  key: string,                    // Object key/path
  data: string | Buffer | Uint8Array | Blob | File | ReadableStream,
  contentType?: string,           // Default: 'application/octet-stream'
  ssecHeaders?: SSECHeaders,      // Optional encryption headers
  additionalHeaders?: AWSHeaders, // Optional x-amz-* headers
  contentLength?: number,         // Optional, auto-detected for most types
);

// Returns: Response object
const etag = response.headers.get('etag');

Examples:

typescript
// String content
await s3.putObject('config.json', JSON.stringify({ key: 'value' }), 'application/json');

// Buffer/Uint8Array
const buffer = await fs.readFile('image.png');
await s3.putObject('images/photo.png', buffer, 'image/png');

// Blob (browser File API or Node 18+)
const blob = new Blob(['Hello'], { type: 'text/plain' });
await s3.putObject('hello.txt', blob, 'text/plain');

// With custom headers
await s3.putObject('data.bin', buffer, 'application/octet-stream', undefined, {
  'x-amz-meta-author': 'john',
  'x-amz-meta-version': '1.0',
});

putAnyObject — Smart Upload (Recommended)

Automatically chooses single PUT or multipart based on data size. This is the recommended method for most use cases.

typescript
const response = await s3.putAnyObject(
  key: string,
  data: string | Buffer | Uint8Array | Blob | File | ReadableStream,
  contentType?: string,
  ssecHeaders?: SSECHeaders,
  additionalHeaders?: AWSHeaders,
  contentLength?: number,
);

Behavior:

  • ≤ minPartSize (8MB default): Single PUT request
  • > minPartSize: Automatic multipart upload with:
    • Parallel part uploads (4 concurrent by default)
    • Automatic retries with exponential backoff (3 retries)
    • Proper cleanup on failure (aborts incomplete uploads)

Examples:

…

Memory efficiency with Blobs:

For large files, using Blob or File is more memory-efficient than Uint8Array:

typescript
// ❌ Loads entire file into memory
const buffer = await fs.readFile('large-video.mp4');
await s3.putAnyObject('video.mp4', buffer);

// ✅ Zero-copy slicing — only reads data when uploading each part
const file = Bun.file('large-video.mp4'); // Bun
// or
const blob = await fs.openAsBlob('large-video.mp4'); // Node
await s3.putAnyObject('video.mp4', blob);

Manual Multipart Upload

For advanced control over multipart uploads (progress tracking, resumable uploads, custom concurrency).

…

Parallel uploads with progress:

…

Abort an incomplete upload:

typescript
await s3.abortMultipartUpload(key, uploadId);

List pending multipart uploads:

typescript
const pending = await s3.listMultipartUploads();
// Clean up orphaned uploads
for (const upload of pending.Upload || []) {
  await s3.abortMultipartUpload(upload.Key, upload.UploadId);
}

Downloading Objects

…

Listing Objects

typescript
// List all objects (auto-paginates)
const objects = await s3.listObjects();

// With prefix filter (list "folder")
const photos = await s3.listObjects('/', 'photos/');

// With max keys limit
const first100 = await s3.listObjects('/', '', 100);

// Manual pagination
let token: string | undefined;
do {
  const { objects, nextContinuationToken } = await s3.listObjectsPaged(
    '/', // delimiter
    'uploads/', // prefix
    100, // maxKeys per page
    token, // continuation token
  );
  console.log(objects);
  token = nextContinuationToken;
} while (token);

Response shape:

typescript
interface ListObject {
  Key: string;
  Size: number;
  LastModified: Date;
  ETag: string;
  StorageClass: string;
}

Deleting Objects

typescript
// Single object
const deleted = await s3.deleteObject('file.txt'); // boolean

// Multiple objects (batched, max 1000 per request)
const keys = ['a.txt', 'b.txt', 'c.txt'];
const results = await s3.deleteObjects(keys); // boolean[] in same order

Copy and Move

Server-side copy (no data transfer through client):

typescript
// Copy within same bucket
const result = await s3.copyObject('source.txt', 'backup/source.txt');

// Copy with new metadata
await s3.copyObject('report.pdf', 'archive/report.pdf', {
  metadataDirective: 'REPLACE',
  metadata: {
    'archived-at': new Date().toISOString(),
  },
  contentType: 'application/pdf',
});

// Move (copy + delete source)
await s3.moveObject('temp/upload.tmp', 'files/document.pdf');

Options:

typescript
interface CopyObjectOptions {
  metadataDirective?: 'COPY' | 'REPLACE';
  metadata?: Record;
  contentType?: string;
  storageClass?: string;
  taggingDirective?: 'COPY' | 'REPLACE';
  sourceSSECHeaders?: SSECHeaders;
  destinationSSECHeaders?: SSECHeaders;
  additionalHeaders?: AWSHeaders;
}

Conditional Requests

Use If-* headers to avoid unnecessary transfers:

typescript
// Only download if changed (returns null if ETag matches)
const data = await s3.getObject('file.txt', {
  'if-none-match': '"abc123"',
});

// Only download if modified since date
const data = await s3.getObject('file.txt', {
  'if-modified-since': 'Wed, 21 Oct 2024 07:28:00 GMT',
});

// Check existence with conditions
const exists = await s3.objectExists('file.txt', {
  'if-match': '"abc123"',
}); // null if ETag mismatch, true/false otherwise

Pre-signed URLs

Generate time-limited URLs that allow unauthenticated HTTP clients to upload or download objects directly — no credentials needed on the client side.

typescript
// Download URL (valid for 1 hour by default)
const downloadUrl = await s3.getPresignedUrl('GET', 'photos/vacation.jpg');

// Upload URL (valid for 5 minutes)
const uploadUrl = await s3.getPresignedUrl('PUT', 'uploads/file.bin', 300);

Client-side usage (no SDK or credentials required):

typescript
// Upload via pre-signed URL
await fetch(uploadUrl, {
  method: 'PUT',
  body: fileData,
  headers: { 'Content-Type': 'image/jpeg' },
});

// Download via pre-signed URL
const response = await fetch(downloadUrl);
const data = await response.arrayBuffer();

Custom response headers:

typescript
// Force download with a specific filename
const url = await s3.getPresignedUrl('GET', 'report.pdf', 3600, {
  'response-content-disposition': 'attachment; filename="report.pdf"',
  'response-content-type': 'application/pdf',
});

Signed headers (enforce headers on the client request):

typescript
// Upload URL that requires Content-Type — client MUST send this exact header
const url = await s3.getPresignedUrl(
  'PUT',
  'uploads/data.json',
  300,
  {},
  {
    'Content-Type': 'application/json',
  },
);

await fetch(url, {
  method: 'PUT',
  body: JSON.stringify({ ok: true }),
  headers: { 'Content-Type': 'application/json' },
});

Method signature:

typescript
getPresignedUrl(
  method: 'GET' | 'PUT',
  key: string,
  expiresIn?: number,           // Default: 3600 (1 hour), max: 604800 (7 days)
  queryParams?: Record<string, string>,
  headers?: Record<string, string>,  // HTTP head

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptaws-s3backblazebunceph

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具