Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local raw = {}
- local bit32 = require("bit32")
- local fs = require("filesystem")
- function raw.createFileStream(path, mode)
- if fs.exists(path) then
- return io.open(path, mode)
- end
- return nil, "file not found"
- end
- function raw.new(stream, mode)
- local tabl = {}
- tabl.stream = stream
- tabl.skip = function(bytes)
- tabl.stream:seek("cur", bytes)
- end
- tabl.getBytes = function(bytes)
- local bytes = tabl.read(bytes)
- tabl.stream:seek("cur", -bytes)
- return bytes
- end
- tabl.readInt = function()
- local b1 = tabl.readByte(1)
- local b2 = tabl.readByte(1)
- local b3 = tabl.readByte(1)
- local b4 = tabl.readByte(1)
- return bit32.bor(bit32.bor(bit32.bor(bit32.lshift(b4, 24), bit32.lshift(b3, 16)), bit32.lshift(b2, 8)), b1)
- end
- tabl.hasNext = function()
- local streamCurr = tabl.stream:seek("cur", 0)
- local streamEnd = tabl.stream:seek("end", 0)
- tabl.stream:seek("set", streamCurr)
- return streamEnd > streamCurr
- end
- tabl.read = function(bytes)
- return tabl.stream:read(bytes)
- end
- tabl.readByte = function()
- return string.byte(tabl.read(1))
- end
- tabl.close = function()
- return tabl.stream:close()
- end
- return tabl
- end
- return raw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement