This is a simple Node.js class for reading and writing files. It was writen in typescript then into javascript by me (atom06) for the nexus project
github || npm (you can use the same to download in yarn/pnpm)
import File from 'File.js';
const file = new File('test.txt');
file.init()
// 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);
}
Create a new File instance with the given file name opening that file.
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).
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).
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).
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.
- Reading directorys (Before June 1st)
- Temporary cache when reading, writing and appending to files improving speed (After May)
v1.1.2
readme update