SHARE
TWEET

rawio.lua

a guest Jun 5th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local raw = {}
  2.  
  3. local bit32 = require("bit32")
  4. local fs = require("filesystem")
  5.  
  6.  
  7. function raw.createFileStream(path, mode)
  8.     if fs.exists(path) then
  9.         return io.open(path, mode)
  10.     end
  11.     return nil, "file not found"
  12. end
  13.  
  14. function raw.new(stream, mode)
  15.     local tabl = {}
  16.     tabl.stream = stream
  17.  
  18.     tabl.skip = function(bytes)
  19.         tabl.stream:seek("cur", bytes)
  20.     end
  21.     tabl.getBytes = function(bytes)
  22.         local bytes = tabl.read(bytes)
  23.         tabl.stream:seek("cur", -bytes)
  24.         return bytes
  25.     end
  26.     tabl.readInt = function()
  27.         local b1 = tabl.readByte(1)
  28.         local b2 = tabl.readByte(1)
  29.         local b3 = tabl.readByte(1)
  30.         local b4 = tabl.readByte(1)
  31.         return bit32.bor(bit32.bor(bit32.bor(bit32.lshift(b4, 24), bit32.lshift(b3, 16)), bit32.lshift(b2, 8)), b1)
  32.     end
  33.     tabl.hasNext = function()
  34.         local streamCurr = tabl.stream:seek("cur", 0)
  35.         local streamEnd = tabl.stream:seek("end", 0)
  36.         tabl.stream:seek("set", streamCurr)
  37.         return streamEnd > streamCurr
  38.     end
  39.     tabl.read = function(bytes)
  40.         return tabl.stream:read(bytes)
  41.     end
  42.     tabl.readByte = function()
  43.         return string.byte(tabl.read(1))
  44.     end
  45.     tabl.close = function()
  46.         return tabl.stream:close()
  47.     end
  48.     return tabl
  49. end
  50.  
  51. return raw
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top