Guest User

pack

a guest
Jul 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local args = {...}
  2. if not pack then
  3.    _G.pack = {}
  4. end
  5. local function pu()
  6.    printError("pack <add/remove/dump/out/read> <input/output>")
  7. end
  8.  
  9. local cmd = args[1] or ""
  10.  
  11. if cmd == "add" then
  12.    if fs.exists(args[2]) then
  13.       local file = fs.open(args[2],"r")
  14.       local r = file.readAll()
  15.       pack[tostring(args[2])] = r
  16.       file.close()
  17.       print("Added File: "..tostring(args[2]))
  18.    end
  19. elseif cmd == "out" then
  20.    local file = fs.open(args[2],"w")
  21.    local op = textutils.serialise(pack)
  22.    file.write(op)
  23.    file.close()
  24.    print("Created package file: "..tostring(args[2]))
  25. elseif cmd == "dump" then
  26.    for k,v in pairs(pack) do
  27.       print(k)
  28.    end
  29. elseif cmd == "read" then
  30.     if fs.exists(args[2]) then
  31.         local file = fs.open(args[2],"r")
  32.         local r = file.readAll()
  33.         local ret = textutils.unserialise(r)
  34.         file.close()
  35.         for k,v in pairs(ret) do
  36.             local file = fs.open(k,"w")
  37.             file.write(v)
  38.             file.close()
  39.             print("Wrote File: "..k)
  40.         end
  41.     end
  42. elseif cmd == "remove" then
  43.    pack[args[2]] = nil
  44.    print("Removed File: "..args[2])
  45. else
  46.    pu()
  47. end
Advertisement
Add Comment
Please, Sign In to add comment