Exif: Stop search if no header was found in PNG, TIFF, and HEIF
This commit is contained in:
parent
78fbab05ae
commit
62f5a5f5f0
2 changed files with 34 additions and 34 deletions
|
@ -56,12 +56,11 @@ func RawExif(fileName string, fileType fs.FileFormat) (rawExif []byte, err error
|
|||
|
||||
if err != nil {
|
||||
return rawExif, fmt.Errorf("metadata: %s in %s (parse png)", err, logName)
|
||||
}
|
||||
|
||||
} else {
|
||||
_, rawExif, err = cs.Exif()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "file does not have EXIF" {
|
||||
if err.Error() == "file does not have EXIF" || strings.HasPrefix(err.Error(), "no exif data") {
|
||||
return rawExif, fmt.Errorf("metadata: found no exif header in %s (parse png)", logName)
|
||||
} else {
|
||||
log.Infof("metadata: %s in %s (parse png)", err, logName)
|
||||
|
@ -69,6 +68,7 @@ func RawExif(fileName string, fileType fs.FileFormat) (rawExif []byte, err error
|
|||
} else {
|
||||
parsed = true
|
||||
}
|
||||
}
|
||||
} else if fileType == fs.FormatHEIF {
|
||||
heicMp := heicexif.NewHeicExifMediaParser()
|
||||
|
||||
|
@ -76,12 +76,11 @@ func RawExif(fileName string, fileType fs.FileFormat) (rawExif []byte, err error
|
|||
|
||||
if err != nil {
|
||||
return rawExif, fmt.Errorf("metadata: %s in %s (parse heic)", err, logName)
|
||||
}
|
||||
|
||||
} else {
|
||||
_, rawExif, err = cs.Exif()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "file does not have EXIF" {
|
||||
if err.Error() == "file does not have EXIF" || strings.HasPrefix(err.Error(), "no exif data") {
|
||||
return rawExif, fmt.Errorf("metadata: found no exif header in %s (parse heic)", logName)
|
||||
} else {
|
||||
log.Infof("metadata: %s in %s (parse heic)", err, logName)
|
||||
|
@ -89,6 +88,7 @@ func RawExif(fileName string, fileType fs.FileFormat) (rawExif []byte, err error
|
|||
} else {
|
||||
parsed = true
|
||||
}
|
||||
}
|
||||
} else if fileType == fs.FormatTiff {
|
||||
tiffMp := tiffstructure.NewTiffMediaParser()
|
||||
|
||||
|
@ -96,12 +96,11 @@ func RawExif(fileName string, fileType fs.FileFormat) (rawExif []byte, err error
|
|||
|
||||
if err != nil {
|
||||
return rawExif, fmt.Errorf("metadata: %s in %s (parse tiff)", err, logName)
|
||||
}
|
||||
|
||||
} else {
|
||||
_, rawExif, err = cs.Exif()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "file does not have EXIF" {
|
||||
if err.Error() == "file does not have EXIF" || strings.HasPrefix(err.Error(), "no exif data") {
|
||||
return rawExif, fmt.Errorf("metadata: found no exif header in %s (parse tiff)", logName)
|
||||
} else {
|
||||
log.Infof("metadata: %s in %s (parse tiff)", err, logName)
|
||||
|
@ -110,6 +109,7 @@ func RawExif(fileName string, fileType fs.FileFormat) (rawExif []byte, err error
|
|||
parsed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !parsed {
|
||||
rawExif, err = exif.SearchFileAndExtractExif(fileName)
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestExif(t *testing.T) {
|
|||
t.Fatal("err should NOT be nil")
|
||||
}
|
||||
|
||||
assert.Equal(t, "metadata: found no exif header in tweethog.png (search and extract)", err.Error())
|
||||
assert.Equal(t, "metadata: found no exif header in tweethog.png (parse png)", err.Error())
|
||||
})
|
||||
|
||||
t.Run("iphone_7.heic", func(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue