Skip to content

sealmove/bitstreams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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 stream into buffer

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.

About

Interface for reading per bits

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages