@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. 安装
  2. 使用量
  3. API 密码
  4. 构造选项
  5. 方法
  6. 路径分辨率
  7. 许可证

@ducktors/ storagebus - 当地

npm version License: MIT

本地文件系统存储适配器 存储总线。 。 。 .

安装

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

使用量

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数字 :

选项类型需求说明
rootFolderstring对*文件存储根目录
bucketstring对*别名 rootFolder
debugboolean没有启用调试日志
loggerLogger没有自定义日志实例
sanitizeKeyboolean | (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 共发布 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。作者已将其标记为弃用,新项目建议寻找替代方案。