Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local file = {}
- local _, fs = pcall(require, "filesystem")
- local _, json = pcall(require, "json")
- function file.Write(path, content, json_encode)
- local f = io.open(path, "w")
- if not f then return false end
- f:write(json_encode and json.encode(content) or content)
- f:close()
- return true
- end
- function file.Read(path, json_decode)
- local f = io.open(path, "r")
- if not f then return false end
- local content = f:read("*a")
- io.close(f)
- if json_decode then
- return json.decode(content) or {}
- else
- return content or ""
- end
- end
- file.Exists = fs.exists
- file.CreateDir = fs.makeDirectory
- return file
Add Comment
Please, Sign In to add comment