@ducktors/storagebus-local

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

npm version License: MIT

此软件包已被标记为弃用

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

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. API
  4. Constructor Options
  5. Methods
  6. Path Resolution
  7. License

@ducktors/storagebus-local

npm version License: MIT

Local filesystem storage adapter for Storagebus.

Installation

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

Usage

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

Constructor Options

You must provide exactly one of rootFolder or bucket:

OptionTypeRequiredDescription
rootFolderstringYes*Root directory for file storage
bucketstringYes*Alias for rootFolder
debugbooleanNoEnable debug logging
loggerLoggerNoCustom logger instance
sanitizeKeyboolean | (key: string) => stringNoSanitize file keys

*Either rootFolder or bucket must be provided, but not both.

Methods

MethodSignatureDescription
write(filePath: string, fileReadable: Readable) => Promise<string>Write a file to storage. Creates subdirectories automatically
exists(filePath: string) => Promise<boolean>Check if a file exists
read(filePath: string) => Promise<Readable>Read a file from storage
remove(filePath: string) => Promise<void>Delete a file from storage
copy(filePath: string, destFilePath: string) => Promise<string>Copy a file. Creates destination subdirectories automatically
move(filePath: string, destFilePath: string) => Promise<string>Move a file. Handles cross-device moves automatically

Path Resolution

  • Absolute paths: Used as-is
  • Relative paths: Placed inside the system's temp directory (os.tmpdir())

The root directory is created automatically if it doesn't exist.

License

MIT

版本与发布记录

@ducktors/storagebus-local 共发布 7 个版本,首次发布于 2022/11/29;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.12.4latest2025/12/2010 个月前
0.12.32023/03/023 年前
0.12.22023/02/043 年前
0.12.12023/01/173 年前
0.12.02022/12/063 年前
0.11.02022/11/303 年前

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

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