Advertisement
Link712011

pastebinToFile

Apr 22nd, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. -- This script must be used with other one, not on pastebin
  2.  
  3. function readAll(file)
  4.     local f = fs.open(file, "r")
  5.     local content
  6.    
  7.     if not f then
  8.         print("Can't open ", file)
  9.         return false
  10.     end
  11.     content = f.readAll()
  12.     f.close()
  13.     return content
  14. end
  15. function writeAll(file, str)
  16.     local f = fs.open(file, "wb")
  17.  
  18.     if not f then
  19.         print("Can't open ", file)
  20.         return false
  21.     end
  22.     for val in str:gmatch".." do
  23.         print(val)
  24.         f.write(tonumber(val, 16))
  25.     end
  26.     f.close()
  27.     return true
  28. end
  29. local arg = {...}
  30. if not arg or not arg[1] or not arg[2] then
  31.     print("pastebinToFile [file to convert] [output file]")
  32. else
  33.     local pasted = readAll(arg[1])
  34.     if pasted then
  35.         writeAll(arg[2], pasted)
  36.         print("Done !")
  37.     end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement