2016-01-23 23:41:55 +01:00
|
|
|
package backend
|
|
|
|
|
2016-08-29 19:18:57 +02:00
|
|
|
import (
|
|
|
|
"io"
|
2016-08-31 22:39:36 +02:00
|
|
|
"restic"
|
2016-08-29 19:18:57 +02:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
2016-02-04 19:37:33 +01:00
|
|
|
|
2016-01-23 23:41:55 +01:00
|
|
|
// LoadAll reads all data stored in the backend for the handle. The buffer buf
|
2016-02-04 19:37:33 +01:00
|
|
|
// is resized to accomodate all data in the blob. Errors returned by be.Load()
|
|
|
|
// are passed on, except io.ErrUnexpectedEOF is silenced and nil returned
|
|
|
|
// instead, since it means this function is working properly.
|
2016-08-31 22:39:36 +02:00
|
|
|
func LoadAll(be restic.Backend, h restic.Handle, buf []byte) ([]byte, error) {
|
2016-01-23 23:41:55 +01:00
|
|
|
fi, err := be.Stat(h)
|
|
|
|
if err != nil {
|
2016-08-29 21:54:50 +02:00
|
|
|
return nil, errors.Wrap(err, "Stat")
|
2016-01-23 23:41:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if fi.Size > int64(len(buf)) {
|
|
|
|
buf = make([]byte, int(fi.Size))
|
|
|
|
}
|
|
|
|
|
|
|
|
n, err := be.Load(h, buf, 0)
|
2016-08-29 19:18:57 +02:00
|
|
|
if errors.Cause(err) == io.ErrUnexpectedEOF {
|
2016-02-04 19:37:33 +01:00
|
|
|
err = nil
|
|
|
|
}
|
2016-01-23 23:41:55 +01:00
|
|
|
buf = buf[:n]
|
|
|
|
return buf, err
|
|
|
|
}
|