diff --git a/pkg/bitio/README.md b/pkg/bitio/README.md deleted file mode 100644 index 26d9cd8f..00000000 --- a/pkg/bitio/README.md +++ /dev/null @@ -1,18 +0,0 @@ -The bitio package tries to mimic the standard library packages io and bytes as much as possible. - -- bitio.Buffer same as bytes.Buffer -- bitio.IOBitReadSeeker is a bitio.ReaderAtSeeker that from a io.ReadSeeker -- bitio.IOBitWriter a bitio.BitWriter that write bytes to a io.Writer, use Flush() to write possible unaligned byte -- bitio.IOReader is a io.Reader that reads bytes from a bit reader, will zero pad on unaligned byte eof -- bitio.IOReadSeeker is a io.ReadSeeker that read/seek bytes in a bit stream, will zero pad on unaligned - bitio.NewBitReader same as bytes.NewReader -- bitio.LimitReader same as io.LimitReader -- bitio.MultiReader same as io.MultiReader -- bitio.SectionReader same as io.SectionReader -- bitio.Copy* same as io.Copy* -- bitio.ReadFull same as io.ReadFull - -TODO: -- bitio.IOBitReader bitio.Reader that reads from a io.Reader -- bitio.IOBitWriteSeeker bitio.BitWriteSeeker that writes to a io.WriteSeeker -- bitio.CopyN -- speed up read by using a cache somehow ([]byte or just a uint64?) diff --git a/pkg/bitio/doc.go b/pkg/bitio/doc.go new file mode 100644 index 00000000..9207a8d8 --- /dev/null +++ b/pkg/bitio/doc.go @@ -0,0 +1,34 @@ +// Package bitio tries to mimic the standard library packages io and bytes but for bits. +// +// - bitio.Buffer same as bytes.Buffer +// +// - bitio.IOBitReadSeeker is a bitio.ReaderAtSeeker that reads from a io.ReadSeeker +// +// - bitio.IOBitWriter a bitio.BitWriter that writes to a io.Writer, use Flush() to write possible zero padded unaligned byte +// +// - bitio.IOReader is a io.Reader that reads bytes from a bitio.Reader, will zero pad unaligned byte at EOF +// +// - bitio.IOReadSeeker is a io.ReadSeeker that reads from a bitio.ReadSeeker, will zero pad unaligned byte at EOF +// +// - bitio.NewBitReader same as bytes.NewReader +// +// - bitio.LimitReader same as io.LimitReader +// +// - bitio.MultiReader same as io.MultiReader +// +// - bitio.SectionReader same as io.SectionReader +// +// - bitio.Copy* same as io.Copy* +// +// - bitio.ReadFull same as io.ReadFull +// +// TODO: +// +// - bitio.IOBitReader bitio.Reader that reads from a io.Reader +// +// - bitio.IOBitWriteSeeker bitio.BitWriteSeeker that writes to a io.WriteSeeker +// +// - bitio.CopyN +// +// - Speed up read by using a cache somehow ([]byte or just a uint64?) +package bitio diff --git a/pkg/bitio/iobitreadseeker.go b/pkg/bitio/iobitreadseeker.go index b2133ec7..48440fe8 100644 --- a/pkg/bitio/iobitreadseeker.go +++ b/pkg/bitio/iobitreadseeker.go @@ -5,7 +5,7 @@ import ( "io" ) -// IOBitReadSeeker is a bitio.BitReadAtSeeker reading from a io.ReadSeeker +// IOBitReadSeeker is a bitio.ReadAtSeeker reading from a io.ReadSeeker type IOBitReadSeeker struct { bitPos int64 rs io.ReadSeeker diff --git a/pkg/bitio/iobitwriter.go b/pkg/bitio/iobitwriter.go index a7a42160..e51901dd 100644 --- a/pkg/bitio/iobitwriter.go +++ b/pkg/bitio/iobitwriter.go @@ -4,7 +4,7 @@ import ( "io" ) -// IOBitWriter is a bitio.BitWriter that writes to a io.Writer +// IOBitWriter is a bitio.Writer that writes to a io.Writer // Use Flush to write possible unaligned byte zero bit padded. type IOBitWriter struct { w io.Writer diff --git a/pkg/bitio/ioreadseeker.go b/pkg/bitio/ioreadseeker.go index a52be258..3b5a674e 100644 --- a/pkg/bitio/ioreadseeker.go +++ b/pkg/bitio/ioreadseeker.go @@ -1,6 +1,6 @@ package bitio -// IOReadSeeker is a io.ReadSeeker that reads and seeks from a bitio.BitReadSeeker +// IOReadSeeker is a io.ReadSeeker that reads from a bitio.ReadSeeker // Unaligned byte at EOF will be zero bit padded type IOReadSeeker struct { IOReader diff --git a/pkg/bitio/readwrite64.go b/pkg/bitio/readwrite64.go index 9d3c72b6..b694dc6c 100644 --- a/pkg/bitio/readwrite64.go +++ b/pkg/bitio/readwrite64.go @@ -90,6 +90,8 @@ func Read64(buf []byte, firstBit int64, nBits int64) uint64 { return n } +// Write64 writes nBits bits large unsigned integer to buf starting from firstBit. +// Integer is written most significant bit first. func Write64(v uint64, nBits int64, buf []byte, firstBit int64) { if nBits < 0 || nBits > 64 { panic(fmt.Sprintf("nBits must be 0-64 (%d)", nBits))