Performance improvements by using a smaller buffer size

This commit is contained in:
Dane Everitt
2020-08-23 17:18:40 -07:00
parent 999947e387
commit 09826fc7ad
10 changed files with 44 additions and 98 deletions

View File

@@ -97,12 +97,13 @@ func (b *Backup) Checksum() ([]byte, error) {
f, err := os.Open(b.Path())
if err != nil {
return []byte{}, errors.WithStack(err)
return nil, errors.WithStack(err)
}
defer f.Close()
if _, err := io.Copy(h, f); err != nil {
return []byte{}, errors.WithStack(err)
buf := make([]byte, 1024*4)
if _, err := io.CopyBuffer(h, f, buf); err != nil {
return nil, err
}
return h.Sum(nil), nil
@@ -123,7 +124,7 @@ func (b *Backup) Details() *ArchiveDetails {
if err != nil {
log.WithFields(log.Fields{
"backup": b.Identifier(),
"error": err,
"error": err,
}).Error("failed to calculate checksum for backup")
}
@@ -151,4 +152,4 @@ func (b *Backup) Details() *ArchiveDetails {
func (b *Backup) Ignored() []string {
return b.IgnoredFiles
}
}