@bradenmacdonald/s3-lite-client

中文文档
1.0.1发布于 2026/10/30MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 1.3万

A lightweight S3 client.

原始使用文档
文档目录4 节
  1. Supported functionality
  2. Installation
  3. Usage Examples (Quickstart)
  4. Developer notes

s3-lite-client

MIT License no dependencies minimized gzipped size JSR Version NPM Version JSR Downloads

This is a lightweight S3 (object storage) client for JavaScript runtimes (Deno, Node 22+, Bun, browsers, etc.). It is designed to offer all the key features you may need, without bloat.

Key features:

  • Has no dependencies and minifies to about 21kB (< 8 kB gzipped).
  • Works with any S3-compatible storage service: AWS S3, MinIO, Cloudflare R2, Backblaze B2, DigitalOcean Spaces, Supabase storage, etc.
  • Works with any JavaScript runtime that supports the fetch API, web streams API, and ES modules (ESM). This client does not depend on any NodeJS APIs nor Deno APIs.
  • Implemented in TypeScript and fully typed.
  • MIT licensed (originally based on the MinIO JavaScript Client).
  • Used in production since 2021.

Supported functionality

  • Authenticated or unauthenticated requests
  • List objects: for await (const object of client.listObjects(options)) { ... }
    • Handles pagination transparently
    • Supports filtering using a prefix
    • Supports grouping using a delimiter (use client.listObjectsGrouped(...))
  • Check if an object exists: client.exists("key")
  • Get metadata about an object: client.statObject("key")
    • Can include custom headers in the request: client.statObject("key", { headers: { 'x-amz-checksum-mode': 'ENABLED' } })
  • Download an object: client.getObject("key", options)
    • This just returns a standard HTTP Response object, so for large files, you can opt to consume the data as a stream (use the .body property).
  • Download a partial object: client.getPartialObject("key", options)
    • Like getObject, this also supports streaming the response if you want to.
  • Upload an object: client.putObject("key", streamOrData, options)
    • Can upload from a string, Uint8Array, or ReadableStream
    • Can split large uploads into multiple parts, and uploads a limited number of parts in parallel.
    • Uploads of 64MB or more are split into 64MB parts by default. Since S3 allows at most 10,000 parts, that supports objects up to 640GB; to upload something bigger, or to stream something bigger without passing size, pass a larger partSize (up to 5GB).
    • Can set custom headers, ACLs, and other metadata on the new object (example below).
  • Copy an object: client.copyObject({ sourceKey: "source", options }, "dest", options)
    • Can copy between different buckets.
  • Delete an object: client.deleteObject("key")
  • Create pre-signed URLs: client.presignedGetObject("key", options) or client.getPresignedUrl(method, "key", options)
  • Create pre-signed POST policy: client.presignedPostObject("key", options) for direct browser uploads
  • Check if a bucket exists: client.bucketExists("bucketName")
  • Create a new bucket: client.makeBucket("bucketName")
  • Remove a bucket: client.removeBucket("bucketName")

Installation

  • Deno: deno add @bradenmacdonald/s3-lite-client
  • Deno (no install): import { S3Client } from "jsr:@bradenmacdonald/[email protected]";
  • NPM: npm add @bradenmacdonald/s3-lite-client
  • Yarn: yarn add jsr:@bradenmacdonald/s3-lite-client
  • pnpm: pnpm add jsr:@bradenmacdonald/s3-lite-client
  • Bun: bunx jsr add @bradenmacdonald/s3-lite-client
  • Browser:
    <script type="module">
    import { S3Client } from "https://esm.sh/jsr/@bradenmacdonald/[email protected]";
    // Or:
    const { S3Client } = await import("https://esm.sh/jsr/@bradenmacdonald/[email protected]");
    </script>
    

Usage Examples (Quickstart)

List data files from a public data set on Amazon S3:

import { S3Client } from "@bradenmacdonald/s3-lite-client";

const s3client = new S3Client({
  endPoint: "https://s3.us-east-1.amazonaws.com",
  region: "us-east-1",
  bucket: "openalex",
});

// Log data about each object found under the 'data/concepts/' prefix:
for await (const obj of s3client.listObjects({ prefix: "data/concepts/" })) {
  console.log(obj);
}
// {
//   type: "Object",
//   key: "data/concepts/updated_date=2024-01-25/part_000.gz",
//   etag: "2c9b2843c8d2e9057656e1af1c2a92ad",
//   size: 44105,
//   lastModified: 2024-01-25T22:57:43.000Z
// },
// ...

// Or, to get all the keys (paths) as an array:
const keys = await Array.fromAsync(s3client.listObjects(), (entry) => entry.key);
// keys = [
//  "data/authors/manifest",
//  "data/authors/updated_date=2023-06-08/part_000.gz",
//  ...
// ]

(Note: As shown above, the list functions normally hide pagination details from you and convert the result to a single list as you retrieve each entry. If you need to request specific pages, see this example.)

Uploading and downloading a file using a local S3-compatible server (e.g. RustFS):

import { S3Client } from "@bradenmacdonald/s3-lite-client";

// Connecting to a local RustFS server:
const s3client = new S3Client({
  endPoint: "http://localhost:9000",
  region: "dev-region",
  bucket: "dev-bucket",
  accessKey: "AKIA_DEV",
  secretKey: "secretkey",
});

// Upload a file:
await s3client.putObject("test.txt", "This is the contents of the file.");

// Now download it
const result = await s3client.getObject("test.txt");
// and stream the results to a local file:
const localOutFile = await Deno.open("test-out.txt", { write: true, createNew: true });
await result.body!.pipeTo(localOutFile.writable);
// or instead of streaming, you can consume the whole file into memory by awaiting
// result.text(), result.blob(), result.arrayBuffer(), or result.json()

Creating a bucket on the S3 service of a local supabase development server:

const client = new S3Client({
  endPoint: "http://127.0.0.1:54321/storage/v1/s3",
  region: "local",
  accessKey: "paste from output of supabase start",
  secretKey: "paste from output of supabase start",
});
await client.makeBucket("my-bucket");

Set ACLs, Content-Type, custom metadata, etc. during upload:

await s3client.putObject("key", streamOrData, {
  metadata: {
    "x-amz-acl": "public-read",
    "x-amz-meta-custom": "value",
  },
});

Create a presigned POST policy for direct uploads from a browser:

// Create a presigned POST policy
const { url, fields } = await s3client.presignedPostObject("my-file.txt", {
  expirySeconds: 3600, // URL expires in 1 hour
  fields: {
    "Content-Type": "text/plain",
  },
});

// In the browser, use the policy for direct uploads:
const formData = new FormData();
// Add all required fields from the presigned POST
Object.entries(fields).forEach(([key, value]) => {
  formData.append(key, value);
});
// Add the file content
formData.append("file", fileInput.files[0]);

// Upload the object using the presigned POST
const response = await fetch(url, {
  method: "POST",
  body: formData,
});

if (response.ok) {
  console.log("File uploaded successfully!");
}

For more examples, check out the tests in integration.ts

Developer notes

To run the tests, please use:

deno lint && deno test

To format the code, use:

deno fmt

To run the integration tests, first start RustFS with this command:

docker run --rm --name rustfs -e RUSTFS_ACCESS_KEY=AKIA_DEV -e RUSTFS_SECRET_KEY=secretkey -e RUSTFS_REGION=dev-region -e RUSTFS_CONSOLE_ENABLE=true -p 9000:9000 -p 9001:9001 --entrypoint /bin/sh rustfs/rustfs:1.0.4 -c 'mkdir -p /data/dev-bucket && exec /entrypoint.sh rustfs'

Then while RustFS is running, run

deno test --allow-net integration.ts

(If you encounter issues and need to debug what RustFS is seeing, you can browse the bucket using the web console at http://localhost:9001/rustfs/console/index.html (log in with the access key and secret key above) and view the server's warning/error logs with this command:)

docker exec rustfs tail -f /logs/rustfs.log

版本与发布记录

@bradenmacdonald/s3-lite-client 共发布 4 个版本,首次发布于 2026/03/30;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.1latest2026/10/309 天前
1.0.02026/08/142 个月前
0.9.62026/03/307 个月前
0.9.52026/03/307 个月前

关于 @bradenmacdonald/s3-lite-client 的常见问题

@bradenmacdonald/s3-lite-client 是什么?

A lightweight S3 client.

如何安装 @bradenmacdonald/s3-lite-client?

在项目目录运行 npm install @bradenmacdonald/s3-lite-client,或使用 pnpm add / yarn add / bun add。

@bradenmacdonald/s3-lite-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bradenmacdonald/s3-lite-client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bradenmacdonald/s3-lite-client 可以商用吗?

@bradenmacdonald/s3-lite-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bradenmacdonald/s3-lite-client 的下载量有多少?

根据 npm 官方下载统计,@bradenmacdonald/s3-lite-client 在 2026/10/09 – 2026/11/07 这 30 天内被下载 12,880 次,日均约 429 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bradenmacdonald/s3-lite-client 还在维护吗?

最新版本 1.0.1 发布于 2026/10/30(9 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/03/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。