Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wiggin77/nibs
Read streams of bytes in nibbles from 1 bit to 64 bits at a time.
https://github.com/wiggin77/nibs
bitreader bytes go golang golang-library golang-package nib nibbles readstream
Last synced: about 2 months ago
JSON representation
Read streams of bytes in nibbles from 1 bit to 64 bits at a time.
- Host: GitHub
- URL: https://github.com/wiggin77/nibs
- Owner: wiggin77
- License: mit
- Created: 2018-01-21T22:09:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-18T22:56:12.000Z (12 months ago)
- Last Synced: 2024-10-12T04:40:55.656Z (3 months ago)
- Topics: bitreader, bytes, go, golang, golang-library, golang-package, nib, nibbles, readstream
- Language: Go
- Size: 17.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nibs
[![GoDoc](https://godoc.org/github.com/wiggin77/nibs?status.svg)](https://godoc.org/github.com/wiggin77/nibs)
![Build Status](https://github.com/wiggin77/nibs/actions/workflows/go.yml/badge.svg)Nibs is a Go package for reading streams of bytes in nibbles. Each nibble can be a number of bits in the range 1 bit to 64 bits inclusive.
## Usage
```go
// provide an io.Reader
b := []byte("this is a test")
buf := bytes.NewReader(b)// create instance of Nibs
nib := nibs.New(buf)// read until io.EOF,
for {
n, err := nib.Nibble8(4)
if err != nil {
break
}
fmt.Printf("nibbled 4 bits: %d", n)
}// once EOF is reached, there will be bits left over
// if nibble sizes do not divide evenly into the `NibbleXX`
// return type. Use `BitsRemaining` to determine how many.
remaining, err := nib.BitsRemaining()
if err == nil && remaining > 0 {
n, err := nib.Nibble(remaining)
if err == nil {
fmt.Printf("nibbled %d remaining bits: %d", remaining, n)
}
}
```