@effect-aws/s3

中文文档
1.0.0发布于 2026/10/02MITTypeScriptES Module零依赖近 30 天下载 4768

有效的 AWS S3 函数

中文使用文档
文档目录4 节
  1. 安装
  2. 使用量
  3. 使用 MultipartUpload
  4. 使用 S3FileSystem

@ affect-aws/s3 (英语)

npm version npm downloads

这个软件包提供了 S3 具体有效的公用事业和执行.

安装

npm install --save @effect-aws/s3 @effect-aws/client-s3

使用量

使用 MultipartUpload

这个 MultipartUpload 是一个有效的端口 Upload 类从 @aws-sdk/lib-storage 软件包.

示例

import { S3 } from "@effect-aws/client-s3"
import { MultipartUpload } from "@effect-aws/s3"
import { FileSystem } from "@effect/platform"
import { Effect } from "effect"

const program = MultipartUpload.uploadObject(
  {
    Bucket: "my-bucket",
    Key: "my-object",
    Body: new Uint8Array(1024 * 1024 * 10) // 10 MB
  },
  {
    // (optional) concurrency configuration
    queueSize: 4,
    // (optional) size of each part, in bytes, at least 5MB
    partSize: FileSystem.MiB(5)
  }
)

program.pipe(Effect.provide(S3.defaultLayer), Effect.runPromise)

使用 S3FileSystem

这个 S3FileSystem 用于平台 文件系统 标签. 您可以用它来操作 S3 桶中的文件, 好像它们是本地文件一样 .

示例 (将文件读作字符串)

import { S3 } from "@effect-aws/client-s3"
import { S3FileSystem } from "@effect-aws/s3"
import { FileSystem } from "@effect/platform"
import { NodeRuntime } from "@effect/platform-node"
import { Effect } from "effect"

const program = Effect.gen(function* () {
  const fs = yield* FileSystem.FileSystem

  // Reading the content of the same file where this code is written
  const content = yield* fs.readFileString("content.txt")
  console.log(content)
})

// Provide the necessary context and run the program
NodeRuntime.runMain(
  program.pipe(
    //                            ┌─── Layer<FileSystem, never, S3Service>
    //                            ▼
    Effect.provide(S3FileSystem.layer({ bucketName: "example-bucket" })),
    Effect.provide(S3.defaultLayer)
  )
)

示例 (单位:千美元)使用 Schema 校验 KeyValueStore:

import { S3 } from "@effect-aws/client-s3"
import { S3FileSystem } from "@effect-aws/s3"
import { Path } from "@effect/platform"
import { KeyValueStore } from "@effect/platform"
import { Effect, Layer, Schema } from "effect"

// Define a schema for the values
const Person = Schema.Struct({
  name: Schema.String,
  age: Schema.Number
})

const program = Effect.gen(function* () {
  // Create a SchemaStore based on the Person schema
  const kv = (yield* KeyValueStore.KeyValueStore).forSchema(Person)

  // Add a value that adheres to the schema
  const value = { name: "Alice", age: 30 }
  yield* kv.set("user1", value)
  console.log(yield* kv.size)

  // Retrieve and log the value
  console.log(yield* kv.get("user1"))
})

// Slash is important here, indicating a folder ──────┐
//                                                    ▼
const mainLayer = KeyValueStore.layerFileSystem("store/").pipe(
  Layer.provide(S3FileSystem.layer({ bucketName: "example-bucket" })),
  Layer.provide(S3.defaultLayer),
  Layer.provide(Path.layer)
)

// Use the S3 file system store implementation
Effect.runPromise(program.pipe(Effect.provide(mainLayer)))
/*
  Output:
  1
  { _id: 'Option', _tag: 'Some', value: { name: 'Alice', age: 30 } }
  */

版本与发布记录

@effect-aws/s3 共发布 19 个版本,首次发布于 2025/03/29;过去 12 个月发布了 11 个版本。

版本发布日期距今
1.0.0latest2026/10/021 个月前
1.0.0-beta.5beta2026/07/193 个月前
0.3.12026/07/193 个月前
1.0.0-beta.42026/04/156 个月前
1.0.0-beta.32026/03/128 个月前
0.3.02026/03/118 个月前

关于 @effect-aws/s3 的常见问题

@effect-aws/s3 是什么?

有效的 AWS S3 函数

如何安装 @effect-aws/s3?

在项目目录运行 npm install @effect-aws/s3,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:effect(>=4.0.0-beta.66 <5.0.0)、@effect-aws/client-s3(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@effect-aws/s3 支持 TypeScript 吗?

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

@effect-aws/s3 支持 ESM 还是 CommonJS?

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

@effect-aws/s3 可以商用吗?

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

@effect-aws/s3 的下载量有多少?

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

@effect-aws/s3 还在维护吗?

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