added custom buffer size error handling

This commit is contained in:
ston1th 2022-03-30 17:06:56 +02:00
commit 711f020c18
4 changed files with 123 additions and 10 deletions

View file

@ -273,6 +273,31 @@ func (mh *MetadataHandler) close() {
close(mh.fs.done)
}
type Error string
func (e Error) Error() string {
return string(e)
}
const (
IOErr Error = "input/output error"
)
func MapError(err error) error {
if err == nil {
return nil
}
s := err.Error()
if strings.HasSuffix(s, IOErr.Error()) {
return IOErr
}
return nil
}
func IsIOErr(err error) bool {
return MapError(err) == IOErr
}
type Metadata struct {
mu sync.RWMutex `json:"-"`
fs *FS `json:"-"`
@ -293,6 +318,15 @@ func (md *Metadata) Delete() error {
return md.fs.RemoveDst(md.name)
}
func (md *Metadata) FullyCached() bool {
md.mu.RLock()
defer md.mu.RUnlock()
if len(md.Chunks) == 0 {
return false
}
return md.Size == md.Chunks[0][1]
}
func (md *Metadata) HasChunk(off int64, n int) bool {
md.mu.RLock()
defer md.mu.RUnlock()