mirror of
https://git.sr.ht/~sircmpwn/tokidoki
synced 2025-12-12 14:17:21 +01:00
Use SHA1 streaming hash for Etag
This commit is contained in:
parent
b3277148d7
commit
e069bc0e9b
1 changed files with 11 additions and 3 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue