Dotfiles/lib/fs.lua
Ade Attwood 77e5752cd8 chore(core): add some more modules in configz
Start building out the config and modules / libs that will make up the
dotfiles. This will start to take over the puppet and eventually be the
only things getting use going forward.
2023-06-02 17:58:39 +01:00

35 lines
735 B
Lua

local fs = {};
--- Read the content of a file and return the content
---@param file_path string
---@return boolean
---@return string
fs.read_file = function(file_path)
local file = io.open(file_path, "rb")
if file == nil then
return false, ""
end
local content = file:read "*all"
file:close()
return true, content
end
--- Write content to a file replacing the existing content if the file already
--- exists. If not then the file will be created.
---@param file_path string
---@param content string
---@return boolean
fs.write_file = function(file_path, content)
local file = io.open(file_path, "w+")
if file == nil then
return false
end
file:write(content)
file:close()
return true
end
return fs