2.1.0 • Published 1 year ago

@atom06/file v2.1.0

Weekly downloads
-
License
SEE LICENSE IN li...
Repository
-
Last release
1 year ago

File Class v2.1.0

This is a simple Node.js class for reading and writing files. It is written in typescript by me (atom06) for the nexus project

github || npm (you can use the same to download in yarn/pnpm)

Usage

import IO from '@atom06/file';

const file = new IO('test.txt');

// Write data to the file
const [writeSuccess, writeError] = await file.write('Hello, world!');

if (writeSuccess) {
  console.log('Data written to file successfully.');
} else {
  console.error('Error writing to file:', writeError);
}

// Append data to the file
const [appendSuccess, appendError] = await file.append('New data to append.');

if (appendSuccess) {
  console.log('Data appended to file successfully.');
} else {
  console.error('Error appending to file:', appendError);
}

// Read data from the file
const [readSuccess, data] = await file.read();

if (readSuccess) {
  console.log('File data:', data);
} else {
  console.error('Error reading file:', data);
}

API

new File(fileName): File

Create a new File instance with the given file name opening that file.

file.write(data: string): Promise<boolean, string | unknown>

Write data to the file. Returns a promise that resolves to a tuple containing a boolean indicating success (true) or failure (false) and either undefined (if successful) or an error object (if failed).

file.read(): Promise<boolean, string | unknown>

Read the contents of the file. Returns a promise that resolves to a tuple containing a boolean indicating success (true) or failure (false) and either the contents of the file (if successful) or an error object (if failed).

file.append(data: string): Promise<boolean, string | unknown>

Append data to the end of the file. Returns a promise that resolves to a tuple containing a boolean indicating success (true) or failure (false) and either undefined (if successful) or an error object (if failed).

License

This code is licensed which allows for free use and modification as long as the original author (Atom06) is credited and the license is included in all versions of the code and the code is not sublicensed or/and sold.

Upcoming features

  • Reading directorys (Before June 1st)
  • Temporary cache when reading, writing and appending to files improving speed (After May)
2.1.0

1 year ago

2.0.0

1 year ago

1.2.2

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago