@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. Installation
  2. Usage
  3. Creating a Custom Adapter
  4. API
  5. Constructor Options
  6. Abstract Methods
  7. Helper Methods
  8. License

@ducktors/storagebus-abstract

npm version License: MIT

Abstract base class for Storagebus storage adapters. This package provides the foundation for creating storage adapters that work with the Storagebus ecosystem.

Installation

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

Usage

This package is intended to be used as a base class for implementing custom storage adapters. If you're looking to use a storage solution directly, check out the available adapters:

Creating a Custom Adapter

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

Constructor Options

OptionTypeDefaultDescription
debugbooleanfalseEnable debug logging
loggerLoggerdefaultLoggerCustom logger instance
sanitizeKeyboolean | (key: string) => stringfalseSanitize file keys. When true, uses built-in sanitizer. Can also be a custom function

Abstract Methods

All storage adapters must implement these methods:

MethodSignatureDescription
write(fileName: string, fileReadable: Readable) => Promise<string>Write a file to storage
exists(fileName: string) => Promise<boolean>Check if a file exists
read(fileName: string) => Promise<Readable>Read a file from storage
remove(fileName: string) => Promise<void>Delete a file from storage
copy(key: string, destKey: string) => Promise<string>Copy a file within storage
move(key: string, destKey: string) => Promise<string>Move a file within storage

Helper Methods

MethodSignatureDescription
toBuffer(readableStream: Readable) => Promise<Buffer>Convert a readable stream to a Buffer

License

MIT

版本与发布记录

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