Interface for reading/writing per bits
This module is a wrapper around stdlib's streams module.
type
BitStream* = ref object
stream: Stream
buffer: uint64
bitsLeft: int
bitsLeft
keeps track of how many bits in buffer
are not read by the end-user, then:
- if they are more than the user requests, then no real read happens on
steam
- if they are less than the user requests, data are read from
stream
intobuffer
Two constructors are provided:
proc newFileBitStream*(f: string; mode = fmRead; size = -1): BitStream
proc newStringBitStream*(s = ""): BitStream
fmWrite
and fmAppend
are disallowed because when writing to a bitstream, reads on the underlying Stream
object are necessary.