local fs = {} fs.read = function(path) if type(path) ~= "string" then error("fs.read: path must be a string", 2) end return __fs_read_file(path) end fs.write = function(path, content) if type(path) ~= "string" then error("fs.write: path must be a string", 2) end if type(content) ~= "string" then error("fs.write: content must be a string", 2) end return __fs_write_file(path, content) end fs.append = function(path, content) if type(path) ~= "string" then error("fs.append: path must be a string", 2) end if type(content) ~= "string" then error("fs.append: content must be a string", 2) end return __fs_append_file(path, content) end fs.exists = function(path) if type(path) ~= "string" then error("fs.exists: path must be a string", 2) end return __fs_exists(path) end fs.remove = function(path) if type(path) ~= "string" then error("fs.remove: path must be a string", 2) end return __fs_remove_file(path) end fs.info = function(path) if type(path) ~= "string" then error("fs.info: path must be a string", 2) end local info = __fs_get_info(path) -- Convert the Unix timestamp to a readable date if info and info.mod_time then info.mod_time_str = os.date("%Y-%m-%d %H:%M:%S", info.mod_time) end return info end -- Directory Operations fs.mkdir = function(path, mode) if type(path) ~= "string" then error("fs.mkdir: path must be a string", 2) end mode = mode or 0755 return __fs_make_dir(path, mode) end fs.ls = function(path) if type(path) ~= "string" then error("fs.ls: path must be a string", 2) end return __fs_list_dir(path) end fs.rmdir = function(path, recursive) if type(path) ~= "string" then error("fs.rmdir: path must be a string", 2) end recursive = recursive or false return __fs_remove_dir(path, recursive) end -- Path Operations fs.join_paths = function(...) return __fs_join_paths(...) end fs.dir_name = function(path) if type(path) ~= "string" then error("fs.dir_name: path must be a string", 2) end return __fs_dir_name(path) end fs.base_name = function(path) if type(path) ~= "string" then error("fs.base_name: path must be a string", 2) end return __fs_base_name(path) end fs.extension = function(path) if type(path) ~= "string" then error("fs.extension: path must be a string", 2) end return __fs_extension(path) end -- Utility Functions fs.read_json = function(path) local content = fs.read_file(path) if not content then return nil, "Could not read file" end local ok, result = pcall(json.decode, content) if not ok then return nil, "Invalid JSON: " .. tostring(result) end return result end fs.write_json = function(path, data, pretty) if type(data) ~= "table" then error("fs.write_json: data must be a table", 2) end local content if pretty then content = json.pretty_print(data) else content = json.encode(data) end return fs.write_file(path, content) end return fs