.gitea/workflows | ||
.vscode | ||
test | ||
ts | ||
.gitignore | ||
.npmignore | ||
license | ||
npmextra.json | ||
package.json | ||
pnpm-lock.yaml | ||
readme.md | ||
tsconfig.json |
@push.rocks/smartfile
offers smart ways to work with files in nodejs
Install
To integrate @push.rocks/smartfile
into your project, run:
npm install @push.rocks/smartfile
Usage
@push.rocks/smartfile
provides a robust suite of tools for managing files in Node.js projects using modern TypeScript and ESM syntax. It simplifies numerous file operations such as reading, writing, copying, and streaming files, as well as working with directories and virtual file systems.
Key Features and Classes
SmartFile
: Facilitates reading from and writing to individual files, managing metadata.StreamFile
: Optimizes memory usage by enabling efficient file streaming.VirtualDirectory
: Allows manipulation of a group of files or directories as a virtual file system.
Getting Started with ESM and TypeScript
First, ensure your project supports ESM syntax and TypeScript. Then, begin by importing the desired features from @push.rocks/smartfile
:
import { SmartFile, StreamFile, VirtualDirectory, memory, fs as smartFs } from '@push.rocks/smartfile';
Reading and Writing Files
Reading Files
Reading a JSON file:
const myJsonFile: SmartFile = await SmartFile.fromFilePath('./data.json');
const jsonData = JSON.parse(myJsonFile.contents.toString());
console.log(jsonData);
Writing Files
Writing content to a file:
const filePath: string = './output.txt';
const content: string = 'Hello, SmartFile!';
await memory.toFs(content, filePath);
console.log('File saved successfully.');
Streaming Large Files
For large files, StreamFile
provides a memory-efficient streaming solution:
import { createReadStream } from 'fs';
const sourceStream = createReadStream('./large-video.mp4');
const myStreamFile = await StreamFile.fromStream(sourceStream, 'large-video.mp4');
await myStreamFile.writeToDir('./storage');
console.log('Large file streamed to disk successfully.');
Working with Virtual Directories
VirtualDirectory
abstracts a collection of files allowing operations to be performed as if they were on disk:
const virtualDir = new VirtualDirectory();
virtualDir.addSmartfiles([smartFile1, smartFile2]); // Assuming these are SmartFile instances
await virtualDir.saveToDisk('./virtual-output');
console.log('Virtual directory saved to disk.');
Advanced File Operations
@push.rocks/smartfile
simplifies complex file operations, including:
- Copying directories and files
- Removing files or directories
- Listing files and directories with filters
- Reading file content directly into JavaScript objects
Web File Handling
Handling files from HTTP requests:
@push.rocks/smartfile
offers utilities to work with files from web sources, making it simpler to manage downloads and uploads.
Comprehensive File Management
Whether you're dealing with local files, directories, or files over the internet, @push.rocks/smartfile
provides a comprehensive set of tools to streamline your workflow and reduce the complexity of file management in your Node.js projects.
License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.