mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-24 18:52:37 +03:00
29 lines
506 B
JavaScript
29 lines
506 B
JavaScript
const fs = require('fs');
|
|
|
|
class File {
|
|
constructor(path) {
|
|
this.path = path;
|
|
this.content = null;
|
|
}
|
|
|
|
read() {
|
|
try {
|
|
const content = fs.readFileSync(this.path, { encoding: 'utf-8' });
|
|
this.content = content;
|
|
return this.content;
|
|
} catch (err) {
|
|
return err.message;
|
|
}
|
|
}
|
|
|
|
write(data, isJSON) {
|
|
this.content = data;
|
|
fs.writeFileSync(
|
|
this.path,
|
|
isJSON ? JSON.stringify(this.content) : this.content
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = File;
|