From 27178b5e6759f6429602acfeb674834e0dad1f13 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 15 Dec 2022 14:06:52 +0100 Subject: [PATCH] feat: utility methods to read/write files --- lua/lazy/util.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/lazy/util.lua b/lua/lazy/util.lua index 5739feb..c2c3d79 100644 --- a/lua/lazy/util.lua +++ b/lua/lazy/util.lua @@ -28,6 +28,20 @@ function M.open(uri) 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 fn fun() function M.throttle(ms, fn)