<commit_before># bitio

bitio is Golang library for bit reader/writer.

## Support Type

* int (int8 - int64)
* uint (uint8 - uint64)
* string (fixed length)
* slice (fixed length)

## Example

### BitField Reader/Writer

```go
type Container struct {
	Sign byte   `bit:"4"`           // 4bit
	Size int    `bit:"4"`           // 4bit
	Data []byte `byte:"1" len:"10"` // 1byte x 10
}

func ReadContainer(r io.Reader) (*Container, error) {
	c := &Container{}

	br := bitio.NewBitFieldReader(r)
	if _, err := bitio.Read(c); err != nil {
		return nil, err
	}

	return c, nil
}

func WriteContainer(w io.Writer, c Container) (nBit int, err error) {
	c := &Container{}

	br := bitio.NewBitFieldWriter(w)
	if nBit, err = bitio.Write(c); err != nil {
		return
	}

	return
}
```

### Bit Reader/Writer

```go
func ReadBit(r io.Reader) {
	br := bitio.NewBitReadBuffer(r)

	var b1 byte
	br.ReadBit(&b1, 1)  //read 1bit

	b2 := make([]byte, 2)
	br.ReadBits(b2, 10) //read 10bit

	b3 := make([]byte, 2)
	br.Read(b3)         //read 2byte(16bit)<commit_msg>fix README<commit_after># bitio

bitio is Golang library for bit reader/writer.

## Support Type

* int (int8 - int64)
* uint (uint8 - uint64)
* string (fixed length)
* slice (fixed length)

## Example

### BitField Reader/Writer

```go
type Container struct {
	Sign byte   `bit:"4"`           // 4bit
	Size int    `bit:"4"`           // 4bit
	Data []byte `byte:"1" len:"10"` // 1byte x 10
}

func ReadContainer(r io.Reader) (*Container, error) {
	c := &Container{}

	br := bitio.NewBitFieldReader(r)
	if _, err := bitio.Read(c); err != nil {
		return nil, err
	}

	return c, nil
}

func WriteContainer(w io.Writer, c *Container) (nBit int, err error) {
	br := bitio.NewBitFieldWriter(w)
	if nBit, err = bitio.Write(c); err != nil {
		return
	}

	return
}
```

### Bit Reader/Writer

```go
func ReadBit(r io.Reader) {
	br := bitio.NewBitReadBuffer(r)

	var b1 byte
	br.ReadBit(&b1, 1)  //read 1bit

	b2 := make([]byte, 2)
	br.ReadBits(b2, 10) //read 10bit

	b3 := make([]byte, 2)
	br.Read(b3)         //read 2byte(16bit)
{'fraction_non_alphanumeric': 0.1658583899127061, 'fraction_numerical': 0.03200775945683802, 'mean_word_length': 3.0851485148514852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7330696', 'n_tokens_mistral': 856, 'n_tokens_neox': 791, 'n_words': 226}