# @ducktors/storagebus-abstract 中文文档

规范地址：https://npmcn.com/package/%40ducktors/storagebus-abstract/

版本：0\.10\.4
npm 元数据更新时间：2026-06-12T11:20:14.753Z
中文译文更新时间：2026-11-12T23:43:12.556Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40ducktors/storagebus-abstract
原文对照：https://npmcn.com/package/%40ducktors/storagebus-abstract/?lang=original
项目主页：https://github.com/ducktors/storagebus#readme
源码仓库：https://github.com/ducktors/storagebus

弃用说明：Package renamed to @storagebus/storage\. Please migrate to @storagebus/storage@^1\.0\.0\.

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

- 包体积（解压后）：63.5 kB，21 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2022-11-29T12:33:22.289Z
- 最新版本发布：2025-12-19T16:25:53.845Z
- 近 30 天下载量：12575（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 1 个）

## 中文简介

[![npm version](https://img.shields.io/npm/v/@ducktors/storagebus-abstract)](https://www.npmjs.com/package/@ducktors/storagebus-abstract) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## 安装

```sh
npm install @ducktors/storagebus-abstract
```

也可以使用：`pnpm add @ducktors/storagebus-abstract`、`yarn add @ducktors/storagebus-abstract`、`bun add @ducktors/storagebus-abstract`

## README

# @ducktors/ storagebus-抽象

[![npm version](https://img.shields.io/npm/v/@ducktors/storagebus-abstract)](https://www.npmjs.com/package/@ducktors/storagebus-abstract) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

存储巴士存储适配器的抽象基类. 这个包为创建与Surverbus生态系统合作的存储适配器提供了基础.

## 安装

```bash
npm install @ducktors/storagebus-abstract
# or
pnpm add @ducktors/storagebus-abstract
# or
yarn add @ducktors/storagebus-abstract
```

## 使用量

本套件拟用作执行自定义存储适配器的基类. 如果您想直接使用存储溶液,请查看可用的适配器:

-   [@ducktors/ storagebus - 当地](https://www.npmjs.com/package/@ducktors/storagebus-local) - 本地文件系统存储
-   [@ducktors/ streagebus-s3 (英语)](https://www.npmjs.com/package/@ducktors/storagebus-s3) - AWS S3存储器
-   [@ducktors/ staragebus-gcs (英语)](https://www.npmjs.com/package/@ducktors/storagebus-gcs) - 谷歌云存储
-   [@ducktors/ streagebus-memory (英语)](https://www.npmjs.com/package/@ducktors/storagebus-memory) - 记忆存储

### 创建自定义适配器

```typescript
import { Readable } from 'node:stream'
import { Storage, AbstractStorageOptions } from '@ducktors/storagebus-abstract'

interface MyStorageOptions extends AbstractStorageOptions {
  // Add your custom options here
}

class MyStorage extends Storage {
  constructor(opts: MyStorageOptions) {
    super(opts)
  }

  async write(fileName: string, fileReadable: Readable): Promise<string> {
    // Implement write logic
  }

  async exists(fileName: string): Promise<boolean> {
    // Implement exists logic
  }

  async read(fileName: string): Promise<Readable> {
    // Implement read logic
  }

  async remove(fileName: string): Promise<void> {
    // Implement remove logic
  }

  async copy(key: string, destKey: string): Promise<string> {
    // Implement copy logic
  }

  async move(key: string, destKey: string): Promise<string> {
    // Implement move logic
  }
}
```

## API 密码

### 构造选项

| 选项 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| `debug` | `boolean` | `false` | 启用调试日志 |
| `logger` | `Logger` | `defaultLogger` | 自定义日志实例 |
| `sanitizeKey` | `boolean | (key: string) => string` | `false` | 将文件密钥设置为安全 。 何时 `true`,使用内置消毒器. 也可以是自定义函数 |

### 摘要方法

所有存储适配器必须执行这些方法:

| 方法 | 签署 | 说明 |
| --- | --- | --- |
| `write` | `(fileName: string, fileReadable: Readable) => Promise<string>` | 写入要存储的文件 |
| `exists` | `(fileName: string) => Promise<boolean>` | 检查文件是否存在 |
| `read` | `(fileName: string) => Promise<Readable>` | 从存储中读取文件 |
| `remove` | `(fileName: string) => Promise<void>` | 从存储中删除文件 |
| `copy` | `(key: string, destKey: string) => Promise<string>` | 在存储中复制文件 |
| `move` | `(key: string, destKey: string) => Promise<string>` | 在存储中移动文件 |

### 帮助方法

| 方法 | 签署 | 说明 |
| --- | --- | --- |
| `toBuffer` | `(readableStream: Readable) => Promise<Buffer>` | 将可读流转换为缓冲 |

## 许可证

麻省理工学院

## 常见问题

### 如何安装 @ducktors/storagebus-abstract？

在项目目录运行 npm install @ducktors/storagebus-abstract，或使用 pnpm add / yarn add / bun add。

### @ducktors/storagebus-abstract 支持 TypeScript 吗？

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

### @ducktors/storagebus-abstract 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @ducktors/storagebus-abstract 可以商用吗？

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

### @ducktors/storagebus-abstract 的下载量有多少？

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

### @ducktors/storagebus-abstract 还在维护吗？

最新版本 0\.10\.4 发布于 2025/12/20（10 个月前）；至今共发布 5 个版本，其中过去 12 个月发布了 1 个；首次发布于 2022/11/29。作者已将其标记为弃用，新项目建议寻找替代方案。

