GetAllExifData for utility

pull/67/head
vinhphuctadang 2021-11-14 00:00:11 +07:00
parent a6301f85c8
commit 2ed40b60c9
5 changed files with 62 additions and 8 deletions

2
v3/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
playground
vendor

View File

@ -11,9 +11,9 @@ import (
"encoding/binary"
"io/ioutil"
"github.com/dsoprea/go-logging"
log "github.com/dsoprea/go-logging"
"github.com/dsoprea/go-exif/v3/common"
exifcommon "github.com/dsoprea/go-exif/v3/common"
)
const (

View File

@ -7,7 +7,8 @@ go 1.12
// replace github.com/dsoprea/go-utility/v2 => ../../go-utility/v2
require (
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d
github.com/dsoprea/go-exif v0.0.0-20210625224831-a6301f85c82b
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd
github.com/dsoprea/go-utility/v2 v2.0.0-20200717064901-2fccff4aa15e
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d
github.com/jessevdk/go-flags v1.4.0

View File

@ -1,3 +1,5 @@
github.com/dsoprea/go-exif v0.0.0-20210625224831-a6301f85c82b h1:hoVHc4m/v8Al8mbWyvKJWr4Z37yM4QUSVh/NY6A5Sbc=
github.com/dsoprea/go-exif v0.0.0-20210625224831-a6301f85c82b/go.mod h1:lOaOt7+UEppOgyvRy749v3do836U/hw0YVJNjoyPaEs=
github.com/dsoprea/go-exif/v2 v2.0.0-20200321225314-640175a69fe4/go.mod h1:Lm2lMM2zx8p4a34ZemkaUV95AnMl4ZvLbCUbwOvLC2E=
github.com/dsoprea/go-exif/v3 v2.0.0-20200321225314-640175a69fe4/go.mod h1:Lm2lMM2zx8p4a34ZemkaUV95AnMl4ZvLbCUbwOvLC2E=
github.com/dsoprea/go-exif/v3 v3.0.0-20200717053412-08f1b6708903/go.mod h1:0nsO1ce0mh5czxGeLo4+OCZ/C6Eo6ZlMWsz7rH/Gxv8=
@ -9,6 +11,8 @@ github.com/dsoprea/go-logging v0.0.0-20200502201358-170ff607885f h1:FonKAuW3PmNt
github.com/dsoprea/go-logging v0.0.0-20200502201358-170ff607885f/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8=
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d h1:F/7L5wr/fP/SKeO5HuMlNEX9Ipyx2MbH2rV9G4zJRpk=
github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8=
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd h1:l+vLbuxptsC6VQyQsfD7NnEC8BZuFpz45PgY+pH8YTg=
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8=
github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf h1:/w4QxepU4AHh3AuO6/g8y/YIIHH5+aKP3Bj8sg5cqhU=
github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf/go.mod h1:95+K3z2L0mqsVYd6yveIv1lmtT3tcQQ3dVakPySffW8=
github.com/dsoprea/go-utility/v2 v0.0.0-20200512094054-1abbbc781176 h1:CfXezFYb2STGOd1+n1HshvE191zVx+QX3A1nML5xxME=

View File

@ -1,19 +1,22 @@
package exif
import (
"errors"
"fmt"
"io"
"math"
"github.com/dsoprea/go-logging"
"github.com/dsoprea/go-utility/v2/filesystem"
"github.com/dsoprea/go-exif"
log "github.com/dsoprea/go-logging"
rifs "github.com/dsoprea/go-utility/v2/filesystem"
"github.com/dsoprea/go-exif/v3/common"
"github.com/dsoprea/go-exif/v3/undefined"
exifcommon "github.com/dsoprea/go-exif/v3/common"
exifundefined "github.com/dsoprea/go-exif/v3/undefined"
)
var (
utilityLogger = log.NewLogger("exif.utility")
utilityLogger = log.NewLogger("exif.utility")
ErrInvalidMaxBlock = errors.New("cannot read maxBlock < -1")
)
// ExifTag is one simple representation of a tag in a flat list of all of them.
@ -86,6 +89,50 @@ func GetFlatExifData(exifData []byte, so *ScanOptions) (exifTags []ExifTag, med
return exifTags, med, nil
}
// GetAllExifData returns all existing EXIF entries until reaches maxBlock/found no more EXIF blocks
// maxBlock == -1 to read untils no more EXIF blocks found
func GetAllExifData(imageData []byte, so *ScanOptions, maxBlock int) (exifTags []ExifTag, blockRead int, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
}
}()
if maxBlock < -1 {
return nil, 0, ErrInvalidMaxBlock
}
for n := 0; maxBlock == -1 || n < maxBlock; n++ {
exifData, err := exif.SearchAndExtractExif(imageData)
if err != nil {
if errors.Is(err, exif.ErrNoExif) {
if n == 0 {
return exifTags, blockRead, nil
}
break
}
log.Panic(err)
}
// help find next EXIF without searching from start
imageData = exifData[ExifSignatureLength:]
entries, _, err := GetFlatExifData(exifData, so)
if err != nil {
fmt.Println("ERROR:", err, errors.Is(err, io.EOF))
if err == io.EOF || err == io.ErrUnexpectedEOF {
continue
}
log.PanicIf(err)
}
blockRead++
exifTags = append(exifTags, entries...)
}
return exifTags, blockRead, nil
}
// RELEASE(dustin): GetFlatExifDataUniversalSearch is a kludge to allow univeral tag searching in a backwards-compatible manner. For the next release, undo this and simply add the flag to GetFlatExifData.
// GetFlatExifDataUniversalSearch returns a simple, flat representation of all