tstor/iio/wrapper.go
Antonio Navarro Perez 45f10e2f81 Refactoring and first steps to make multi OS compatible.
- Using cgofuse to be compatible with multiple OSes
- Refactor to make possible better testing
- Add a bunch of tests
- Add code coverage

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2020-10-18 11:39:59 +02:00

38 lines
539 B
Go

package iio
import (
"io"
"sync"
)
type readAtWrapper struct {
mu sync.Mutex
io.ReadSeeker
io.ReaderAt
io.Closer
}
func NewReadAtWrapper(r io.ReadSeeker) Reader {
return &readAtWrapper{ReadSeeker: r}
}
func (rw *readAtWrapper) ReadAt(p []byte, off int64) (int, error) {
rw.mu.Lock()
defer rw.mu.Unlock()
_, err := rw.Seek(off, io.SeekStart)
if err != nil {
return 0, err
}
return rw.Read(p)
}
func (rw *readAtWrapper) Close() error {
c, ok := rw.ReadSeeker.(io.Closer)
if !ok {
return nil
}
return c.Close()
}