image hashing to sha256
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash/crc64"
|
||||
@@ -42,7 +42,7 @@ type FileSystem struct {
|
||||
// Files partitioned across multiple subdirectories.
|
||||
func (f *FileSystem) Save(name string, r io.Reader) (id string, err error) {
|
||||
|
||||
h := sha1.Sum([]byte(name))
|
||||
h := sha256.Sum224([]byte(name))
|
||||
id = hex.EncodeToString(h[:])
|
||||
if ext := path.Ext(name); ext != "" {
|
||||
id += ext
|
||||
|
||||
@@ -24,9 +24,9 @@ func TestImage_Save(t *testing.T) {
|
||||
}
|
||||
id, err := svc.Save("blah_ff1.png", strings.NewReader("blah blah"))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "6851dcde6024e03258a66705f29e14b506048c74.png", id)
|
||||
assert.Equal(t, "fc77a87ad3c898b9603119711f99305145e272e103c904d85ee2deda.png", id)
|
||||
|
||||
dst := path.Join(loc, "02", id)
|
||||
dst := path.Join(loc, "56", id)
|
||||
data, err := ioutil.ReadFile(dst)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "blah blah", string(data))
|
||||
|
||||
Reference in New Issue
Block a user