tapbundle-fs/readme.md
2024-04-14 18:37:25 +02:00

110 lines
4.9 KiB
Markdown

# @push.rocks/tapbundle-fs
an fs extension for tapbundle
## Install
To install `@push.rocks/tapbundle-fs`, you need to have Node.js installed on your system. If you have Node.js and npm (Node Package Manager) set up, you can install this package by running the following command in your terminal:
```bash
npm install @push.rocks/tapbundle-fs --save
```
Make sure you are in your project directory or have a `package.json` file in your current directory where you are running the npm install command. This will add `@push.rocks/tapbundle-fs` as a dependency to your project.
## Usage
This package is designed to extend `tapbundle` with file system functionalities, leveraging the capabilities of `@pushrocks/smartfile` for enhanced file handling in Node.js projects. Below are some examples of how to utilize `@push.rocks/tapbundle-fs` in your TypeScript projects using ESM syntax.
### Basic Setup
First, you need to import the functionalities you want to use from `@push.rocks/tapbundle-fs`.
```typescript
import * as tapbundleFs from '@push.rocks/tapbundle-fs';
```
### Using smartfile functionalities
`@push.rocks/tapbundle-fs` exports all functionalities from `@pushrocks/smartfile`, which allows you to perform various file system operations such as reading from, writing to files, and more.
#### Reading a File
To read a file from the filesystem, you can use the `readFile` function from the `smartfile` export.
```typescript
import { smartfile } from '@push.rocks/tapbundle-fs';
async function readMyFile() {
const filePath = './myFile.txt';
const fileContent = await smartfile.fs.readTextFile(filePath);
console.log(fileContent);
}
readMyFile();
```
The `readTextFile` method is asynchronous and returns a promise that resolves to the content of the file as a string.
#### Writing to a File
Similarly, to write content to a file, utilize the `writeFile` function.
```typescript
import { smartfile } from '@push.rocks/tapbundle-fs';
async function writeMyFile() {
const filePath = './myNewFile.txt';
const fileContent = 'Hello, World!';
await smartfile.fs.writeTextFile(filePath, fileContent);
console.log('File written successfully');
}
writeMyFile();
```
#### Working with JSON Files
`smartfile` also simplifies working with JSON files with `readJsonFile` and `writeJsonFile`.
```typescript
import { smartfile } from '@push.rocks/tapbundle-fs';
async function readAndWriteJson() {
const filePath = './myData.json';
const data = await smartfile.fs.readJsonFile(filePath);
console.log('Data:', data);
data.newField = 'New value';
await smartfile.fs.writeJsonFile(filePath, data);
console.log('JSON file updated successfully');
}
readAndWriteJson();
```
### Conclusion
`@push.rocks/tapbundle-fs` extends `tapbundle` to incorporate file system functionalities seamlessly into your testing workflow, powered by `@pushrocks/smartfile`. With this package, you have a powerful set of tools to manipulate files in your Node.js applications, making it easier to handle a variety of file operations including reading, writing, and modifying files.
Remember, the key to effectively utilizing `@push.rocks/tapbundle-fs` lies in understanding the underlying `@pushrocks/smartfile` package. For more comprehensive operations and features such as glob patterns, file copying, and directory scanning, refer to the `@pushrocks/smartfile` documentation.
By integrating file system operations within your `tapbundle` tests or Node.js applications, you can automate and enhance your testing and file handling capabilities, ensuring a more robust and maintainable codebase.
## 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](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.