feat: utility methods to read/write files

This commit is contained in:
Folke Lemaitre 2022-12-15 14:06:52 +01:00
parent a2f0637c77
commit 27178b5e67
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 14 additions and 0 deletions

View File

@ -28,6 +28,20 @@ function M.open(uri)
end end
end end
function M.read_file(file)
local fd = assert(io.open(file, "r"))
---@type string
local data = fd:read("*a")
fd:close()
return data
end
function M.write_file(file, contents)
local fd = assert(io.open(file, "w+"))
fd:write(contents)
fd:close()
end
---@param ms number ---@param ms number
---@param fn fun() ---@param fn fun()
function M.throttle(ms, fn) function M.throttle(ms, fn)