All Projects → icza → Bitio

icza / Bitio

Licence: apache-2.0
Optimized bit-level Reader and Writer for Go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Bitio

maildir
A Go package for reading & writing messages in maildir format
Stars: ✭ 13 (-91.03%)
Mutual labels:  writer, reader
Spout
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
Stars: ✭ 3,861 (+2562.76%)
Mutual labels:  reader, writer
java-class-tools
Read and write java class files in Node.js or in the browser.
Stars: ✭ 27 (-81.38%)
Mutual labels:  writer, reader
Qtcsv
Library for reading and writing csv-files in Qt.
Stars: ✭ 156 (+7.59%)
Mutual labels:  reader, writer
Xopen
open files for buffered reading and writing in #golang
Stars: ✭ 55 (-62.07%)
Mutual labels:  reader, writer
mp4-rust
🎥 MP4 reader and writer library in Rust! 🦀
Stars: ✭ 149 (+2.76%)
Mutual labels:  writer, reader
Asmresolver
A library for editing PE files with full .NET metadata support
Stars: ✭ 267 (+84.14%)
Mutual labels:  reader, writer
Acr122u Reader Writer
A simple tool to read/write Mifare RFID tags with an ACR122U device
Stars: ✭ 169 (+16.55%)
Mutual labels:  reader, writer
Ini
Ini file reader/writer for C# / .NET written in pure .NET in a single source file
Stars: ✭ 43 (-70.34%)
Mutual labels:  reader, writer
Xml
XML without worries
Stars: ✭ 35 (-75.86%)
Mutual labels:  reader, writer
iobit
Package iobit provides primitives for reading & writing bits
Stars: ✭ 16 (-88.97%)
Mutual labels:  writer, reader
Iostreams
IOStreams is an incredibly powerful streaming library that makes changes to file formats, compression, encryption, or storage mechanism transparent to the application.
Stars: ✭ 84 (-42.07%)
Mutual labels:  reader, writer
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (+156.55%)
Mutual labels:  reader, writer
Cistern
Ruby API client framework
Stars: ✭ 81 (-44.14%)
Mutual labels:  reader, writer
Parquet4s
Read and write Parquet in Scala. Use Scala classes as schema. No need to start a cluster.
Stars: ✭ 125 (-13.79%)
Mutual labels:  reader, writer
Laravel Log Reader
A log reader and management tool for Laravel
Stars: ✭ 115 (-20.69%)
Mutual labels:  reader
Node Pcsclite
Bindings over pcsclite to access Smart Cards
Stars: ✭ 127 (-12.41%)
Mutual labels:  reader
Go Excel
A simple and light excel file reader to read a standard excel as a table faster | 一个轻量级的Excel数据读取库,用一种更`关系数据库`的方式解析Excel。
Stars: ✭ 114 (-21.38%)
Mutual labels:  reader
Album Bankakyou
Most simple UI, gallery before your eyes.
Stars: ✭ 102 (-29.66%)
Mutual labels:  reader
Mangaonlineviewer
This scripts loads all pages(images) from the current chapter of the manga showing them in one page in a list type structure, witch helps reading faster.
Stars: ✭ 133 (-8.28%)
Mutual labels:  reader

bitio

Build Status GoDoc Go Report Card codecov

Package bitio provides an optimized bit-level Reader and Writer for Go.

You can use Reader.ReadBits() to read arbitrary number of bits from an io.Reader and return it as an uint64, and Writer.WriteBits() to write arbitrary number of bits of an uint64 value to an io.Writer.

Both Reader and Writer also provide optimized methods for reading / writing 1 bit of information in the form of a bool value: Reader.ReadBool() and Writer.WriteBool(). These make this package ideal for compression algorithms that use Huffman coding for example, where decision whether to step left or right in the Huffman tree is the most frequent operation.

Reader and Writer give a bit-level view of the underlying io.Reader and io.Writer, but they also provide a byte-level view (io.Reader and io.Writer) at the same time. This means you can also use the Reader.Read() and Writer.Write() methods to read and write slices of bytes. These will give you best performance if the underlying io.Reader and io.Writer are aligned to a byte boundary (else all the individual bytes are assembled from / spread to multiple bytes). You can ensure byte boundary alignment by calling the Align() method of Reader and Writer. As an extra, io.ByteReader and io.ByteWriter are also implemented.

Bit order

The more general highest-bits-first order is used. So for example if the input provides the bytes 0x8f and 0x55:

HEXA    8    f     5    5
BINARY  1100 1111  0101 0101
        aaaa bbbc  ccdd dddd

Then ReadBits will return the following values:

r := NewReader(bytes.NewBuffer([]byte{0x8f, 0x55}))
a, err := r.ReadBits(4) //   1100 = 0x08
b, err := r.ReadBits(3) //    111 = 0x07
c, err := r.ReadBits(3) //    101 = 0x05
d, err := r.ReadBits(6) // 010101 = 0x15

Writing the above values would result in the same sequence of bytes:

b := &bytes.Buffer{}
w := NewWriter(b)
err := w.WriteBits(0x08, 4)
err = w.WriteBits(0x07, 3)
err = w.WriteBits(0x05, 3)
err = w.WriteBits(0x15, 6)
err = w.Close()
// b will hold the bytes: 0x8f and 0x55

Error handling

All ReadXXX() and WriteXXX() methods return an error which you are expected to handle. For convenience, there are also matching TryReadXXX() and TryWriteXXX() methods which do not return an error. Instead they store the (first) error in the Reader.TryError / Writer.TryError field which you can inspect later. These TryXXX() methods are a no-op if a TryError has been encountered before, so it's safe to call multiple TryXXX() methods and defer the error checking.

For example:

r := NewReader(bytes.NewBuffer([]byte{0x8f, 0x55}))
a := r.TryReadBits(4) //   1100 = 0x08
b := r.TryReadBits(3) //    111 = 0x07
c := r.TryReadBits(3) //    101 = 0x05
d := r.TryReadBits(6) // 010101 = 0x15
if r.TryError != nil {
    // Handle error
}

This allows you to easily convert the result of individual ReadBits(), like this:

r := NewReader(bytes.NewBuffer([]byte{0x8f, 0x55}))
a := byte(r.TryReadBits(4))   //   1100 = 0x08
b := int32(r.TryReadBits(3))  //    111 = 0x07
c := int64(r.TryReadBits(3))  //    101 = 0x05
d := uint16(r.TryReadBits(6)) // 010101 = 0x15
if r.TryError != nil {
    // Handle error
}

And similarly:

b := &bytes.Buffer{}
w := NewWriter(b)
w.TryWriteBits(0x08, 4)
w.TryWriteBits(0x07, 3)
w.TryWriteBits(0x05, 3)
w.TryWriteBits(0x15, 6)
if w.TryError != nil {
    // Handle error
}
err = w.Close()
// b will hold the bytes: 0x8f and 0x55
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].