diff --git a/npmextra.json b/npmextra.json index 67d3f4d..238eb78 100644 --- a/npmextra.json +++ b/npmextra.json @@ -10,11 +10,11 @@ "githost": "code.foss.global", "gitscope": "push.rocks", "gitrepo": "smartfile", - "description": "provides a robust suite of tools for managing files in Node.js using TypeScript.", + "description": "Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.", "npmPackagename": "@push.rocks/smartfile", "license": "MIT", "keywords": [ - "files management", + "file management", "TypeScript", "Node.js", "file operations", @@ -23,7 +23,15 @@ "virtual directory", "filesystem utilities", "memory-efficient file handling", - "custom file operations" + "custom file operations", + "write files", + "read files", + "copy files", + "delete files", + "list directories", + "handle large files", + "virtual filesystems", + "buffer operations" ] } }, diff --git a/package.json b/package.json index 0da6e70..27dce13 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@push.rocks/smartfile", "private": false, "version": "11.0.14", - "description": "provides a robust suite of tools for managing files in Node.js using TypeScript.", + "description": "Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.", "main": "dist_ts/index.js", "typings": "dist_ts/index.d.ts", "type": "module", @@ -16,7 +16,7 @@ "url": "git+https://gitlab.com/push.rocks/smartfile.git" }, "keywords": [ - "files management", + "file management", "TypeScript", "Node.js", "file operations", @@ -25,7 +25,15 @@ "virtual directory", "filesystem utilities", "memory-efficient file handling", - "custom file operations" + "custom file operations", + "write files", + "read files", + "copy files", + "delete files", + "list directories", + "handle large files", + "virtual filesystems", + "buffer operations" ], "author": "Lossless GmbH (https://lossless.com)", "license": "MIT", diff --git a/readme.md b/readme.md index 1cae708..7e3a1f2 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,7 @@ npm install @push.rocks/smartfile First, ensure you're working in an environment that supports ECMAScript modules (ESM) and TypeScript. Here’s how you’d generally import and use `@push.rocks/smartfile`: ```typescript -import { SmartFile, StreamFile, VirtualDirectory, fs, memory } from '@push.rocks/smartfile'; +import { SmartFile, StreamFile, VirtualDirectory, fs, memory, interpreter } from '@push.rocks/smartfile'; ``` ### Working with `SmartFile` @@ -53,14 +53,13 @@ const largeFile: StreamFile = await StreamFile.fromPath('./largeInput/largeFile. await largeFile.writeToDisk('./largeOutput/largeFileCopy.mp4'); ``` -### Managing Virtual Directories +### Working with Virtual Directories Handling multiple files as if they were part of a file system: ```typescript -const virtualDir = new VirtualDirectory(); -await virtualDir.addSmartfiles([smartFile1, smartFile2]); -await virtualDir.saveToDisk('./virtualDirOutput'); +const virtualDir = await VirtualDirectory.fromFsDirPath('./data/inputDir'); +await virtualDir.saveToDisk('./data/outputDir'); ``` ### File System Operations @@ -94,7 +93,7 @@ For specialized file operations, such as editing the contents of a file or strea ```typescript const smartFileToEdit: SmartFile = await SmartFile.fromFilePath('./editableFile.txt'); -await smartFileToEdit.editContentAsString((content) => content.replace(/originalText/g, 'newText')); +await smartFileToEdit.editContentAsString(async (content) => content.replace(/originalText/g, 'newText')); await smartFileToEdit.write(); ``` @@ -117,13 +116,110 @@ const bufferSmartFile: SmartFile = await SmartFile.fromBuffer('./bufferFile.txt' await bufferSmartFile.write(); ``` -#### Uploading a File +### Using `VirtualDirectory` for Complex File Management -Stream files or buffers can be integrated with web frameworks to handle file uploads efficiently, utilizing streams to reduce memory footprint. +`VirtualDirectory` simplifies the management of multiple files that are otherwise scattered across different directories or created at runtime. -### Conclusion +#### Creating a `VirtualDirectory` -With `@push.rocks/smartfile`, managing files in Node.js using TypeScript becomes significantly more straightforward and efficient. Utilizing the provided classes and methods, you can handle a wide range of file operations, from basic read/write tasks to complex operations such as virtual directory management and file streaming, with minimal boilerplate code and maximum efficiency. +To create a `VirtualDirectory` from an existing file directory: + +```typescript +const virtualDirectory = await VirtualDirectory.fromFsDirPath('./someDirectory'); +``` + +#### Adding More Files + +You can add more `SmartFile` instances to your `VirtualDirectory`: + +```typescript +const additionalFiles = [ + await SmartFile.fromFilePath('./anotherDirectory/file1.txt'), + await SmartFile.fromFilePath('./anotherDirectory/file2.txt') +]; +virtualDirectory.addSmartfiles(additionalFiles); +``` + +#### Saving `VirtualDirectory` to Disk + +Save your entire `VirtualDirectory` to disk: + +```typescript +await virtualDirectory.saveToDisk('./outputDirectory'); +``` + +### Utilizing StreamFile for Efficient File Handling + +Using `StreamFile` can be especially beneficial for large files or when performing streaming operations. + +#### Streaming from a URL + +`StreamFile` provides capabilities to stream files directly from URLs, making it easier to work with remote content. + +```typescript +const urlStreamFile: StreamFile = await StreamFile.fromUrl('https://example.com/largefile.zip'); +await urlStreamFile.writeToDisk('./downloadedFiles/largefile.zip'); +``` + +### Combining Buffer and Stream Approaches + +Create `StreamFile` from a buffer for efficient, multi-use streams. + +```typescript +const buffer = Buffer.from('Streaming buffer content'); +const bufferStreamFile = StreamFile.fromBuffer(buffer, 'bufferBasedStream.txt'); +await bufferStreamFile.writeToDisk('./streams/bufferBasedStream.txt'); +``` + +### Read and Write Operations with StreamFile + +Perform read and write operations efficiently using `StreamFile`. + +```typescript +const fileStream = await StreamFile.fromPath('./inputData/largeFile.data'); +await fileStream.writeToDisk('./outputData/largeFileCopy.data'); +``` + +Check for completeness of your read and write operations, ensuring the integrity of file content. + +```typescript +const readBuffer = await fileStream.getContentAsBuffer(); +console.log(readBuffer.toString()); +``` + +### Ensuring File Readiness for Streaming + +Ensure a file is ready for streaming or create a custom readable stream incorporating data transformation. + +```typescript +const smartReadStream = new SmartReadStream('./incomingData/sample.data'); +smartReadStream.on('data', (chunk) => { + console.log('New Data Chunk:', chunk.toString()); +}); +``` + +### File Transformation with SmartReadStream + +Perform transformations on the stream of data while reading: + +```typescript +smartReadStream.on('data', (chunk) => { + // Perform some transformation + const transformedChunk = chunk.toString().toUpperCase(); + console.log('Transformed Data Chunk:', transformedChunk); +}); +``` + +### Streaming with SmartReadStream + +Stream data from a `SmartReadStream` to a file efficiently managing large datasets. + +```typescript +const transformedWriteStream = fs.createWriteStream('./processedData/transformed.data'); +smartReadStream.pipe(transformedWriteStream); +``` + +`@push.rocks/smartfile` significantly simplifies the handling of complex file operations in Node.js projects, making these tasks straightforward while maintaining efficiency and ease of use. Explore and leverage these features to enhance your project's file management capabilities. ## License and Legal Information diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 0ec1405..ec98396 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartfile', - version: '11.0.14', - description: 'provides a robust suite of tools for managing files in Node.js using TypeScript.' + version: '11.0.15', + description: 'Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.' }