Download lib/lowdb/adapters/TextFileSync.js from RamaZyx/StableBOT: direct link, hf CLI and curl.
- Browser
- Download file 685 Bytes
-
https://huggingface.co/RamaZyx/StableBOT/resolve/main/lib/lowdb/adapters/TextFileSync.js
- Command line
-
hf download hf://RamaZyx/StableBOT/lib/lowdb/adapters/TextFileSync.js
-
curl -L -o TextFileSync.js https://huggingface.co/RamaZyx/StableBOT/resolve/main/lib/lowdb/adapters/TextFileSync.js
685 Bytes
| const fs = require('fs'); | |
| const path = require('path'); | |
| class TextFileSync { | |
| constructor(filename) { | |
| this.filename = filename; | |
| this.tempFilename = path.join(path.dirname(filename), `.${path.basename(filename)}.tmp`); | |
| } | |
| read() { | |
| let data; | |
| try { | |
| data = fs.readFileSync(this.filename, 'utf-8'); | |
| } | |
| catch (e) { | |
| if (e.code === 'ENOENT') { | |
| return null; | |
| } | |
| throw e; | |
| } | |
| return data; | |
| } | |
| write(str) { | |
| fs.writeFileSync(this.tempFilename, str); | |
| fs.renameSync(this.tempFilename, this.filename); | |
| } | |
| } | |
| module.exports = { TextFileSync }; | |