Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.
Go to file
2024-04-03 15:38:58 +02:00
.gitea/workflows fix(core): update 2023-10-12 02:21:39 +02:00
.vscode fix(updated repo structure): update 2022-03-11 09:46:54 +01:00
test fix(core): update 2023-11-04 20:14:20 +01:00
ts fix(core): update 2024-04-03 15:38:58 +02:00
.gitignore fix(core): update 2020-03-15 18:58:46 +00:00
.npmignore add copy 2016-03-14 03:50:14 +01:00
license fix(core): update 2022-06-07 15:50:47 +02:00
npmextra.json fix(core): update 2024-04-02 21:37:31 +02:00
package.json 11.0.8 2024-04-02 21:37:32 +02:00
pnpm-lock.yaml fix(core): update 2023-11-24 19:15:41 +01:00
readme.md fix(core): update 2024-04-02 21:37:31 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:35:01 +02:00

@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.

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.