Advertisement
Guest User

compress

a guest
May 22nd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. --[[local function Decompile(CompiledTbl)
  2.   local Str = ''
  3.   for k, v in pairs(CompiledTbl) do
  4.     Str = Str .. string.char(v)
  5.   end
  6.   return Str
  7. end
  8.  
  9. local function Compile(Str)
  10.   local Compiled = {string.byte(Str,1,#tostring(Str))}
  11.   return Compiled, table.concat(Compiled, ',')
  12. end
  13.  
  14. local Compiled, Concat = Compile('{HelloWorld = "mikkel809h"}')
  15. print(Concat)
  16. local Decompiled = Decompile(Compiled)
  17. print(Decompiled)
  18. --]]
  19.  
  20.  
  21. local Path = '/'
  22. local Contents = {}
  23.  
  24. local function GetDir(Path)
  25.   if Path:find('rom/') then
  26.   else
  27.     local List = fs.list(Path or '/')
  28.     for k, v in pairs(List) do
  29.  
  30.       local CurrentPath = Path..fs.getName(
  31.         fs.combine(
  32.           Path,
  33.           v
  34.         )
  35.       )
  36.       if fs.isDir(CurrentPath) then
  37.         CurrentPath = CurrentPath .. '/'
  38.       end
  39.       print(tostring(CurrentPath))
  40.       if fs.isDir(CurrentPath) then
  41.         GetDir(CurrentPath)
  42.       else
  43.         local File = fs.open(CurrentPath, 'r')
  44.         if File then
  45.           local Data = File.readAll()
  46.           -- Compile data --
  47.           --Data = --{string.byte(Data,1,#tostring(Data))}
  48.           --print(table.concat(Data, ', '))
  49.           --os.pullEvent()
  50.           File.close()
  51.           Contents[CurrentPath] = Data
  52.           os.queueEvent('Ping')
  53.           os.pullEvent('Ping')
  54.         end
  55.       end
  56.     end
  57.   end
  58. end
  59.  
  60.  
  61. --GetDir(Path)
  62.  
  63. --print('Waiting for input...')
  64. --os.pullEvent('key')
  65. --term.clear()
  66. --term.setCursorPos(1,1)
  67. Compiled = fs.open('Compiled', 'r')
  68. Decompiled = textutils.serialize(Compiled.readAll())
  69. Compiled.close()
  70. local Decompiled = {}
  71. for k, v in pairs(Contents) do
  72.   Decompiled[k] = ''
  73.   for i, j in pairs(v) do
  74.     print(i .. ' -> ' .. tostring(string.char(j)))
  75.     Decompiled[k] = Decompiled[k]..string.char(j)
  76.   end
  77. end
  78. for k, v in pairs(Decompiled) do
  79.   Decompiled = fs.open(k, 'w')
  80.   Decompiled.write(v)
  81.   Decompiled.close()
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement