File storage utility, covering basic I/O and metadata guessing, and with plugged-in extension, file buffer could be transformed accordingly.
- [x] Read File
- [x] Write File
- [x] Delete File
--
Parameter | Type | Required | Description |
---|---|---|---|
directory | string | true | directory will be used |
autoMkdir | boolean | false | should create folder if directory is not exists |
converters | FileConverter[] | false | inject extensions for file conversion and respective manipulation |
import { LocalStorage } from "@rytass/storages-adapter-local";
import { resolve } from 'path';
const storage = new StorageLocalService({
directory: resolve(__dirname, 'storage'),
});
read file from disk
Parameter | Type | Required | Description |
---|---|---|---|
key | string | true | file name for read |
options.format | string | false | buffer/stream |
const fileStream = await storage.read('targetFile.png');
const fileBuffer = await storage.read('targetFile.png', { options: 'buffer' });
remove file
--
await storage.remove('willRemove.png');
write file to disk
Parameter | Type | Required | Description |
---|---|---|---|
file | InputFile | true | Buffer of Readable stream |