Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function file_readAll(file,s)
- local f = fs.open(file,"r")
- local cont = f.readAll()
- f.close()
- if(s)then return textutils.unserialize(s) end
- return cont
- end
- function file_readLine(file,s)
- local f = fs.open(file,"r")
- local cont = f.readLine()
- f.close()
- if(s)then return textutils.unserialize(s) end
- return cont
- end
- function file_write(file,data,s)
- local f = fs.open(file,"w")
- if(s)then f.write(textutils.serialize(data)) else
- f.write(data) end
- f.close()
- end
- function file_writeline(file,data,s)
- local f = fs.open(file,"w")
- if(s)then f.writeLine(textutils.serialize(data)) else
- f.writeLine(data) end
- f.close()
- end
- local function formatpath(path)
- local pathtbl={}
- local s=""
- local pathsize=0
- -- Divide string and count the number of
- -- divisions.
- for str in string.gmatch(path, "([^/]+)") do
- pathtbl[#pathtbl+1] = str
- end
- table.remove(pathtbl,1)
- for i = 1, #pathtbl do
- s = s .. pathtbl[i] .. "/"
- end
- return s
- end
- local function getcontent(data,wdata,ctbl)
- -- Returns a table --
- for k, v in pairs(fs.list(data)) do
- if(fs.isDir(data.."/"..v) )then
- getcontent(data..v.."/",v.."/",ctbl)
- else
- --print(data..v)
- local f = fs.open(data..v,"r")
- ctbl[formatpath(data..v)] = {content=f.readAll()}
- f.close()
- end
- end
- return textutils.serialize(ctbl)
- end
- function archive(data,export)
- local content = {}
- content = getcontent('/' .. data .. "/","/",content)
- file_write(export,content)
- return true
- end
- function extract(file,to)
- local cont = textutils.unserialize(file_readAll(file))
- for k,v in pairs(cont) do
- file_write(to .. "/" .. k,v.content)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement