File size: 578 Bytes
a2b2aac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
const fs = require('fs');
const { Writer } = require('steno');
class TextFile {
constructor(filename) {
this.filename = filename;
this.writer = new Writer(filename);
}
async read() {
let data;
try {
data = await fs.promises.readFile(this.filename, 'utf-8');
}
catch (e) {
if (e.code === 'ENOENT') {
return null;
}
throw e;
}
return data;
}
write(str) {
return this.writer.write(str);
}
}
module.exports = { TextFile }; |