mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-06 10:46:34 +03:00
resource: Use MD5 to identify image files
But only a set of byte chunks spread around in the image file to calculate the fingerprint, which is much faster than reading the whole file: ```bash BenchmarkMD5FromFileFast/full=false-4 300000 4356 ns/op 240 B/op 5 allocs/op BenchmarkMD5FromFileFast/full=true-4 30000 42899 ns/op 32944 B/op 5 allocs/op ``` Fixes #4186
This commit is contained in:
parent
7e76a6fd3b
commit
e50a8c7a14
7 changed files with 176 additions and 26 deletions
|
@ -153,7 +153,19 @@ func (r *Spec) newResource(
|
|||
gr := r.newGenericResource(linker, fi, absPublishDir, absSourceFilename, filepath.ToSlash(relTargetFilename), mimeType)
|
||||
|
||||
if mimeType == "image" {
|
||||
f, err := r.Fs.Source.Open(absSourceFilename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
hash, err := helpers.MD5FromFileFast(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Image{
|
||||
hash: hash,
|
||||
imaging: r.imaging,
|
||||
genericResource: gr}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue