Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- A simple file io wrapper
- by Nautical
- */
- FileIO = {
- baseDir = "gmodz";
- }
- // File Reading & Writing
- function FileIO:WriteFile(name, contents)
- if (!file.Exists(self.baseDir, "DATA")) then
- file.CreateDir(self.baseDir);
- end
- local path = self.baseDir .. "/" .. name;
- file.Write(path, contents);
- end
- function FileIO:ReadFile(name)
- local path = self.baseDir .. "/" .. name;
- if (!file.Exists(path, "DATA")) then
- return ""
- end
- return file.Read(path,"DATA");
- end
- // JSON Encoding / Decoding
- function FileIO:Encode(name, table)
- self:WriteFile(name, util.TableToJSON(table));
- end
- function FileIO:Decode(name)
- local contents = self:ReadFile(name);
- if (contents == "") then
- return {};
- end
- return util.JSONToTable(contents);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement