Advertisement
Windows10User

random stuff

May 3rd, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. function compress(dir, zip)
  2.     if fs.isDir(dir) then
  3.         local filelist = fs.list(dir)
  4.         local archive = {
  5.             files = {
  6.                
  7.             },
  8.            
  9.             filedata = {
  10.                
  11.             },
  12.            
  13.             archive = "true"
  14.         }
  15.        
  16.         for i=1, #filelist do
  17.             if fs.isDir(dir.."/"..filelist[i]) == false then
  18.                 local filehandle = fs.open(dir.."/"..filelist[i], "r")
  19.                 table.insert(archive.files, filelist[i])
  20.                 archive.filedata[filelist[i]] = filehandle.readAll()
  21.                 filehandle.close()
  22.             end
  23.         end
  24.         local fArchive = fs.open(zip..".cmp", "w")
  25.         fArchive.write(textutils.serialize(archive))
  26.         fArchive.close()
  27.         return true
  28.     else
  29.         return false
  30.     end
  31. end
  32.  
  33.  
  34. function decompress(archive, dir)
  35.     if isArchive(archive) then
  36.         local zipfile = fs.open(archive, "r")
  37.         local zip = textutils.unserialize(zipfile.readAll())
  38.         zipfile.close()
  39.        
  40.         fs.makeDir(dir)
  41.         for i=1, #zip.files do
  42.             local file = fs.open(dir.."/"..zip.files[i], "w")
  43.             file.write(zip.filedata[zip.files[i]])
  44.             file.close()
  45.         end
  46.         return true
  47.     else
  48.         return false
  49.     end
  50. end
  51.  
  52. function isArchive(path)
  53.     local fshandle = fs.open(path, "r")
  54.     local table2 = textutils.unserialize(fshandle.readAll())
  55.     fshandle.close()
  56.    
  57.     if table2.archive == "true" then
  58.         return true
  59.     else
  60.         return false
  61.     end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement