@rocketmakers/storage
v0.3.1
Published
This package provides a convenient way to interact with local storage for your development or local environment. This package allows you to perform various operations on files stored locally, such as copying, deleting, reading, and creating.
Downloads
5,456
Keywords
Readme
@rocketmakers/storage - Local
This package provides a convenient way to interact with local storage for your development or local environment. This package allows you to perform various operations on files stored locally, such as copying, deleting, reading, and creating.
Installation
To use this package, you can install it via npm:
npm install @rocketmakers/storage
yarn add @rocketmakers/storage
pnpm add @rocketmakers/storage
LocalStorage
Usage
Here's an example of how you can use the LocalStorage
class in your Node.js application:
import { LocalStorage, ILocalStorageConfig } from '@rocketmakers/storage';
// Configuration for local storage
const localStorageConfig: ILocalStorageConfig = {
local: {
rootPath: '/path/to/local/storage',
},
};
// Create an instance of LocalStorage
const localStorage = new LocalStorage(localStorageConfig);
// Example: Validate storage
const result = await localStorage.validate();
console.log('Storage validation result:', result);
// Example: Copy a file
const fromFilePath = '/path/to/source/file.txt';
const toFilePath = '/path/to/destination/file.txt';
const success = await localStorage.fileCopy(fromFilePath, toFilePath);
console.log('File copy result:', success);
// ... Other operations (delete, read, create, etc.)
AsyncFs
This package also gives you access to AsyncFs
. AsyncFs
is a TypeScript module that provides asynchronous wrappers for common file system operations. It is designed to work with the Node.js fs module and is particularly useful for handling file-related tasks in an asynchronous, non-blocking manner.
Usage
import { AsyncFs } from '@rocketmakers/storage';
// Example: Check if a file exists asynchronously
const filePath = 'path/to/file.txt';
const fileExists = await AsyncFs.existsAsync(filePath);
console.log(`File ${filePath} exists: ${fileExists}`);
// Example: Read the content of a file asynchronously
const fileContent = await AsyncFs.readFileAsync(filePath);
console.log(`Content of ${filePath}: ${fileContent}`);