SmartFile is a comprehensive toolkit for file manipulation in Node.js. It provides functionalities for working with the filesystem, in-memory operations, streaming, and handling virtual directories. Below, you will find examples showcasing how to utilize these functionalities effectively.
### Basic File Operations
For reading and writing files, SmartFile provides synchronous and asynchronous methods. Here’s how you can use them:
#### Async Write to File
```typescript
import { memory } from '@push.rocks/smartfile';
const myData: string = 'Hello, SmartFile!';
// Writing string data to a file asynchronously
memory.toFs(myData, './data/hello.txt');
```
#### Sync Write to File
```typescript
import { memory } from '@push.rocks/smartfile';
const myData: string = 'Hello, World!';
// Writing string data to a file synchronously
memory.toFsSync(myData, './data/helloSync.txt');
```
### Working with Streams
Streaming files to and from the filesystem is made easy with SmartFile. Here’s an example:
SmartFile simplifies handling files in a Node.js environment, providing a concise, promise-based API for various file operations, stream handling, and in-memory file manipulation. Whether you're dealing with physical files on the disk, manipulating file streams, or managing virtual files and directories, SmartFile has got you covered.
SmartFile is licensed under the MIT License. This permissive license is short and to the point. It lets people do anything they want with your code as long as they provide attribution back to you and don’t hold you liable.