Use SHA1 streaming hash for Etag
This commit is contained in:
parent
b3277148d7
commit
e069bc0e9b
@ -2,10 +2,11 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -75,11 +76,18 @@ func (b *filesystemBackend) safePath(ctx context.Context, path string) (string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func etagForFile(path string) (string, error) {
|
func etagForFile(path string) (string, error) {
|
||||||
data, err := ioutil.ReadFile(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
csum := md5.Sum(data)
|
defer f.Close()
|
||||||
|
|
||||||
|
h := sha1.New()
|
||||||
|
if _, err := io.Copy(h, f); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
csum := h.Sum(nil)
|
||||||
|
|
||||||
return base64.StdEncoding.EncodeToString(csum[:]), nil
|
return base64.StdEncoding.EncodeToString(csum[:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user