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
Implemented
Planned
Implementations / Adapters
Implemented
Planned
Prio 1
Prio 2
Usage
Install the main package and any adapters you might need:
npm i -S @flystorage/file-storage
npm i -S @flystorage/aws-s3
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 {LocalFileStorage} from '@flystorage/local-fs';
const rootDirectory = resolve(process.cwd(), 'my-files');
const storage = new FileStorage(new LocalFileStorage(rootDirectory));
await storage.write('write-from-a-string.txt', 'file contents');
const stream = createReadStream(resolve(process.cwd(), 'test-files/picture.png'));
await storage.write('picture.png', stream);
await storage.write('public.txt', 'debug', {
visibility: Visibility.PUBLIC,
});
await storage.write('private.txt', 'debug', {
visibility: Visibility.PRIVATE,
});
const contentsAsAsyncGenerator = storage.list('', {deep: true});
for await (const item of contentsAsAsyncGenerator) {
console.log(item.path);
if (item.isFile) {
} else if (item.isDirectory) {
}
}
await storage.deleteFile('some-file.txt');
await storage.deleteDirectory('some-directory');
Author
Flystorage is built by the maintainer of Flysystem, a
filesystem abstraction for PHP. This brings along more than
a decade of smoothing over filesystem implementation differences
and weighing trade-offs to make a usable API.