New Setup 📦
This commit is contained in:
parent
d16174b447
commit
415dbd08a1
10194 changed files with 1368647 additions and 4 deletions
41
home/.config/awesome/ui/sidebar/services/read_writer.lua
Normal file
41
home/.config/awesome/ui/sidebar/services/read_writer.lua
Normal file
|
@ -0,0 +1,41 @@
|
|||
-- ## Simple file read / writer ##
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
local file_reader = {}
|
||||
|
||||
local information_dir ="/tmp/"
|
||||
|
||||
-- Return true if file exists and is readable.
|
||||
local check_exits = function(path)
|
||||
local file = io.open(path, "rb")
|
||||
if file then file:close() end
|
||||
return file ~= nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Read an entire file.
|
||||
file_reader.readall = function(filename)
|
||||
if check_exits(information_dir .. filename) then
|
||||
local fh = assert(io.open(information_dir .. filename, "rb"))
|
||||
local infor = assert(fh:read("*a"))
|
||||
fh:close()
|
||||
return tostring(infor:gsub("%s+", ""))
|
||||
else
|
||||
return "not found"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Write a string to a file.
|
||||
file_reader.write = function(filename, contents)
|
||||
if check_exits(information_dir .. filename) then
|
||||
local fh = assert(io.open(information_dir .. filename, "wb"))
|
||||
fh:write(contents)
|
||||
fh:flush()
|
||||
fh:close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return file_reader
|
Loading…
Add table
Add a link
Reference in a new issue