helpers: Avoid writing the last MD5 buff part twice

This commit is contained in:
Bjørn Erik Pedersen 2017-12-28 22:52:27 +01:00
parent e50a8c7a14
commit 612dcc1944
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
3 changed files with 5 additions and 7 deletions

View file

@ -410,8 +410,6 @@ func MD5FromFileFast(f afero.File) (string, error) {
h.Write(buff) h.Write(buff)
} }
h.Write(buff)
return hex.EncodeToString(h.Sum(nil)), nil return hex.EncodeToString(h.Sum(nil)), nil
} }

View file

@ -311,7 +311,7 @@ func TestFastMD5FromFile(t *testing.T) {
m1, err := MD5FromFileFast(sf1) m1, err := MD5FromFileFast(sf1)
req.NoError(err) req.NoError(err)
req.Equal("308d8a1127b46524b51507424071c22c", m1) req.Equal("e9c8989b64b71a88b4efb66ad05eea96", m1)
m2, err := MD5FromFileFast(sf2) m2, err := MD5FromFileFast(sf2)
req.NoError(err) req.NoError(err)

View file

@ -82,13 +82,13 @@ func TestImageTransform(t *testing.T) {
assert.Equal(200, resizedAndRotated.Height()) assert.Equal(200, resizedAndRotated.Height())
assertFileCache(assert, image.spec.Fs, resizedAndRotated.RelPermalink(), 125, 200) assertFileCache(assert, image.spec.Fs, resizedAndRotated.RelPermalink(), 125, 200)
assert.Equal("/a/sunset_H47566bb0ca0462db92c65f4033d77175_90587_300x200_resize_q75_box_center.jpg", resized.RelPermalink()) assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q75_box_center.jpg", resized.RelPermalink())
assert.Equal(300, resized.Width()) assert.Equal(300, resized.Width())
assert.Equal(200, resized.Height()) assert.Equal(200, resized.Height())
fitted, err := resized.Fit("50x50") fitted, err := resized.Fit("50x50")
assert.NoError(err) assert.NoError(err)
assert.Equal("/a/sunset_H47566bb0ca0462db92c65f4033d77175_90587_9b37eba4e4e6ea0cc56a59bb5aa98143.jpg", fitted.RelPermalink()) assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_e71d3649737587d41fe50793bf366f6f.jpg", fitted.RelPermalink())
assert.Equal(50, fitted.Width()) assert.Equal(50, fitted.Width())
assert.Equal(31, fitted.Height()) assert.Equal(31, fitted.Height())
@ -96,13 +96,13 @@ func TestImageTransform(t *testing.T) {
fittedAgain, _ := fitted.Fit("10x20") fittedAgain, _ := fitted.Fit("10x20")
fittedAgain, err = fittedAgain.Fit("10x20") fittedAgain, err = fittedAgain.Fit("10x20")
assert.NoError(err) assert.NoError(err)
assert.Equal("/a/sunset_H47566bb0ca0462db92c65f4033d77175_90587_9a8be1402216c385e0dfd73e267c6827.jpg", fittedAgain.RelPermalink()) assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_8731035e4934a6e6e09cd10d6f04db93.jpg", fittedAgain.RelPermalink())
assert.Equal(10, fittedAgain.Width()) assert.Equal(10, fittedAgain.Width())
assert.Equal(6, fittedAgain.Height()) assert.Equal(6, fittedAgain.Height())
filled, err := image.Fill("200x100 bottomLeft") filled, err := image.Fill("200x100 bottomLeft")
assert.NoError(err) assert.NoError(err)
assert.Equal("/a/sunset_H47566bb0ca0462db92c65f4033d77175_90587_200x100_fill_q75_box_bottomleft.jpg", filled.RelPermalink()) assert.Equal("/a/sunset_H59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q75_box_bottomleft.jpg", filled.RelPermalink())
assert.Equal(200, filled.Width()) assert.Equal(200, filled.Width())
assert.Equal(100, filled.Height()) assert.Equal(100, filled.Height())
assertFileCache(assert, image.spec.Fs, filled.RelPermalink(), 200, 100) assertFileCache(assert, image.spec.Fs, filled.RelPermalink(), 200, 100)