fix(core): update
This commit is contained in:
parent
50cc3fa8bf
commit
255cc844ad
@ -10,11 +10,11 @@
|
|||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartfile",
|
"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",
|
"npmPackagename": "@push.rocks/smartfile",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"files management",
|
"file management",
|
||||||
"TypeScript",
|
"TypeScript",
|
||||||
"Node.js",
|
"Node.js",
|
||||||
"file operations",
|
"file operations",
|
||||||
@ -23,7 +23,15 @@
|
|||||||
"virtual directory",
|
"virtual directory",
|
||||||
"filesystem utilities",
|
"filesystem utilities",
|
||||||
"memory-efficient file handling",
|
"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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
14
package.json
14
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "@push.rocks/smartfile",
|
"name": "@push.rocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "11.0.14",
|
"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",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"url": "git+https://gitlab.com/push.rocks/smartfile.git"
|
"url": "git+https://gitlab.com/push.rocks/smartfile.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"files management",
|
"file management",
|
||||||
"TypeScript",
|
"TypeScript",
|
||||||
"Node.js",
|
"Node.js",
|
||||||
"file operations",
|
"file operations",
|
||||||
@ -25,7 +25,15 @@
|
|||||||
"virtual directory",
|
"virtual directory",
|
||||||
"filesystem utilities",
|
"filesystem utilities",
|
||||||
"memory-efficient file handling",
|
"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 <hello@lossless.com> (https://lossless.com)",
|
"author": "Lossless GmbH <hello@lossless.com> (https://lossless.com)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
116
readme.md
116
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`:
|
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
|
```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`
|
### Working with `SmartFile`
|
||||||
@ -53,14 +53,13 @@ const largeFile: StreamFile = await StreamFile.fromPath('./largeInput/largeFile.
|
|||||||
await largeFile.writeToDisk('./largeOutput/largeFileCopy.mp4');
|
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:
|
Handling multiple files as if they were part of a file system:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const virtualDir = new VirtualDirectory();
|
const virtualDir = await VirtualDirectory.fromFsDirPath('./data/inputDir');
|
||||||
await virtualDir.addSmartfiles([smartFile1, smartFile2]);
|
await virtualDir.saveToDisk('./data/outputDir');
|
||||||
await virtualDir.saveToDisk('./virtualDirOutput');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### File System Operations
|
### File System Operations
|
||||||
@ -94,7 +93,7 @@ For specialized file operations, such as editing the contents of a file or strea
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const smartFileToEdit: SmartFile = await SmartFile.fromFilePath('./editableFile.txt');
|
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();
|
await smartFileToEdit.write();
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -117,13 +116,110 @@ const bufferSmartFile: SmartFile = await SmartFile.fromBuffer('./bufferFile.txt'
|
|||||||
await bufferSmartFile.write();
|
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
|
## License and Legal Information
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartfile',
|
name: '@push.rocks/smartfile',
|
||||||
version: '11.0.14',
|
version: '11.0.15',
|
||||||
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.'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user