bit-level reader/writer over buffers for luau
| LICENSE | Initial commit | |
| README.md | Update README.md | |
| stream.luau | Upload files to "/" | |
stream
bit-level reader/writer over buffers for luau
Usage
local stream = require(...)
local s = stream.new()
local s = stream.from_buffer(buf)
local s = stream.from_string(str)
stream.write_bit(s, 1)
stream.write_bits(s, 0b10110, 5)
stream.write_bits64(s, lo, hi, 48)
stream.write_u8(s, 255)
stream.write_u16(s, 0xABCD)
stream.write_u32(s, 0xDEADBEEF)
stream.write_i8(s, -42)
stream.write_i16(s, -1000)
stream.write_i32(s, -100000)
stream.write_f32(s, 3.14)
stream.write_f64(s, 3.141592653589793)
stream.write_bool(s, true)
stream.write_varint(s, 100000)
stream.write_signed_varint(s, -500)
stream.write_zigzag(s, -42, 8)
stream.write_unary(s, 5)
stream.write_elias_gamma(s, 100)
stream.write_elias_delta(s, 100)
stream.write_rice(s, 42, 3)
stream.write_string(s, "hello")
stream.write_bytes(s, buf)
stream.write_packed_u8s(s, { 3, 7, 1, 5 }, 3)
stream.reset(s)
local bit = stream.read_bit(s)
local val = stream.read_bits(s, 5)
local lo, hi = stream.read_bits64(s, 48)
local a = stream.read_u8(s)
local b = stream.read_u16(s)
local c = stream.read_u32(s)
local d = stream.read_f64(s)
local e = stream.read_bool(s)
local f = stream.read_varint(s)
local g = stream.read_string(s)
stream.get_pos(s)
stream.get_len(s)
stream.remaining(s)
stream.is_aligned(s)
stream.align(s)
stream.skip(s, 16)
stream.peek_bit(s)
stream.peek_bits(s, 8)
local checkpoint = stream.checkpoint(s)
stream.restore(s, checkpoint)
local buf = stream.to_buffer(s)
local copy = stream.copy(s)