# @bunny\.net/storage-sdk 中文文档

规范地址：https://npmcn.com/package/%40bunny.net/storage-sdk/

版本：0\.3\.2
npm 元数据更新时间：2026-09-23T15:08:49.649Z
中文译文更新时间：2026-11-08T19:55:55.973Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40bunny.net/storage-sdk
原文对照：https://npmcn.com/package/%40bunny.net/storage-sdk/?lang=original
项目主页：https://github.com/BunnyWay/edge-script-sdk#readme
源码仓库：https://github.com/BunnyWay/edge-script-sdk

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

- 包体积（解压后）：83.4 kB，14 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2025-03-05T09:12:34.060Z
- 最新版本发布：2026-09-23T15:08:49.489Z
- 近 30 天下载量：32095（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：6（近 12 个月 2 个）

## 中文简介

* * *

## 安装

```sh
npm install @bunny.net/storage-sdk
```

也可以使用：`pnpm add @bunny.net/storage-sdk`、`yarn add @bunny.net/storage-sdk`、`bun add @bunny.net/storage-sdk`

## README

# @bunny.net/ storage-sdk (英语)

* * *

[![Bunny](https://github.com/BunnyWay/edge-script-sdk/blob/main/asset/bunny.png?raw=true)](https://bunny.net/)

这个 `@bunny.net/storage-sdk` 一个帮助您互动的库 BunnyCDN存储 API.

# 兔子存储 SDK

此寄存器包含 `@bunny.net/storage-sdk`,一个旨在简化BunnyCDN存储 API的用法的库.

## 使用量

与 `@bunny.net/storage-sdk`您可以与 BunnyCDN 存储 API 交互。 下面是帮助您建立本地服务器的简单例子。 关于其他实例和使用案例,请参见: [示例文件夹](https://npmcn.com/example/)。 。 。 .

### 在您的存储区域中列出文件

```typescript
import * as BunnySDK from "@bunny.net/edgescript-sdk";
import * as BunnyStorageSDK from "@bunny.net/storage-sdk";

let sz_zone = process.env.STORAGE_ZONE!;
let access_key = process.env.STORAGE_ACCESS_KEY!;

let sz = BunnyStorageSDK.zone.connect_with_accesskey(BunnyStorageSDK.regions.StorageRegion.Falkenstein, sz_zone, access_key);

console.log("Starting server...");

BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => {
  let list = await BunnyStorageSDK.file.list(sz, "/");
  console.log(`[INFO]: ${req.method} - ${req.url}`);
  return new Response(JSON.stringify(list));
});
```

此示例使用 Bunny Edge 脚本 SDK 设置了本地的 HTTP 服务器,使用 BunnyCDN 存储 SDK 在存储区列出文件 。 您可以在127.0.0.1:8080访问服务器并观察实时请求日志.

### 快速启动

-   [列表](https://npmcn.com/package/%40bunny.net/storage-sdk/#readme-listing-files)
-   [删除](https://npmcn.com/package/%40bunny.net/storage-sdk/#readme-remove-files-or-directory)
-   [上传](https://npmcn.com/package/%40bunny.net/storage-sdk/#readme-uploading-a-file)
-   [下载](https://npmcn.com/package/%40bunny.net/storage-sdk/#readme-download-a-file)

#### 获取文件

获取文件时, 您可以获取文件的元数据, 或是内容 文档.

元数据描述文件.

```typescript
import * as BunnyStorageSDK from "@bunny.net/storage-sdk";

let storageZone = BunnyStorageSDK.zone.connect_with_accesskey(BunnyStorageSDK.regions.StorageRegion.Falkenstein, "storage-zone-name", "token")
let obj = await BunnyStorageSDK.file.get(storageZone, "/my-folder/my-file");

/*
 * Here obj will be equal to something like this:
const obj = {
    Guid: '123',
    UserId: 'user1',
    LastChanged: '2023-01-01T00:00:00Z',
    DateCreated: '2022-01-01T00:00:00Z',
    StorageZoneName: 'test-zone',
    Path: '/test/path',
    ObjectName: 'test-file.txt',
    Length: 100,
    StorageZoneId: 1,
    IsDirectory: false,
    ServerId: 1,
    Checksum: 'abc123',
    ReplicatedZones: 'UK,NY',
    ContentType: 'text/plain',
    data: () => Promise<{
      stream: ReadableStream<Uint8Array>;
      response: Response;
      length?: number;
    }>,

};
*/
```

在此元数据中, 您可以使用 `await obj.data()`。 。 。 .

#### 列出文件

您可以使用 :

```typescript
let list = await BunnyStorageSDK.file.list(sz, "/");
```

这将给你一个可以浏览的文件元数据列表.

#### 上传文件

要上传一个文件,我们就用杠杆 **流线** 以允许的方式上传文件 在不提供完整内容流的情况下上传文件.

```typescript
export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream<Uint8Array>, options?: UploadOptions): Promise<boolean>;
export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream<Uint8Array>): Promise<boolean>;
export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream<Uint8Array>, options?: UploadOptions): Promise<boolean>;

export type UploadOptions = {
  /**
   * The SHA256 Checksum associated to the data you want to send. If null then
   * the server will automatically calculate it.
   */
  sha256Checksum?: string;
  /**
   * You can override the content-type of the file you upload with this option.
   */
  contentType?: string;
};
```

示例

```typescript
await BunnyStorageSDK.file.upload(sz, "/some-file", random_bytes_10kb);
```

#### 下载文件

要压低文件, 你有两种选择, 要么使用此功能 直接下载.

```typescript
export async function download(storageZone: StorageZone.StorageZone, path: string): Promise<{
  stream: ReadableStream<Uint8Array>;
  response: Response;
  length?: number;
}>;
```

示例

```typescript
await BunnyStorageSDK.file.download(sz, "/some-file");
```

你会有内容流 和相关的反应 和长度 如果有的话.

你也可以用这个 `data` 文件元数据中可用的函数.

#### 删除文件或目录

```typescript
export async function remove(storageZone: StorageZone.StorageZone, path: string): Promise<boolean>;
export async function removeDirectory(storageZone: StorageZone.StorageZone, path: string): Promise<boolean>;
```

示例

```typescript
await BunnyStorageSDK.file.remove(sz, "/some-file");
```

## 常见问题

### 如何安装 @bunny\.net/storage-sdk？

在项目目录运行 npm install @bunny\.net/storage-sdk，或使用 pnpm add / yarn add / bun add。

### @bunny\.net/storage-sdk 支持 TypeScript 吗？

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

### @bunny\.net/storage-sdk 支持 ESM 还是 CommonJS？

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

### @bunny\.net/storage-sdk 可以商用吗？

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

### @bunny\.net/storage-sdk 的下载量有多少？

根据 npm 官方下载统计，@bunny\.net/storage-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 32,095 次，日均约 1,070 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bunny\.net/storage-sdk 还在维护吗？

最新版本 0\.3\.2 发布于 2026/09/23（1 个月前）；至今共发布 6 个版本，其中过去 12 个月发布了 2 个；首次发布于 2025/03/05。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

