@ducktors/storagebus-abstract

中文文档
0.10.4发布于 2025/12/20MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1.3万

npm version License: MIT

此软件包已被标记为弃用

Package renamed to @storagebus/storage. Please migrate to @storagebus/storage@^1.0.0.

中文使用文档
文档目录8 节
  1. 安装
  2. 使用量
  3. 创建自定义适配器
  4. API 密码
  5. 构造选项
  6. 摘要方法
  7. 帮助方法
  8. 许可证

@ducktors/ storagebus-抽象

npm version License: MIT

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

安装

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

使用量

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

创建自定义适配器

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 密码

构造选项

选项类型默认说明
debugbooleanfalse启用调试日志
loggerLoggerdefaultLogger自定义日志实例
sanitizeKeyboolean | (key: string) => stringfalse将文件密钥设置为安全 。 何时 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 共发布 5 个版本,首次发布于 2022/11/29;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.4latest2025/12/2010 个月前
0.10.32023/03/023 年前
0.10.22023/02/043 年前
0.10.12023/01/173 年前
0.10.02022/11/293 年前

关于 @ducktors/storagebus-abstract 的常见问题

如何安装 @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。作者已将其标记为弃用,新项目建议寻找替代方案。