1
1
mirror of https://github.com/wader/fq.git synced 2024-12-22 12:51:38 +03:00

doc: Document io packages a bit

This commit is contained in:
Mattias Wadman 2021-11-21 21:55:53 +01:00
parent 7c4b0b3844
commit 1047d909ac
3 changed files with 28 additions and 6 deletions

View File

@ -60,3 +60,25 @@ main:main()
print tree
empty output
```
## bitio and other io packages
```
*os.File, *bytes.Buffer
^
ctxreadseeker.Reader defers blocking io operations to a goroutine to make them cancellable
^
progressreadseeker.Reader approximates how much of a file has been read
^
aheadreadseeker.Reader does readahead caching
^
| (io.ReadSeeker interface)
|
bitio.Reader (implements bitio.Bit* interfaces)
^
| (bitio.Bit* interfaces)
|
bitio.Buffer convenience wrapper to read bytes from bit reader, create section readers etc
SectionBitReader
MultiBitReader
```

View File

@ -6,7 +6,7 @@ import (
type ProgressFn func(approxReadBytes int64, totalSize int64)
type ProgressReaderSeeker struct {
type Reader struct {
rs io.ReadSeeker
pos int64
totalSize int64
@ -16,12 +16,12 @@ type ProgressReaderSeeker struct {
progressFn ProgressFn
}
func New(rs io.ReadSeeker, precision int64, totalSize int64, fn ProgressFn) *ProgressReaderSeeker {
func New(rs io.ReadSeeker, precision int64, totalSize int64, fn ProgressFn) *Reader {
partitionSize := totalSize / precision
if totalSize%precision != 0 {
partitionSize++
}
return &ProgressReaderSeeker{
return &Reader{
rs: rs,
totalSize: totalSize,
partitionSize: partitionSize,
@ -30,7 +30,7 @@ func New(rs io.ReadSeeker, precision int64, totalSize int64, fn ProgressFn) *Pro
}
}
func (prs *ProgressReaderSeeker) Read(p []byte) (n int, err error) {
func (prs *Reader) Read(p []byte) (n int, err error) {
n, err = prs.rs.Read(p)
newPos := prs.pos + int64(n)
lastPartitionsReadCount := prs.partitionsReadCount
@ -59,7 +59,7 @@ func (prs *ProgressReaderSeeker) Read(p []byte) (n int, err error) {
return n, err
}
func (prs *ProgressReaderSeeker) Seek(offset int64, whence int) (int64, error) {
func (prs *Reader) Seek(offset int64, whence int) (int64, error) {
pos, err := prs.rs.Seek(offset, whence)
prs.pos = pos
return pos, err

View File

@ -151,7 +151,7 @@ func (i *Interp) _open(c interface{}, a []interface{}) interface{} {
const cacheReadAheadSize = 512 * 1024
aheadRs := aheadreadseeker.New(fRS, cacheReadAheadSize)
// bitio.Buffer -> aheadreadseeker -> progressreadseeker -> ctxreadseeker -> readseeker
// bitio.Buffer -> (bitio.Reader) -> aheadreadseeker -> progressreadseeker -> ctxreadseeker -> readseeker
bbf.bb, err = bitio.NewBufferFromReadSeeker(aheadRs)
if err != nil {