Guest User

FAILED lua binary read write by Big SHiny Toys

a guest
Sep 6th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. --[[
  2.         BINNARY READ / WRITE
  3. ]]--
  4. local function readAsString(fileParth)
  5.     if fs.exists(fileParth) then
  6.         if not fs.isDir(fileParth) then
  7.             local output = ""
  8.             local file = fs.open(fileParth,"rb")
  9.             local dec = file:read()
  10.             while dec do
  11.                 sChar = string.char(dec)
  12.                 output = output..sChar
  13.                 dec = file:read()
  14.             end
  15.             return output
  16.         else
  17.             error("ERROR folder not file")
  18.         end
  19.     else
  20.         error("ERROR File not found")
  21.     end
  22. end
  23. local function writeString2Binary(fileParth,sDATA)
  24.     file = fs.open(fileParth,"wb")
  25.     if file then
  26.         for i = 1,#sDATA do
  27.             file:write(string.byte(string.sub(sDATA,i,i)))
  28.         end
  29.         file:close()
  30.         return true
  31.     end
  32. end
  33. local sFile = readAsString("rom/user/BENCH4.lua")
  34. print(sFile)
  35. writeString2Binary("test",sFile)
Advertisement
Add Comment
Please, Sign In to add comment