mirror of
https://github.com/dsoprea/go-exif.git
synced 2025-05-31 11:41:57 +00:00
backwards incompatible: GetFlatExifData(), Scan(), and Visit() all take a ScanOptions struct now
This commit is contained in:
parent
3f7ee4ce89
commit
7ca1c7b13e
@ -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.
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user