erdos/src/fs.lua

42 lines
842 B
Lua

return function()
local lfs = love.filesystem
function fsPath(path)
local v = path:gsub(':', '/')
return v
end
function fsLs(path)
return lfs.getDirectoryItems(fsPath(path))
end
function fsHas(file)
if lfs.getInfo
then return not not lfs.getInfo(fsPath(file)) end
return lfs.exists(fsPath(file))
end
function fsInfo(file)
file = fsPath(file)
if lfs.getInfo
then return lfs.getInfo(file)
end
if not fsHas(file)
then return end
local info = {}
if lfs.isFile(file) then info.type = 'file'
elseif lfs.isDirectory(file) then info.type = 'directory'
elseif lfs.isSymlink(file) then info.type = 'symlink'
else info.type = 'other' end
info.size = lfs.getSize(file)
info.modtime = lfs.getLastModified(file)
return info
end
function fsRead(file)
return lfs.read(fsPath(file)), nil
end
end