Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sUtils = {}
- function sUtils.contains(t, value)
- for i = 1, #t do
- if t[i] == value then
- return true
- end
- end
- return false
- end
- function sUtils.getFile(sFilename, sNetAddress, nFails)
- nFails = nFails or 0
- if nFails > 5 then
- error("Failed too many times. Stopping.", -1)
- end
- local h, err = http.get(sNetAddress)
- if h then
- local fh, err2 = io.open(sFilename, 'w')
- if fh then
- fh:write(h:readAll()):close()
- h.close()
- else
- h.close()
- printError("Failed to write file: " .. err2)
- getFile(sFilename, sNetAddress, nFails + 1)
- end
- else
- printError("Failed to connect: " .. err)
- getFile(sFilename, sNetAddress, nFails + 1)
- end
- end
- function sUtils.split (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function sUtils.countLines(path)
- local lines = 0
- for _ in io.lines(path) do lines = lines + 1 end
- return lines
- end
- function sUtils.getSize(path)
- local size = 0
- local files = fs.list(path)
- for i=1,#files do
- if fs.isDir(fs.combine(path, files[i])) then
- size = size + file.getSize(fs.combine(path, files[i]))
- else
- size = size + fs.getSize(fs.combine(path, files[i]))
- end
- end
- return size
- end
- return sUtils
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement