mirror of
https://github.com/sealmove/bitstreams
synced 2026-01-14 19:31:41 +00:00
No description
| bitstreams.nim | ||
| bitstreams.nimble | ||
| LICENSE | ||
| README.md | ||
bitstreams
Interface for reading/writing per bits
How it works
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
streamintobuffer
Constructor & Modes
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.