# @ducktors/storagebus-local 中文文档

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

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

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

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

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

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

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

## 中文简介

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

## 安装

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

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

## README

# @ducktors/ storagebus - 当地

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

本地文件系统存储适配器 [存储总线](https://github.com/ducktors/storagebus)。 。 。 .

## 安装

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

## 使用量

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

// Using an absolute path
const storage = new Storage({
  rootFolder: '/path/to/storage',
})

// Using a relative path (will be placed in system temp directory)
const storageTmp = new Storage({
  rootFolder: 'my-storage',
})

// Alternative: use 'bucket' instead of 'rootFolder'
const storageAlt = new Storage({
  bucket: '/path/to/storage',
})

async function main() {
  const readable = Readable.from('Hello, world!')

  // Write a file
  const writtenFile = await storage.write('path/to/file.txt', readable)

  // Check if file exists
  const exists = await storage.exists('path/to/file.txt')

  // Read a file
  const fileStream = await storage.read('path/to/file.txt')

  // Copy a file
  const copiedFile = await storage.copy('path/to/file.txt', 'path/to/copy.txt')

  // Move a file
  const movedFile = await storage.move('path/to/copy.txt', 'new/path/file.txt')

  // Delete a file
  await storage.remove('path/to/file.txt')
}
```

## API 密码

### 构造选项

你必须提供其中之一 `rootFolder` 或者说 `bucket`数字 :

| 选项 | 类型 | 需求 | 说明 |
| --- | --- | --- | --- |
| `rootFolder` | `string` | 对\* | 文件存储根目录 |
| `bucket` | `string` | 对\* | 别名 `rootFolder` |
| `debug` | `boolean` | 没有 | 启用调试日志 |
| `logger` | `Logger` | 没有 | 自定义日志实例 |
| `sanitizeKey` | `boolean | (key: string) => string` | 没有 | 将文件密钥设置为安全 |

\*以太过 `rootFolder` 或者说 `bucket` 必须提供,但不能同时提供.

### 方法

| 方法 | 签署 | 说明 |
| --- | --- | --- |
| `write` | `(filePath: string, fileReadable: Readable) => Promise<string>` | 写一个文件到存储 。 自动创建子目录 |
| `exists` | `(filePath: string) => Promise<boolean>` | 检查文件是否存在 |
| `read` | `(filePath: string) => Promise<Readable>` | 从存储中读取文件 |
| `remove` | `(filePath: string) => Promise<void>` | 从存储中删除文件 |
| `copy` | `(filePath: string, destFilePath: string) => Promise<string>` | 复制一个文件。 自动创建目标子目录 |
| `move` | `(filePath: string, destFilePath: string) => Promise<string>` | 移动一个文件。 自动处理交叉设备 |

## 路径分辨率

-   **绝对路径**: 现用
-   **相对路径**: 放在系统临时目录内(`os.tmpdir()`(中文(简体) )

如果根目录不存在,则自动创建.

## 许可证

麻省理工学院

## 常见问题

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

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

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

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

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

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

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

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

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

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

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

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

