Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/lib/lowdb/adapters/TextFileSync.js
2591 views
1
//═══════════════════════════════════════════════════════//
2
//If you want to recode, reupload
3
//or copy the codes/script,
4
//pls give credit
5
//no credit? i will take action immediately
6
//© 2022 Xeon Bot Inc. Cheems Bot MD
7
//Thank you to Lord Buddha, Family and Myself
8
//════════════════════════════//
9
const fs = require('fs');
10
const path = require('path');
11
class TextFileSync {
12
constructor(filename) {
13
this.filename = filename;
14
this.tempFilename = path.join(path.dirname(filename), `.${path.basename(filename)}.tmp`);
15
}
16
read() {
17
let data;
18
try {
19
data = fs.readFileSync(this.filename, 'utf-8');
20
}
21
catch (e) {
22
if (e.code === 'ENOENT') {
23
return null;
24
}
25
throw e;
26
}
27
return data;
28
}
29
write(str) {
30
fs.writeFileSync(this.tempFilename, str);
31
fs.renameSync(this.tempFilename, this.filename);
32
}
33
}
34
module.exports = { TextFileSync };
35
36