mirror of
https://github.com/LingChair/LingChair-V0.git
synced 2025-12-08 10:05:49 +08:00
chore: init
This commit is contained in:
48
server_src/iolib.js
Normal file
48
server_src/iolib.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* ©2024 满月叶
|
||||
* Github: MoonLeeeaf
|
||||
* 更简单地使用 FileSystem 库
|
||||
*/
|
||||
|
||||
const fs = require("fs")
|
||||
|
||||
class IoImpl {
|
||||
constructor(p, m) {
|
||||
this.path = p
|
||||
this.mode = m
|
||||
}
|
||||
write(byteOrString) {
|
||||
fs.writeFileSync(this.path, byteOrString)
|
||||
return this
|
||||
}
|
||||
read(type) {
|
||||
// TODO: impentments this method
|
||||
return fs.readFileSync(this.path)
|
||||
}
|
||||
close() {
|
||||
delete this.path
|
||||
delete this.mode
|
||||
delete this.read
|
||||
delete this.write
|
||||
}
|
||||
readJson() {
|
||||
return JSON.parse(this.read("*a"))
|
||||
}
|
||||
writeJson(data) {
|
||||
return this.write(JSON .stringify(data))
|
||||
}
|
||||
}
|
||||
|
||||
let apis = {
|
||||
open: (path, mode) => {
|
||||
return new IoImpl(path, mode)
|
||||
},
|
||||
mkdirs: (path) => {
|
||||
try {fs.mkdirSync(path, { recursive: true })}catch(e){}
|
||||
},
|
||||
exists: (path) => {
|
||||
return fs.existsSync(path)
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = apis
|
||||
Reference in New Issue
Block a user