# @effect-aws/s3 中文文档

规范地址：https://npmcn.com/package/%40effect-aws/s3/

版本：1\.0\.0
npm 元数据更新时间：2026-10-02T14:21:14.535Z
中文译文更新时间：2026-11-13T08:16:50.457Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40effect-aws/s3
原文对照：https://npmcn.com/package/%40effect-aws/s3/?lang=original
项目主页：https://floydspace.github.io/effect-aws/docs/s3
源码仓库：https://github.com/floydspace/effect-aws

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：72.9 kB，31 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：effect \>=4\.0\.0-beta\.66 \<5\.0\.0，@effect-aws/client-s3 ^2\.0\.0
- 首次发布：2025-03-29T00:06:47.195Z
- 最新版本发布：2026-10-02T14:21:14.256Z
- 近 30 天下载量：4768（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：19（近 12 个月 11 个）

## 中文简介

有效的 AWS S3 函数

## 安装

```sh
npm install @effect-aws/s3
```

也可以使用：`pnpm add @effect-aws/s3`、`yarn add @effect-aws/s3`、`bun add @effect-aws/s3`

## README

# @ affect-aws/s3 (英语)

[![npm version](https://img.shields.io/npm/v/%40effect-aws%2Fs3?color=brightgreen&label=npm%20package)](https://www.npmjs.com/package/@effect-aws/s3) [![npm downloads](https://img.shields.io/npm/dm/%40effect-aws%2Fs3)](https://www.npmjs.com/package/@effect-aws/s3)

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

## 安装

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

## 使用量

### 使用 `MultipartUpload`

这个 `MultipartUpload` 是一个有效的端口 `Upload` 类从 [`@aws-sdk/lib-storage`](https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-storage) 软件包.

**示例**

```ts
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` 用于平台 [文件系统](https://effect.website/docs/platform/file-system) 标签. 您可以用它来操作 S3 桶中的文件, 好像它们是本地文件一样 .

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

```ts
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`](https://effect.website/docs/platform/key-value-store/#schemastore):

```ts
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 是什么？

有效的 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 和提交记录判断。

