backwards incompatible: GetFlatExifData(), Scan(), and Visit() all take a ScanOptions struct now

This commit is contained in:
Dustin Oprea 2020-07-11 11:48:49 -04:00
parent 3f7ee4ce89
commit 7ca1c7b13e
5 changed files with 13 additions and 10 deletions

View File

@ -106,7 +106,7 @@ func main() {
// Run the parse.
entries, err := exif.GetFlatExifData(rawExif)
entries, _, err := exif.GetFlatExifData(rawExif, nil)
log.PanicIf(err)
// Write the thumbnail is requested and present.

View File

@ -192,7 +192,7 @@ func ParseExifHeader(data []byte) (eh ExifHeader, err error) {
}
// Visit recursively invokes a callback for every tag.
func Visit(rootIfdIdentity *exifcommon.IfdIdentity, ifdMapping *exifcommon.IfdMapping, tagIndex *TagIndex, exifData []byte, visitor TagVisitorFn) (eh ExifHeader, furthestOffset uint32, err error) {
func Visit(rootIfdIdentity *exifcommon.IfdIdentity, ifdMapping *exifcommon.IfdMapping, tagIndex *TagIndex, exifData []byte, visitor TagVisitorFn, so *ScanOptions) (eh ExifHeader, furthestOffset uint32, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
@ -205,7 +205,7 @@ func Visit(rootIfdIdentity *exifcommon.IfdIdentity, ifdMapping *exifcommon.IfdMa
ebs := NewExifReadSeekerWithBytes(exifData)
ie := NewIfdEnumerate(ifdMapping, tagIndex, ebs, eh.ByteOrder)
_, err = ie.Scan(rootIfdIdentity, eh.FirstIfdOffset, visitor)
_, err = ie.Scan(rootIfdIdentity, eh.FirstIfdOffset, visitor, so)
log.PanicIf(err)
furthestOffset = ie.FurthestOffset()

View File

@ -98,7 +98,7 @@ func TestVisit(t *testing.T) {
return nil
}
_, furthestOffset, err := Visit(exifcommon.IfdStandardIfdIdentity, im, ti, data[foundAt:], visitor)
_, furthestOffset, err := Visit(exifcommon.IfdStandardIfdIdentity, im, ti, data[foundAt:], visitor, nil)
log.PanicIf(err)
if furthestOffset != 32935 {

View File

@ -597,9 +597,14 @@ func (med *MiscellaneousExifData) UnknownTags() map[exifcommon.BasicTag]exifcomm
return med.unknownTags
}
// ScanOptions tweaks parser behavior/choices.
type ScanOptions struct {
// NOTE(dustin): Reserved for future usage.
}
// Scan enumerates the different EXIF blocks (called IFDs). `rootIfdName` will
// be "IFD" in the TIFF standard.
func (ie *IfdEnumerate) Scan(iiRoot *exifcommon.IfdIdentity, ifdOffset uint32, visitor TagVisitorFn) (med *MiscellaneousExifData, err error) {
func (ie *IfdEnumerate) Scan(iiRoot *exifcommon.IfdIdentity, ifdOffset uint32, visitor TagVisitorFn, so *ScanOptions) (med *MiscellaneousExifData, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))

View File

@ -68,10 +68,8 @@ func (et ExifTag) String() string {
len(et.ValueBytes), et.ChildIfdPath)
}
// RELEASE(dustin): In the next release, add an options struct to Scan() and GetFlatExifData(), and put the MiscellaneousExifData in the return.
// GetFlatExifData returns a simple, flat representation of all tags.
func GetFlatExifData(exifData []byte) (exifTags []ExifTag, err error) {
func GetFlatExifData(exifData []byte, so *ScanOptions) (exifTags []ExifTag, med *MiscellaneousExifData, err error) {
defer func() {
if state := recover(); state != nil {
err = log.Wrap(state.(error))
@ -137,10 +135,10 @@ func GetFlatExifData(exifData []byte) (exifTags []ExifTag, err error) {
return nil
}
_, err = ie.Scan(exifcommon.IfdStandardIfdIdentity, eh.FirstIfdOffset, visitor)
med, err = ie.Scan(exifcommon.IfdStandardIfdIdentity, eh.FirstIfdOffset, visitor, nil)
log.PanicIf(err)
return exifTags, nil
return exifTags, med, nil
}
// GpsDegreesEquals returns true if the two `GpsDegrees` are identical.