@flystorage/file-storage

中文文档
1.2.2发布于 2026/01/24MITTypeScriptESM + CJS零依赖近 30 天下载 8.9万

File-storage abstraction: multiple filesystems, one API.

原始使用文档
文档目录6 节
  1. What is Flystorage NOT:
  2. Capabilities
  3. Adapters
  4. Usage
  5. Local Usage
  6. Author

Flystorage

Flystorage is a file storage abstraction for NodeJS and TypeScript. It is an 80/20 solution that is built around a set of goals:

  • Provide a straight-forward API that is easy to use.
  • Allow application code to be unaware WHERE files are stored.
  • Pragmatically smooth over underlying storage differences.
  • Expose an async/await based API, promises all the way.
  • Abstract over file permissions using "visibility".
  • Actually tested using real integrations, mocks are not welcome.
  • Stand on the shoulders of giants, use official vendor packages when possible.

What is Flystorage NOT:

Flystorage is meant to be used in cases for generic file storage use-cases. It's not an API for any specific filesystem. It's a generalised solution and will not implement feature only specific to one particular storage implementation. There will be use-cases that are not catered to, simply because they cannot be abstracted over in a reasonable manner.

Capabilities

  • Write files using string | buffer | readable/stream
  • Read files as stream, string, or Uint8Array
  • List the contents of a directory/prefix, (shallow and deep).
  • Metadata, such as; mime-type, last modified timestamp, and file size.
  • Expose or calculate checksums for files.
  • Delete files without failing when they don't exist.
  • Set permissions using abstracted visibility
  • Delete directories (and any files it contains)
  • Generate public URLs.
  • Generate temporary (signed) URLs.
  • Secure direct uploads from the browser.
  • Moving files
  • Copying files

Adapters

Usage

Install the main package and any adapters you might need:

npm i -S @flystorage/file-storage

# for using AWS S3
npm i -S @flystorage/aws-s3

# for using the local filesystem
npm i -S @flystorage/local-fs

Local Usage

import {resolve} from 'node:path';
import {createReadStream} from 'node:fs';
import {FileStorage, Visibility} from '@flystorage/file-storage';
import {LocalStorageAdapter} from '@flystorage/local-fs';

/**
 * SETUP
 **/

const rootDirectory = resolve(process.cwd(), 'my-files');
const storage = new FileStorage(new LocalStorageAdapter(rootDirectory));

/**
 * USAGE
 **/

// Write using a string
await storage.write('write-from-a-string.txt', 'file contents');

// Write using a stream
const stream = createReadStream(resolve(process.cwd(), 'test-files/picture.png'));
await storage.write('picture.png', stream);

// Write with visibility (permissions).
await storage.write('public.txt', 'debug', {
    visibility: Visibility.PUBLIC, // mode: 0o644
});
await storage.write('private.txt', 'debug', {
    visibility: Visibility.PRIVATE, // mode: 0o600
});

// List directory contents
const contentsAsAsyncGenerator = storage.list('', {deep: true});

for await (const item of contentsAsAsyncGenerator) {
    console.log(item.path);

    if (item.isFile) {
        // do something with the file
    } else if (item.isDirectory) {
        // do something with the directory
    }
}

// Delete a file
await storage.deleteFile('some-file.txt');

// Delete a directory (with all contents)
await storage.deleteDirectory('some-directory');

Author

Flystorage is built by the maintainer of Flysystem, a filesystem abstraction for PHP. This brings along over a decade of filesystem abstraction experience.

版本与发布记录

@flystorage/file-storage 共发布 22 个版本,首次发布于 2023/11/30;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.2.2latest2026/01/249 个月前
1.2.12025/11/2911 个月前
1.2.02025/09/131.2 年前
1.1.02025/05/131.5 年前
1.0.12025/01/141.8 年前
1.0.02024/12/121.9 年前

关于 @flystorage/file-storage 的常见问题

@flystorage/file-storage 是什么?

File-storage abstraction: multiple filesystems, one API.

如何安装 @flystorage/file-storage?

在项目目录运行 npm install @flystorage/file-storage,或使用 pnpm add / yarn add / bun add。

@flystorage/file-storage 支持 TypeScript 吗?

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

@flystorage/file-storage 支持 ESM 还是 CommonJS?

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

@flystorage/file-storage 可以商用吗?

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

@flystorage/file-storage 的下载量有多少?

根据 npm 官方下载统计,@flystorage/file-storage 在 2026/10/15 – 2026/11/13 这 30 天内被下载 89,091 次,日均约 2,970 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flystorage/file-storage 还在维护吗?

最新版本 1.2.2 发布于 2026/01/24(9 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/11/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。