diff --git a/common_test.go b/common_test.go index 214429a..26a1deb 100644 --- a/common_test.go +++ b/common_test.go @@ -8,7 +8,7 @@ import ( "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( diff --git a/exif-read-tool/main.go b/exif-read-tool/main.go index b5ef20e..d29282b 100644 --- a/exif-read-tool/main.go +++ b/exif-read-tool/main.go @@ -22,7 +22,7 @@ import ( "io/ioutil" "github.com/dsoprea/go-exif" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -64,7 +64,7 @@ func main() { os.Exit(1) } - if printLoggingArg == true { + if printLoggingArg { cla := log.NewConsoleLogAdapter() log.AddAdapter("console", cla) } @@ -147,7 +147,7 @@ func main() { _, err = exif.Visit(exif.IfdStandard, im, ti, rawExif, visitor) log.PanicIf(err) - if printAsJsonArg == true { + if printAsJsonArg { data, err := json.MarshalIndent(entries, "", " ") log.PanicIf(err) diff --git a/exif-read-tool/main_test.go b/exif-read-tool/main_test.go index 32fdbf9..cd9bfd9 100644 --- a/exif-read-tool/main_test.go +++ b/exif-read-tool/main_test.go @@ -12,7 +12,7 @@ import ( "io/ioutil" "os/exec" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -141,7 +141,7 @@ func TestMainJson(t *testing.T) { err = json.Unmarshal(expectedRaw, &expected) log.PanicIf(err) - if reflect.DeepEqual(actual, expected) == false { + if !reflect.DeepEqual(actual, expected) { t.Fatalf("Output not as expected:\nACTUAL:\n%s\nEXPECTED:\n%s", actualRaw, expectedRaw) } } diff --git a/exif.go b/exif.go index 8d1b848..f042d4a 100644 --- a/exif.go +++ b/exif.go @@ -2,6 +2,7 @@ package exif import ( "bytes" + "context" "errors" "fmt" "os" @@ -9,7 +10,7 @@ import ( "encoding/binary" "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) const ( @@ -78,7 +79,7 @@ func SearchAndExtractExif(data []byte) (rawExif []byte, err error) { if _, err := ParseExifHeader(data[i:]); err == nil { foundAt = i break - } else if log.Is(err, ErrNoExif) == false { + } else if !log.Is(err, ErrNoExif) { return nil, err } } @@ -143,32 +144,32 @@ func ParseExifHeader(data []byte) (eh ExifHeader, err error) { // -> http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf if len(data) < 2 { - exifLogger.Warningf(nil, "Not enough data for EXIF header (1): (%d)", len(data)) + exifLogger.Warningf(context.TODO(), "Not enough data for EXIF header (1): (%d)", len(data)) return eh, ErrNoExif } byteOrderBytes := [2]byte{data[0], data[1]} byteOrder, found := ByteOrderLookup[byteOrderBytes] - if found == false { - // exifLogger.Warningf(nil, "EXIF byte-order not recognized: [%v]", byteOrderBytes) + if !found { + // exifLogger.Warningf(context.Todo(), "EXIF byte-order not recognized: [%v]", byteOrderBytes) return eh, ErrNoExif } if len(data) < 4 { - exifLogger.Warningf(nil, "Not enough data for EXIF header (2): (%d)", len(data)) + exifLogger.Warningf(context.TODO(), "Not enough data for EXIF header (2): (%d)", len(data)) return eh, ErrNoExif } fixedBytes := [2]byte{data[2], data[3]} expectedFixedBytes := ExifFixedBytesLookup[byteOrder] if fixedBytes != expectedFixedBytes { - // exifLogger.Warningf(nil, "EXIF header fixed-bytes should be [%v] but are: [%v]", expectedFixedBytes, fixedBytes) + // exifLogger.Warningf(context.Todo(), "EXIF header fixed-bytes should be [%v] but are: [%v]", expectedFixedBytes, fixedBytes) return eh, ErrNoExif } if len(data) < 2 { - exifLogger.Warningf(nil, "Not enough data for EXIF header (3): (%d)", len(data)) + exifLogger.Warningf(context.TODO(), "Not enough data for EXIF header (3): (%d)", len(data)) return eh, ErrNoExif } diff --git a/exif_test.go b/exif_test.go index 2f1de56..3c60baa 100644 --- a/exif_test.go +++ b/exif_test.go @@ -10,7 +10,7 @@ import ( "encoding/binary" "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestVisit(t *testing.T) { @@ -43,7 +43,7 @@ func TestVisit(t *testing.T) { if _, err := ParseExifHeader(data[i:]); err == nil { foundAt = i break - } else if log.Is(err, ErrNoExif) == false { + } else if !log.Is(err, ErrNoExif) { log.Panic(err) } } @@ -165,7 +165,7 @@ func TestVisit(t *testing.T) { "IFD-PATH=[IFD] ID=(0x0128) NAME=[ResolutionUnit] COUNT=(1) TYPE=[SHORT] VALUE=[2]", } - if reflect.DeepEqual(tags, expected) == false { + if !reflect.DeepEqual(tags, expected) { fmt.Printf("\n") fmt.Printf("ACTUAL:\n") fmt.Printf("\n") @@ -194,7 +194,7 @@ func TestSearchFileAndExtractExif(t *testing.T) { rawExif, err := SearchFileAndExtractExif(testImageFilepath) log.PanicIf(err) - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } @@ -206,7 +206,7 @@ func TestSearchAndExtractExif(t *testing.T) { rawExif, err := SearchAndExtractExif(imageData) log.PanicIf(err) - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } diff --git a/go.mod b/go.mod index 82f2666..3366ce7 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/dsoprea/go-exif go 1.13 require ( - github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696 - github.com/go-errors/errors v1.0.1 // indirect - github.com/golang/geo v0.0.0-20190916061304-5b978397cfec - golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect - gopkg.in/yaml.v2 v2.2.7 + github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd + github.com/go-errors/errors v1.4.2 // indirect + github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 + golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect + gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index a36fc59..aae3dbb 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,23 @@ -github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696 h1:VGFnZAcLwPpt1sHlAxml+pGLZz9A2s+K/s1YNhPC91Y= -github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696/go.mod h1:Nm/x2ZUNRW6Fe5C3LxdY1PyZY5wmDv/s5dkPJ/VB3iA= -github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= -github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/golang/geo v0.0.0-20190916061304-5b978397cfec h1:lJwO/92dFXWeXOZdoGXgptLmNLwynMSHUmU6besqtiw= -github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= +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/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 h1:gtexQ/VGyN+VVFRXSFiguSNcXmS6rkKT+X7FdIrTtfo= +github.com/golang/geo v0.0.0-20210211234256-740aa86cb551/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU= +golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= -gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/gps.go b/gps.go index 7d74f22..56de9e6 100644 --- a/gps.go +++ b/gps.go @@ -48,7 +48,7 @@ func (gi *GpsInfo) S2CellId() s2.CellID { ll := s2.LatLngFromDegrees(latitude, longitude) cellId := s2.CellIDFromLatLng(ll) - if cellId.IsValid() == false { + if !cellId.IsValid() { panic(ErrGpsCoordinatesNotValid) } diff --git a/ifd.go b/ifd.go index e75404d..7ac9f66 100644 --- a/ifd.go +++ b/ifd.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) const ( @@ -36,10 +36,6 @@ const ( IfdPathStandardGps = "IFD/GPSInfo" ) -var ( - ifdLogger = log.NewLogger("exif.ifd") -) - var ( ErrChildIfdNotMapped = errors.New("no child-IFD for that tag-ID under parent") ) @@ -113,7 +109,7 @@ func (im *IfdMapping) Get(parentPlacement []uint16) (childIfd *MappedIfd, err er ptr := im.rootNode for _, tagId := range parentPlacement { - if descendantPtr, found := ptr.Children[tagId]; found == false { + if descendantPtr, found := ptr.Children[tagId]; !found { log.Panicf("ifd child with tag-ID (%04x) not registered: [%s]", tagId, ptr.PathPhrase()) } else { ptr = descendantPtr @@ -328,7 +324,7 @@ func (im *IfdMapping) Add(parentPlacement []uint16, tagId uint16, name string) ( Children: make(map[uint16]*MappedIfd), } - if _, found := ptr.Children[tagId]; found == true { + if _, found := ptr.Children[tagId]; found { log.Panicf("child IFD with tag-ID (%04x) already registered under IFD [%s] with tag-ID (%04x)", tagId, ptr.Name, ptr.TagId) } diff --git a/ifd_builder.go b/ifd_builder.go index 40ef4dc..2c9d1bb 100644 --- a/ifd_builder.go +++ b/ifd_builder.go @@ -12,11 +12,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" -) - -var ( - ifdBuilderLogger = log.NewLogger("exif.ifd_builder") + log "github.com/dsoprea/go-logging" ) var ( @@ -30,7 +26,7 @@ type IfdBuilderTagValue struct { } func (ibtv IfdBuilderTagValue) String() string { - if ibtv.IsBytes() == true { + if ibtv.IsBytes() { var valuePhrase string if len(ibtv.valueBytes) <= 8 { valuePhrase = fmt.Sprintf("%v", ibtv.valueBytes) @@ -39,7 +35,7 @@ func (ibtv IfdBuilderTagValue) String() string { } return fmt.Sprintf("IfdBuilderTagValue", valuePhrase, len(ibtv.valueBytes)) - } else if ibtv.IsIb() == true { + } else if ibtv.IsIb() { return fmt.Sprintf("IfdBuilderTagValue", ibtv.ib) } else { log.Panicf("IBTV state undefined") @@ -66,9 +62,9 @@ func (ibtv IfdBuilderTagValue) IsBytes() bool { } func (ibtv IfdBuilderTagValue) Bytes() []byte { - if ibtv.IsBytes() == false { + if !ibtv.IsBytes() { log.Panicf("this tag is not a byte-slice value") - } else if ibtv.IsIb() == true { + } else if ibtv.IsIb() { log.Panicf("this tag is an IFD-builder value not a byte-slice") } @@ -80,9 +76,9 @@ func (ibtv IfdBuilderTagValue) IsIb() bool { } func (ibtv IfdBuilderTagValue) Ib() *IfdBuilder { - if ibtv.IsIb() == false { + if !ibtv.IsIb() { log.Panicf("this tag is not an IFD-builder value") - } else if ibtv.IsBytes() == true { + } else if ibtv.IsBytes() { log.Panicf("this tag is a byte-slice, not a IFD-builder") } @@ -132,7 +128,7 @@ func (bt *BuilderTag) Value() (value *IfdBuilderTagValue) { func (bt *BuilderTag) String() string { var valueString string - if bt.value.IsBytes() == true { + if bt.value.IsBytes() { var err error valueString, err = Format(bt.value.Bytes(), bt.typeId, false, bt.byteOrder) @@ -250,7 +246,7 @@ func NewIfdBuilder(ifdMapping *IfdMapping, tagIndex *TagIndex, fqIfdPath string, mi, err := ifdMapping.GetWithPath(ifdPath) if err == nil { ifdTagId = mi.TagId - } else if log.Is(err, ErrChildIfdNotMapped) == false { + } else if !log.Is(err, ErrChildIfdNotMapped) { log.Panic(err) } @@ -346,7 +342,7 @@ func (ib *IfdBuilder) ChildWithTagId(childIfdTagId uint16) (childIb *IfdBuilder, }() for _, bt := range ib.tags { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { continue } @@ -434,7 +430,7 @@ func getOrCreateIbFromRootIbInner(rootIb *IfdBuilder, parentIb *IfdBuilder, curr var foundChild *IfdBuilder for _, bt := range thisIb.tags { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { continue } @@ -529,7 +525,7 @@ func (ib *IfdBuilder) SetThumbnail(data []byte) (err error) { // TODO(dustin): !! Add a test for this function. - if data == nil || len(data) == 0 { + if len(data) == 0 { log.Panic("thumbnail is empty") } @@ -586,18 +582,18 @@ func (ib *IfdBuilder) printTagTree(levels int) { _, err := ib.ifdMapping.GetChild(currentIb.ifdPath, tag.tagId) if err == nil { isChildIb = true - } else if log.Is(err, ErrChildIfdNotMapped) == false { + } else if !log.Is(err, ErrChildIfdNotMapped) { log.Panic(err) } tagName := "" // If a normal tag (not a child IFD) get the name. - if isChildIb == true { + if isChildIb { tagName = "" } else { it, err := ib.tagIndex.Get(tag.ifdPath, tag.tagId) - if log.Is(err, ErrTagNotFound) == true { + if log.Is(err, ErrTagNotFound) { tagName = "" } else if err != nil { log.Panic(err) @@ -608,14 +604,14 @@ func (ib *IfdBuilder) printTagTree(levels int) { value := tag.Value() - if value.IsIb() == true { + if value.IsIb() { fmt.Printf("%s (%d): [%s] %s\n", indent, i, tagName, value.Ib()) } else { fmt.Printf("%s (%d): [%s] %s\n", indent, i, tagName, tag) } - if isChildIb == true { - if tag.value.IsIb() == false { + if isChildIb { + if !tag.value.IsIb() { log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag) } @@ -655,12 +651,12 @@ func (ib *IfdBuilder) printIfdTree(levels int) { _, err := ib.ifdMapping.GetChild(currentIb.ifdPath, tag.tagId) if err == nil { isChildIb = true - } else if log.Is(err, ErrChildIfdNotMapped) == false { + } else if !log.Is(err, ErrChildIfdNotMapped) { log.Panic(err) } - if isChildIb == true { - if tag.value.IsIb() == false { + if isChildIb { + if !tag.value.IsIb() { log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag) } @@ -693,7 +689,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin for i, tag := range thisIb.tags { var childIb *IfdBuilder childIfdName := "" - if tag.value.IsIb() == true { + if tag.value.IsIb() { childIb = tag.value.Ib() childIfdName = childIb.ifdPath } @@ -707,7 +703,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin childPrefix := "" if prefix == "" { - childPrefix = fmt.Sprintf("%s", thisIb.ifdPath) + childPrefix = thisIb.ifdPath } else { childPrefix = fmt.Sprintf("%s->%s", prefix, thisIb.ifdPath) } @@ -790,7 +786,7 @@ func (ib *IfdBuilder) DeleteAll(tagId uint16) (n int, err error) { for { err = ib.DeleteN(tagId, 1) - if log.Is(err, ErrTagEntryNotFound) == true { + if log.Is(err, ErrTagEntryNotFound) { break } else if err != nil { log.Panic(err) @@ -846,7 +842,7 @@ func (ib *IfdBuilder) Set(bt *BuilderTag) (err error) { position, err := ib.Find(bt.tagId) if err == nil { ib.tags[position] = bt - } else if log.Is(err, ErrTagEntryNotFound) == true { + } else if log.Is(err, ErrTagEntryNotFound) { err = ib.add(bt) log.PanicIf(err) } else { @@ -961,7 +957,7 @@ func (ib *IfdBuilder) Add(bt *BuilderTag) (err error) { } }() - if bt.value.IsIb() == true { + if bt.value.IsIb() { log.Panicf("child IfdBuilders must be added via AddChildIb() or AddTagsFromExisting(), not Add()") } @@ -1034,7 +1030,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol if err == nil { err = ib.SetThumbnail(thumbnailData) log.PanicIf(err) - } else if log.Is(err, ErrNoThumbnail) == false { + } else if !log.Is(err, ErrNoThumbnail) { log.Panic(err) } @@ -1044,7 +1040,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol continue } - if excludeTagIds != nil && len(excludeTagIds) > 0 { + if len(excludeTagIds) > 0 { found := false for _, excludedTagId := range excludeTagIds { if excludedTagId == ite.TagId { @@ -1052,12 +1048,12 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol } } - if found == true { + if found { continue } } - if includeTagIds != nil && len(includeTagIds) > 0 { + if len(includeTagIds) > 0 { // Whether or not there was a list of excludes, if there is a list // of includes than the current tag has to be in it. @@ -1069,7 +1065,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol } } - if found == false { + if !found { continue } } @@ -1130,7 +1126,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol } undefined, ok := undefinedInterface.(UnknownTagValue) - if ok != true { + if !ok { log.Panicf("unexpected value returned from undefined-value processor") } @@ -1221,7 +1217,7 @@ func (ib *IfdBuilder) SetStandard(tagId uint16, value interface{}) (err error) { i, err := ib.Find(tagId) if err != nil { - if log.Is(err, ErrTagEntryNotFound) == false { + if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } @@ -1252,7 +1248,7 @@ func (ib *IfdBuilder) SetStandardWithName(tagName string, value interface{}) (er i, err := ib.Find(bt.tagId) if err != nil { - if log.Is(err, ErrTagEntryNotFound) == false { + if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } diff --git a/ifd_builder_encode.go b/ifd_builder_encode.go index 90fb2dd..1134b27 100644 --- a/ifd_builder_encode.go +++ b/ifd_builder_encode.go @@ -7,7 +7,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) const ( @@ -217,7 +217,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * // Write unit-count. - if bt.value.IsBytes() == true { + if bt.value.IsBytes() { effectiveType := bt.typeId if bt.typeId == TypeUndefined { effectiveType = TypeByte @@ -233,7 +233,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * len_ := len(valueBytes) unitCount := uint32(len_) / typeSize - if _, found := tagsWithoutAlignment[bt.tagId]; found == false { + if _, found := tagsWithoutAlignment[bt.tagId]; !found { remainder := uint32(len_) % typeSize if remainder > 0 { @@ -260,7 +260,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * log.PanicIf(err) } } else { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { log.Panicf("tag value is not a byte-slice but also not a child IB: %v", bt) } @@ -362,7 +362,7 @@ func (ibe *IfdByteEncoder) encodeIfdToBytes(ib *IfdBuilder, ifdAddressableOffset // N the link from this IFD to the next IFD that will be written in the // next cycle. - if setNextIb == true { + if setNextIb { // Write address of next IFD in chain. This will be the original // allocation offset plus the size of everything we have allocated for // this IFD and its child-IFDs. diff --git a/ifd_builder_encode_test.go b/ifd_builder_encode_test.go index f2a8b12..478a938 100644 --- a/ifd_builder_encode_test.go +++ b/ifd_builder_encode_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { @@ -16,7 +16,7 @@ func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { err := bw.writeAsBytes(uint8(0x12)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12}) { t.Fatalf("uint8 not encoded correctly.") } } @@ -28,7 +28,7 @@ func Test_ByteWriter_writeAsBytes_uint16(t *testing.T) { err := bw.writeAsBytes(uint16(0x1234)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34}) { t.Fatalf("uint16 not encoded correctly.") } } @@ -40,7 +40,7 @@ func Test_ByteWriter_writeAsBytes_uint32(t *testing.T) { err := bw.writeAsBytes(uint32(0x12345678)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) { t.Fatalf("uint32 not encoded correctly.") } } @@ -52,7 +52,7 @@ func Test_ByteWriter_WriteUint16(t *testing.T) { err := bw.WriteUint16(uint16(0x1234)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34}) { t.Fatalf("uint16 not encoded correctly (as bytes).") } } @@ -64,7 +64,7 @@ func Test_ByteWriter_WriteUint32(t *testing.T) { err := bw.WriteUint32(uint32(0x12345678)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) { t.Fatalf("uint32 not encoded correctly (as bytes).") } } @@ -76,7 +76,7 @@ func Test_ByteWriter_WriteFourBytes(t *testing.T) { err := bw.WriteFourBytes([]byte{0x11, 0x22, 0x33, 0x44}) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x11, 0x22, 0x33, 0x44}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x11, 0x22, 0x33, 0x44}) { t.Fatalf("four-bytes not encoded correctly.") } } @@ -112,7 +112,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset1(t *testing.T) { t.Fatalf("offset not bumped correctly (2): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3}) { t.Fatalf("buffer not correct after write (1)") } @@ -125,7 +125,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset1(t *testing.T) { t.Fatalf("offset not bumped correctly (3): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) { t.Fatalf("buffer not correct after write (2)") } } @@ -149,7 +149,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset2(t *testing.T) { t.Fatalf("offset not bumped correctly (2): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3}) { t.Fatalf("buffer not correct after write (1)") } @@ -162,7 +162,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset2(t *testing.T) { t.Fatalf("offset not bumped correctly (3): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) { t.Fatalf("buffer not correct after write (2)") } } @@ -212,7 +212,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_embedded1(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00}) { t.Fatalf("encoded tag-entry bytes not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation was done but not expected") @@ -246,7 +246,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_embedded2(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78}) { t.Fatalf("encoded tag-entry bytes not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation was done but not expected") @@ -280,11 +280,11 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (1)") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34}) { t.Fatalf("encoded tag-entry bytes not correct (1)") } else if ida.NextOffset() != addressableOffset+uint32(5) { t.Fatalf("allocation offset not expected (1)") - } else if bytes.Compare(ida.Bytes(), []byte{0x12, 0x34, 0x56, 0x78, 0x9A}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x12, 0x34, 0x56, 0x78, 0x9A}) { t.Fatalf("allocated data not correct (1)") } @@ -297,17 +297,17 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (2)") - } else if bytes.Compare(b.Bytes(), []byte{ + } else if !bytes.Equal(b.Bytes(), []byte{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34, // Tag 1 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x39, // Tag 2 - }) != 0 { + }) { t.Fatalf("encoded tag-entry bytes not correct (2)") } else if ida.NextOffset() != addressableOffset+uint32(10) { t.Fatalf("allocation offset not expected (2)") - } else if bytes.Compare(ida.Bytes(), []byte{ + } else if !bytes.Equal(ida.Bytes(), []byte{ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xbc, 0xde, 0xf0, 0x12, 0x34, - }) != 0 { + }) { t.Fatalf("allocated data not correct (2)") } } @@ -339,7 +339,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_childIfd__withoutAllocate(t *testing.T if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x87, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x87, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) { t.Fatalf("encoded tag-entry with child-IFD not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation offset not expected") @@ -433,7 +433,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_childIfd__withAllocate(t *testing.T) { t.Fatalf("IFD first tag unit-count not correct: (%d)", iteV.UnitCount) } else if iteV.ValueOffset != nextIfdOffsetToWrite { t.Fatalf("IFD's child-IFD offset (as offset) is not correct: (%d) != (%d)", iteV.ValueOffset, nextIfdOffsetToWrite) - } else if bytes.Compare(iteV.RawValueOffset, []byte{0x0, 0x0, 0x07, 0xd0}) != 0 { + } else if !bytes.Equal(iteV.RawValueOffset, []byte{0x0, 0x0, 0x07, 0xd0}) { t.Fatalf("IFD's child-IFD offset (as raw bytes) is not correct: [%x]", iteV.RawValueOffset) } else if iteV.ChildIfdPath != IfdPathStandardExif { t.Fatalf("IFD first tag IFD-name name not correct: [%s]", iteV.ChildIfdPath) @@ -464,7 +464,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_childIfd__withAllocate(t *testing.T) { t.Fatalf("Child IFD first tag unit-count not correct: (%d)", ite.UnitCount) } else if ite.ValueOffset != 0x12340000 { t.Fatalf("Child IFD first tag value value (as offset) not correct: (0x%02x)", ite.ValueOffset) - } else if bytes.Compare(ite.RawValueOffset, []byte{0x12, 0x34, 0x0, 0x0}) != 0 { + } else if !bytes.Equal(ite.RawValueOffset, []byte{0x12, 0x34, 0x0, 0x0}) { t.Fatalf("Child IFD first tag value value (as raw bytes) not correct: [%v]", ite.RawValueOffset) } else if ite.ChildIfdPath != "" { t.Fatalf("Child IFD first tag IFD-name name not empty: [%s]", ite.ChildIfdPath) @@ -542,7 +542,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_simpleTag_allocate(t *testing.T) { t.Fatalf("Tag unit-count not correct: (%d)", ite.UnitCount) } else if ite.ValueOffset != addressableOffset { t.Fatalf("Tag's value (as offset) is not correct: (%d) != (%d)", ite.ValueOffset, addressableOffset) - } else if bytes.Compare(ite.RawValueOffset, []byte{0x0, 0x0, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(ite.RawValueOffset, []byte{0x0, 0x0, 0x12, 0x34}) { t.Fatalf("Tag's value (as raw bytes) is not correct: [%x]", ite.RawValueOffset) } else if ite.ChildIfdPath != "" { t.Fatalf("Tag's IFD-name should be empty: [%s]", ite.ChildIfdPath) @@ -556,7 +556,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_simpleTag_allocate(t *testing.T) { allocatedBytes := ida.Bytes() - if bytes.Compare(allocatedBytes, expectedBytes) != 0 { + if !bytes.Equal(allocatedBytes, expectedBytes) { t.Fatalf("Allocated bytes not correct: %v != %v", allocatedBytes, expectedBytes) } } @@ -616,7 +616,7 @@ func Test_IfdByteEncoder_encodeIfdToBytes_simple(t *testing.T) { 0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, } - if bytes.Compare(tableAndAllocated, expectedIfdAndDataBytes) != 0 { + if !bytes.Equal(tableAndAllocated, expectedIfdAndDataBytes) { t.Fatalf("IFD table and allocated data not correct: %v", DumpBytesClauseToString(tableAndAllocated)) } } diff --git a/ifd_builder_test.go b/ifd_builder_test.go index c5059b6..edc3c03 100644 --- a/ifd_builder_test.go +++ b/ifd_builder_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestIfdBuilder_Add(t *testing.T) { @@ -79,25 +79,25 @@ func TestIfdBuilder_Add(t *testing.T) { if tags[0].tagId != 0x11 { t.Fatalf("tag (0) tag-ID not correct") - } else if bytes.Compare(tags[0].value.Bytes(), []byte("test string")) != 0 { + } else if !bytes.Equal(tags[0].value.Bytes(), []byte("test string")) { t.Fatalf("tag (0) value not correct") } if tags[1].tagId != 0x22 { t.Fatalf("tag (1) tag-ID not correct") - } else if bytes.Compare(tags[1].value.Bytes(), []byte("test string2")) != 0 { + } else if !bytes.Equal(tags[1].value.Bytes(), []byte("test string2")) { t.Fatalf("tag (1) value not correct") } if tags[2].tagId != 0x33 { t.Fatalf("tag (2) tag-ID not correct") - } else if bytes.Compare(tags[2].value.Bytes(), []byte("test string3")) != 0 { + } else if !bytes.Equal(tags[2].value.Bytes(), []byte("test string3")) { t.Fatalf("tag (2) value not correct") } if tags[3].tagId != 0x44 { t.Fatalf("tag (3) tag-ID not correct") - } else if bytes.Compare(tags[3].value.Bytes(), originalBytes) != 0 { + } else if !bytes.Equal(tags[3].value.Bytes(), originalBytes) { t.Fatalf("tag (3) value not correct") } } @@ -469,12 +469,12 @@ func TestIfdBuilder_FindN__First_2_2Returned(t *testing.T) { tags := ib.Tags() bt = tags[found[0]] - if bt.tagId != 0x11 || bytes.Compare(bt.value.Bytes(), []byte("test string")) != 0 { + if bt.tagId != 0x11 || !bytes.Equal(bt.value.Bytes(), []byte("test string")) { log.Panicf("Found entry 0 is not correct: (0x%04x) [%s]", bt.tagId, bt.value) } bt = tags[found[1]] - if bt.tagId != 0x11 || bytes.Compare(bt.value.Bytes(), []byte("test string4")) != 0 { + if bt.tagId != 0x11 || !bytes.Equal(bt.value.Bytes(), []byte("test string4")) { log.Panicf("Found entry 1 is not correct: (0x%04x) [%s]", bt.tagId, bt.value) } } @@ -764,7 +764,7 @@ func TestIfdBuilder_Find__Miss(t *testing.T) { _, err = ib.Find(0x99) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -813,7 +813,7 @@ func TestIfdBuilder_Replace(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-replace tags are not correct.") } @@ -832,7 +832,7 @@ func TestIfdBuilder_Replace(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) { t.Fatalf("Post-replace tags are not correct.") } } @@ -881,7 +881,7 @@ func TestIfdBuilder_ReplaceN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-replace tags are not correct.") } @@ -900,7 +900,7 @@ func TestIfdBuilder_ReplaceN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) { t.Fatalf("Post-replace tags are not correct.") } } @@ -963,7 +963,7 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -979,7 +979,7 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Post-delete (1) tags not correct.") } @@ -995,14 +995,14 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete (2) tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1065,7 +1065,7 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1081,7 +1081,7 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Post-delete (1) tags not correct.") } @@ -1097,14 +1097,14 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete (2) tags not correct.") } err = ib.DeleteN(0x22, 1) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1167,7 +1167,7 @@ func TestIfdBuilder_DeleteN_Two(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1183,14 +1183,14 @@ func TestIfdBuilder_DeleteN_Two(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1253,7 +1253,7 @@ func TestIfdBuilder_DeleteAll(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1271,14 +1271,14 @@ func TestIfdBuilder_DeleteAll(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1375,7 +1375,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) { "TAG", } - if reflect.DeepEqual(actual, expected) == false { + if !reflect.DeepEqual(actual, expected) { fmt.Printf("ACTUAL:\n%s\n\nEXPECTED:\n%s\n", strings.Join(actual, "\n"), strings.Join(expected, "\n")) t.Fatalf("IB did not [correctly] duplicate the IFD structure.") } @@ -1425,7 +1425,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) { // Check the thumbnail. - if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 { + if !bytes.Equal(recoveredThumbnailData, originalThumbnailData) { t.Fatalf("recovered thumbnail does not match original") } @@ -1493,7 +1493,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) { recoveredValueBytes, err := recoveredIte.ValueBytes(recoveredIndex.RootIfd.addressableData, recoveredIndex.RootIfd.ByteOrder) log.PanicIf(err) - if bytes.Compare(originalValueBytes, recoveredValueBytes) != 0 { + if !bytes.Equal(originalValueBytes, recoveredValueBytes) { t.Fatalf("bytes of tag content not correct: %s != %s", originalIte, recoveredIte) } } @@ -1554,7 +1554,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) { // // Check the thumbnail. -// if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 { +// if !bytes.Equal(recoveredThumbnailData, originalThumbnailData) { // t.Fatalf("recovered thumbnail does not match original") // } @@ -1627,10 +1627,10 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) { // expectedValueBytes = append(expectedValueBytes, []byte{'A', 'S', 'C', 'I', 'I', 0, 0, 0}...) // expectedValueBytes = append(expectedValueBytes, []byte("TEST COMMENT")...) -// if bytes.Compare(recoveredValueBytes, expectedValueBytes) != 0 { +// if !bytes.Equal(recoveredValueBytes, expectedValueBytes) { // t.Fatalf("Recovered UserComment does not have the right value: %v != %v", recoveredValueBytes, expectedValueBytes) // } -// } else if bytes.Compare(recoveredValueBytes, originalValueBytes) != 0 { +// } else if !bytes.Equal(recoveredValueBytes, originalValueBytes) { // t.Fatalf("bytes of tag content not correct: %v != %v ITE=%s", recoveredValueBytes, originalValueBytes, recoveredIte) // } // } @@ -1838,7 +1838,7 @@ func TestNewStandardBuilderTag__OneUnit(t *testing.T) { t.Fatalf("II in BuilderTag not correct") } else if bt.tagId != 0x8833 { t.Fatalf("tag-ID not correct") - } else if bytes.Compare(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) { t.Fatalf("value not correct") } } diff --git a/ifd_enumerate.go b/ifd_enumerate.go index 317e847..eb9d175 100644 --- a/ifd_enumerate.go +++ b/ifd_enumerate.go @@ -2,6 +2,7 @@ package exif import ( "bytes" + "context" "errors" "fmt" "reflect" @@ -11,7 +12,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -52,7 +53,6 @@ var ( type IfdTagEnumerator struct { byteOrder binary.ByteOrder addressableData []byte - ifdOffset uint32 buffer *bytes.Buffer } @@ -119,12 +119,11 @@ func (ife *IfdTagEnumerator) getUint32() (value uint32, raw []byte, err error) { } type IfdEnumerate struct { - exifData []byte - buffer *bytes.Buffer - byteOrder binary.ByteOrder - currentOffset uint32 - tagIndex *TagIndex - ifdMapping *IfdMapping + exifData []byte + buffer *bytes.Buffer + byteOrder binary.ByteOrder + tagIndex *TagIndex + ifdMapping *IfdMapping } func NewIfdEnumerate(ifdMapping *IfdMapping, tagIndex *TagIndex, exifData []byte, byteOrder binary.ByteOrder) *IfdEnumerate { @@ -167,7 +166,7 @@ func (ie *IfdEnumerate) parseTag(fqIfdPath string, tagPosition int, ite *IfdTagE valueOffset, rawValueOffset, err := ite.getUint32() log.PanicIf(err) - if _, found := TypeNames[tagType]; found == false { + if _, found := TypeNames[tagType]; !found { log.Panic(ErrTagTypeNotValid) } @@ -184,7 +183,7 @@ func (ie *IfdEnumerate) parseTag(fqIfdPath string, tagPosition int, ite *IfdTagE RawValueOffset: rawValueOffset, } - if resolveValue == true { + if resolveValue { value, isUnhandledUnknown, err := ie.resolveTagValue(tag) log.PanicIf(err) @@ -203,7 +202,7 @@ func (ie *IfdEnumerate) parseTag(fqIfdPath string, tagPosition int, ite *IfdTagE // We also need to set `tag.ChildFqIfdPath` but can't do it here // because we don't have the IFD index. - } else if log.Is(err, ErrChildIfdNotMapped) == false { + } else if !log.Is(err, ErrChildIfdNotMapped) { log.Panic(err) } @@ -248,16 +247,16 @@ func (ie *IfdEnumerate) resolveTagValue(ite *IfdTagEntry) (valueBytes []byte, is log.Panic(err) } else { - switch value.(type) { + switch v := value.(type) { case []byte: - return value.([]byte), false, nil + return v, false, nil case TagUnknownType_UnknownValue: - b := []byte(value.(TagUnknownType_UnknownValue)) + b := []byte(v) return b, false, nil case string: - return []byte(value.(string)), false, nil + return []byte(v), false, nil case UnknownTagValue: - valueBytes, err := value.(UnknownTagValue).ValueBytes() + valueBytes, err := v.ValueBytes() log.PanicIf(err) return valueBytes, false, nil @@ -272,15 +271,15 @@ func (ie *IfdEnumerate) resolveTagValue(ite *IfdTagEntry) (valueBytes []byte, is tt := NewTagType(TypeByte, ie.byteOrder) - if tt.valueIsEmbedded(byteCount) == true { - iteLogger.Debugf(nil, "Reading BYTE value (ITE; embedded).") + if tt.valueIsEmbedded(byteCount) { + iteLogger.Debugf(context.TODO(), "Reading BYTE value (ITE; embedded).") // In this case, the bytes normally used for the offset are actually // data. valueBytes, err = tt.ParseBytes(ite.RawValueOffset, byteCount) log.PanicIf(err) } else { - iteLogger.Debugf(nil, "Reading BYTE value (ITE; at offset).") + iteLogger.Debugf(context.TODO(), "Reading BYTE value (ITE; at offset).") valueBytes, err = tt.ParseBytes(addressableData[ite.ValueOffset:], byteCount) log.PanicIf(err) @@ -330,12 +329,12 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, ite *IfdTagEnum var ok bool visitorWrapper, ok = visitor.(RawTagWalk) - if ok == false { + if !ok { // Legacy usage. // `ok` can be `true` but `legacyVisitor` can still be `nil` (when // passed as nil). - if legacyVisitor, ok := visitor.(RawTagVisitor); ok == true && legacyVisitor != nil { + if legacyVisitor, ok := visitor.(RawTagVisitor); ok && legacyVisitor != nil { visitorWrapper = RawTagWalkLegacyWrapper{ legacyVisitor: legacyVisitor, } @@ -346,7 +345,7 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, ite *IfdTagEnum tagCount, _, err := ite.getUint16() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Current IFD tag-count: (%d)", tagCount) + ifdEnumerateLogger.Debugf(context.TODO(), "Current IFD tag-count: (%d)", tagCount) entries = make([]*IfdTagEntry, 0) @@ -356,8 +355,8 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, ite *IfdTagEnum for i := 0; i < int(tagCount); i++ { tag, err := ie.parseTag(fqIfdPath, i, ite, resolveValues) if err != nil { - if log.Is(err, ErrTagTypeNotValid) == true { - ifdEnumerateLogger.Warningf(nil, "Tag in IFD [%s] at position (%d) has invalid type and will be skipped.", fqIfdPath, i) + if log.Is(err, ErrTagTypeNotValid) { + ifdEnumerateLogger.Warningf(context.TODO(), "Tag in IFD [%s] at position (%d) has invalid type and will be skipped.", fqIfdPath, i) continue } @@ -386,8 +385,8 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, ite *IfdTagEnum // (the standard IFD tag type), later, unless we skip it because it's // [likely] not even in the standard list of known tags. if tag.ChildIfdPath != "" { - if doDescend == true { - ifdEnumerateLogger.Debugf(nil, "Descending to IFD [%s].", tag.ChildIfdPath) + if doDescend { + ifdEnumerateLogger.Debugf(context.TODO(), "Descending to IFD [%s].", tag.ChildIfdPath) err := ie.scan(tag.ChildFqIfdPath, tag.ValueOffset, visitor, resolveValues) log.PanicIf(err) @@ -405,7 +404,7 @@ func (ie *IfdEnumerate) ParseIfd(fqIfdPath string, ifdIndex int, ite *IfdTagEnum nextIfdOffset, _, err = ite.getUint32() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Next IFD at offset: (%08x)", nextIfdOffset) + ifdEnumerateLogger.Debugf(context.TODO(), "Next IFD at offset: (%08x)", nextIfdOffset) return nextIfdOffset, entries, thumbnailData, nil } @@ -448,7 +447,7 @@ func (ie *IfdEnumerate) scan(fqIfdName string, ifdOffset uint32, visitor interfa }() for ifdIndex := 0; ; ifdIndex++ { - ifdEnumerateLogger.Debugf(nil, "Parsing IFD [%s] (%d) at offset (%04x).", fqIfdName, ifdIndex, ifdOffset) + ifdEnumerateLogger.Debugf(context.TODO(), "Parsing IFD [%s] (%d) at offset (%04x).", fqIfdName, ifdIndex, ifdOffset) ite := ie.getTagEnumerator(ifdOffset) nextIfdOffset, _, _, err := ie.ParseIfd(fqIfdName, ifdIndex, ite, visitor, true, resolveValues) @@ -586,7 +585,7 @@ func (ifd *Ifd) FindTagWithId(tagId uint16) (results []*IfdTagEntry, err error) }() results, found := ifd.EntriesByTagId[tagId] - if found != true { + if !found { log.Panic(ErrTagNotFound) } @@ -603,7 +602,7 @@ func (ifd *Ifd) FindTagWithName(tagName string) (results []*IfdTagEntry, err err }() it, err := ifd.tagIndex.GetWithName(ifd.IfdPath, tagName) - if log.Is(err, ErrTagNotFound) == true { + if log.Is(err, ErrTagNotFound) { log.Panic(ErrTagNotStandard) } else if err != nil { log.Panic(err) @@ -662,7 +661,7 @@ func (ifd *Ifd) dumpTags(tags []*IfdTagEntry) []*IfdTagEntry { ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[tag.ChildIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", tag.ChildIfdPath) } @@ -712,7 +711,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo } var value interface{} - if populateValues == true { + if populateValues { var err error value, err = ifd.TagValue(tag) @@ -732,7 +731,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[tag.ChildIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", tag.ChildIfdPath) } @@ -773,7 +772,7 @@ func (ifd *Ifd) printIfdTree(level int, nextLink bool) { ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[tag.ChildIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", tag.ChildIfdPath) } @@ -820,7 +819,7 @@ func (ifd *Ifd) dumpTree(tagsDump []string, level int) []string { ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[tag.ChildIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", tag.ChildIfdPath) } @@ -867,28 +866,28 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { log.Panicf("GPS can only be read on GPS IFD: [%s] != [%s]", ifd.IfdPath, IfdPathStandardGps) } - if tags, found := ifd.EntriesByTagId[TagVersionId]; found == false { + if tags, found := ifd.EntriesByTagId[TagVersionId]; !found { // We've seen this. We'll just have to default to assuming we're in a // 2.2.0.0 format. - ifdEnumerateLogger.Warningf(nil, "No GPS version tag (0x%04x) found.", TagVersionId) + ifdEnumerateLogger.Warningf(context.TODO(), "No GPS version tag (0x%04x) found.", TagVersionId) } else { hit := false for _, acceptedGpsVersion := range ValidGpsVersions { - if bytes.Compare(tags[0].value, acceptedGpsVersion[:]) == 0 { + if bytes.Equal(tags[0].value, acceptedGpsVersion[:]) { hit = true break } } - if hit != true { - ifdEnumerateLogger.Warningf(nil, "GPS version not supported: %v", tags[0].value) + if !hit { + ifdEnumerateLogger.Warningf(context.TODO(), "GPS version not supported: %v", tags[0].value) log.Panic(ErrNoGpsTags) } } tags, found := ifd.EntriesByTagId[TagLatitudeId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "latitude not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "latitude not found") log.Panic(ErrNoGpsTags) } @@ -897,8 +896,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { // Look for whether North or South. tags, found = ifd.EntriesByTagId[TagLatitudeRefId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "latitude-ref not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "latitude-ref not found") log.Panic(ErrNoGpsTags) } @@ -906,8 +905,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { log.PanicIf(err) tags, found = ifd.EntriesByTagId[TagLongitudeId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "longitude not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "longitude not found") log.Panic(ErrNoGpsTags) } @@ -916,8 +915,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { // Look for whether West or East. tags, found = ifd.EntriesByTagId[TagLongitudeRefId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "longitude-ref not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "longitude-ref not found") log.Panic(ErrNoGpsTags) } @@ -949,7 +948,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { altitudeTags, foundAltitude := ifd.EntriesByTagId[TagAltitudeId] altitudeRefTags, foundAltitudeRef := ifd.EntriesByTagId[TagAltitudeRefId] - if foundAltitude == true && foundAltitudeRef == true { + if foundAltitude && foundAltitudeRef { altitudeValue, err := ifd.TagValue(altitudeTags[0]) log.PanicIf(err) @@ -970,7 +969,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { timestampTags, foundTimestamp := ifd.EntriesByTagId[TagTimestampId] datestampTags, foundDatestamp := ifd.EntriesByTagId[TagDatestampId] - if foundTimestamp == true && foundDatestamp == true { + if foundTimestamp && foundDatestamp { datestampValue, err := ifd.TagValue(datestampTags[0]) log.PanicIf(err) @@ -1098,7 +1097,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32, resolveValues bool) (index queue = queue[1:] - ifdEnumerateLogger.Debugf(nil, "Parsing IFD [%s] (%d) at offset (%04x).", ifdPath, index, offset) + ifdEnumerateLogger.Debugf(context.TODO(), "Parsing IFD [%s] (%d) at offset (%04x).", ifdPath, index, offset) ite := ie.getTagEnumerator(offset) nextIfdOffset, entries, thumbnailData, err := ie.ParseIfd(fqIfdPath, index, ite, nil, false, resolveValues) @@ -1109,7 +1108,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32, resolveValues bool) (index entriesByTagId := make(map[uint16][]*IfdTagEntry) for _, tag := range entries { tags, found := entriesByTagId[tag.TagId] - if found == false { + if !found { tags = make([]*IfdTagEntry, 0) } @@ -1155,7 +1154,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32, resolveValues bool) (index // Install into by-name buckets. - if list_, found := lookup[ifdPath]; found == true { + if list_, found := lookup[ifdPath]; found { lookup[ifdPath] = append(list_, ifd) } else { list_ = make([]*Ifd, 1) @@ -1165,7 +1164,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32, resolveValues bool) (index } // Add a link from the previous IFD in the chain to us. - if previousIfd, found := edges[offset]; found == true { + if previousIfd, found := edges[offset]; found { previousIfd.NextIfd = ifd } diff --git a/ifd_enumerate_test.go b/ifd_enumerate_test.go index 3050ac6..0ab6655 100644 --- a/ifd_enumerate_test.go +++ b/ifd_enumerate_test.go @@ -10,7 +10,7 @@ import ( "encoding/binary" "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestIfdTagEntry_ValueBytes(t *testing.T) { @@ -35,7 +35,7 @@ func TestIfdTagEntry_ValueBytes(t *testing.T) { decodedBytes, err := ite.ValueBytes(ed.Encoded, byteOrder) log.PanicIf(err) - if bytes.Compare(decodedBytes, original) != 0 { + if !bytes.Equal(decodedBytes, original) { t.Fatalf("Bytes not decoded correctly.") } } @@ -82,7 +82,7 @@ func TestIfdTagEntry_ValueBytes_RealData(t *testing.T) { if len(decodedBytes) != int(ite.UnitCount) { t.Fatalf("Decoded bytes not the right count.") - } else if bytes.Compare(decodedBytes, expected) != 0 { + } else if !bytes.Equal(decodedBytes, expected) { t.Fatalf("Decoded bytes not correct.") } } @@ -103,6 +103,7 @@ func TestIfd_FindTagWithId_Hit(t *testing.T) { ifd := index.RootIfd results, err := ifd.FindTagWithId(0x011b) + log.PanicIf(err) if len(results) != 1 { t.Fatalf("Exactly one result was not found: (%d)", len(results)) @@ -130,7 +131,7 @@ func TestIfd_FindTagWithId_Miss(t *testing.T) { _, err = ifd.FindTagWithId(0xffff) if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotFound) == false { + } else if !log.Is(err, ErrTagNotFound) { log.Panic(err) } } @@ -151,6 +152,7 @@ func TestIfd_FindTagWithName_Hit(t *testing.T) { ifd := index.RootIfd results, err := ifd.FindTagWithName("YResolution") + log.PanicIf(err) if len(results) != 1 { t.Fatalf("Exactly one result was not found: (%d)", len(results)) @@ -178,7 +180,7 @@ func TestIfd_FindTagWithName_Miss(t *testing.T) { _, err = ifd.FindTagWithName("PlanarConfiguration") if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotFound) == false { + } else if !log.Is(err, ErrTagNotFound) { log.Panic(err) } } @@ -202,7 +204,7 @@ func TestIfd_FindTagWithName_NonStandard(t *testing.T) { _, err = ifd.FindTagWithName("GeorgeNotAtHome") if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotStandard) == false { + } else if !log.Is(err, ErrTagNotStandard) { log.Panic(err) } } @@ -236,7 +238,7 @@ func TestIfd_Thumbnail(t *testing.T) { expected, err := ioutil.ReadFile(expectedFilepath) log.PanicIf(err) - if bytes.Compare(actual, expected) != 0 { + if !bytes.Equal(actual, expected) { t.Fatalf("thumbnail not correct") } } diff --git a/ifd_tag_entry.go b/ifd_tag_entry.go index 59e79cc..13e3a3e 100644 --- a/ifd_tag_entry.go +++ b/ifd_tag_entry.go @@ -1,12 +1,13 @@ package exif import ( + "context" "fmt" "reflect" "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -109,16 +110,16 @@ func (ite *IfdTagEntry) ValueBytes(addressableData []byte, byteOrder binary.Byte value, err := valueContext.Undefined() log.PanicIf(err) - switch value.(type) { + switch v := value.(type) { case []byte: - return value.([]byte), nil + return v, nil case TagUnknownType_UnknownValue: - b := []byte(value.(TagUnknownType_UnknownValue)) + b := []byte(v) return b, nil case string: - return []byte(value.(string)), nil + return []byte(v), nil case UnknownTagValue: - valueBytes, err := value.(UnknownTagValue).ValueBytes() + valueBytes, err := v.ValueBytes() log.PanicIf(err) return valueBytes, nil @@ -133,15 +134,15 @@ func (ite *IfdTagEntry) ValueBytes(addressableData []byte, byteOrder binary.Byte tt := NewTagType(TypeByte, byteOrder) - if tt.valueIsEmbedded(byteCount) == true { - iteLogger.Debugf(nil, "Reading BYTE value (ITE; embedded).") + if tt.valueIsEmbedded(byteCount) { + iteLogger.Debugf(context.TODO(), "Reading BYTE value (ITE; embedded).") // In this case, the bytes normally used for the offset are actually // data. value, err = tt.ParseBytes(ite.RawValueOffset, byteCount) log.PanicIf(err) } else { - iteLogger.Debugf(nil, "Reading BYTE value (ITE; at offset).") + iteLogger.Debugf(context.TODO(), "Reading BYTE value (ITE; at offset).") value, err = tt.ParseBytes(addressableData[ite.ValueOffset:], byteCount) log.PanicIf(err) diff --git a/ifd_tag_entry_test.go b/ifd_tag_entry_test.go index 8aa1db0..6263b70 100644 --- a/ifd_tag_entry_test.go +++ b/ifd_tag_entry_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestIfdTagEntry_ValueString_Allocated(t *testing.T) { @@ -89,7 +89,7 @@ func TestIfdTagEntry_ValueBytes_Allocated(t *testing.T) { value, err := ite.ValueBytes(data, TestDefaultByteOrder) log.PanicIf(err) - if bytes.Compare(value, data) != 0 { + if !bytes.Equal(value, data) { t.Fatalf("Value not expected: [%s] != [%s]", value, data) } } @@ -110,7 +110,7 @@ func TestIfdTagEntry_ValueBytes_Embedded(t *testing.T) { value, err := ite.ValueBytes(nil, TestDefaultByteOrder) log.PanicIf(err) - if bytes.Compare(value, data) != 0 { + if !bytes.Equal(value, data) { t.Fatalf("Value not expected: [%s] != [%s]", value, data) } } @@ -131,7 +131,7 @@ func TestIfdTagEntry_Value_Normal(t *testing.T) { value, err := ite.Value(nil, TestDefaultByteOrder) log.PanicIf(err) - if bytes.Compare(value.([]byte), data) != 0 { + if !bytes.Equal(value.([]byte), data) { t.Fatalf("Value not expected: [%s] != [%s]", value, data) } } @@ -157,7 +157,7 @@ func TestIfdTagEntry_Value_Unknown(t *testing.T) { vb, err := gs.ValueBytes() log.PanicIf(err) - if bytes.Compare(vb, data) != 0 { + if !bytes.Equal(vb, data) { t.Fatalf("Value not expected: [%s] != [%s]", value, data) } } @@ -204,7 +204,7 @@ func TestIfdTagEntryValueResolver_ValueBytes(t *testing.T) { value, err := itevr.ValueBytes(&ite) log.PanicIf(err) - if bytes.Compare(value, allocatedData) != 0 { + if !bytes.Equal(value, allocatedData) { t.Fatalf("bytes not expected: %v != %v", value, allocatedData) } } diff --git a/ifd_test.go b/ifd_test.go index 9b5bd47..5e93097 100644 --- a/ifd_test.go +++ b/ifd_test.go @@ -6,7 +6,7 @@ import ( "sort" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestIfdMapping_Add(t *testing.T) { @@ -229,6 +229,7 @@ func TestIfdMapping_NewIfdMappingWithStandard(t *testing.T) { imWithout := NewIfdMapping() err := LoadStandardIfds(imWithout) + log.PanicIf(err) outputWith, err := imWith.DumpLineages() log.PanicIf(err) diff --git a/parser.go b/parser.go index 4702db2..3dcea25 100644 --- a/parser.go +++ b/parser.go @@ -2,10 +2,11 @@ package exif import ( "bytes" + "context" "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) type Parser struct { @@ -45,7 +46,7 @@ func (p *Parser) ParseAscii(data []byte, unitCount uint32) (value string, err er if len(data) == 0 || data[count-1] != 0 { s := string(data[:count]) - typeLogger.Warningf(nil, "ascii not terminated with nul as expected: [%v]", s) + typeLogger.Warningf(context.TODO(), "ascii not terminated with nul as expected: [%v]", s) return s, nil } else { diff --git a/tag_type.go b/tag_type.go index e53b1c4..b1a9bdb 100644 --- a/tag_type.go +++ b/tag_type.go @@ -7,7 +7,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) type TagType struct { @@ -18,7 +18,7 @@ type TagType struct { func NewTagType(tagType TagTypePrimitive, byteOrder binary.ByteOrder) TagType { name, found := TypeNames[tagType] - if found == false { + if !found { log.Panicf("tag-type not valid: 0x%04x", tagType) } @@ -58,23 +58,6 @@ func (tt TagType) valueIsEmbedded(unitCount uint32) bool { return (tt.tagType.Size() * int(unitCount)) <= 4 } -func (tt TagType) readRawEncoded(valueContext ValueContext) (rawBytes []byte, err error) { - defer func() { - if state := recover(); state != nil { - err = log.Wrap(state.(error)) - } - }() - - unitSizeRaw := uint32(tt.tagType.Size()) - - if tt.valueIsEmbedded(valueContext.UnitCount()) == true { - byteLength := unitSizeRaw * valueContext.UnitCount() - return valueContext.RawValueOffset()[:byteLength], nil - } else { - return valueContext.AddressableData()[valueContext.ValueOffset() : valueContext.ValueOffset()+valueContext.UnitCount()*unitSizeRaw], nil - } -} - func (tt TagType) ParseBytes(data []byte, unitCount uint32) (value []uint8, err error) { defer func() { if state := recover(); state != nil { @@ -334,7 +317,7 @@ func (tt TagType) ResolveAsString(valueContext ValueContext, justFirst bool) (va } }() - if justFirst == true { + if justFirst { value, err = valueContext.FormatFirst() log.PanicIf(err) } else { diff --git a/tags.go b/tags.go index 7f7e515..b6960d8 100644 --- a/tags.go +++ b/tags.go @@ -1,9 +1,10 @@ package exif import ( + "context" "fmt" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" "gopkg.in/yaml.v2" ) @@ -98,12 +99,12 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) { // Store by ID. family, found := ti.tagsByIfd[it.IfdPath] - if found == false { + if !found { family = make(map[uint16]*IndexedTag) ti.tagsByIfd[it.IfdPath] = family } - if _, found := family[it.Id]; found == true { + if _, found := family[it.Id]; found { log.Panicf("tag-ID defined more than once for IFD [%s]: (%02x)", it.IfdPath, it.Id) } @@ -112,12 +113,12 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) { // Store by name. familyR, found := ti.tagsByIfdR[it.IfdPath] - if found == false { + if !found { familyR = make(map[string]*IndexedTag) ti.tagsByIfdR[it.IfdPath] = familyR } - if _, found := familyR[it.Name]; found == true { + if _, found := familyR[it.Name]; found { log.Panicf("tag-name defined more than once for IFD [%s]: (%s)", it.IfdPath, it.Name) } @@ -140,12 +141,12 @@ func (ti *TagIndex) Get(ifdPath string, id uint16) (it *IndexedTag, err error) { } family, found := ti.tagsByIfd[ifdPath] - if found == false { + if !found { log.Panic(ErrTagNotFound) } it, found = family[id] - if found == false { + if !found { log.Panic(ErrTagNotFound) } @@ -166,7 +167,7 @@ func (ti *TagIndex) GetWithName(ifdPath string, name string) (it *IndexedTag, er } it, found := ti.tagsByIfdR[ifdPath][name] - if found != true { + if !found { log.Panic(ErrTagNotFound) } @@ -204,7 +205,7 @@ func LoadStandardTags(ti *TagIndex) (err error) { } tagTypeId, found := TypeNamesR[tagTypeName] - if found == false { + if !found { log.Panicf("type [%s] for [%s] not valid", tagTypeName, tagName) continue } @@ -223,7 +224,7 @@ func LoadStandardTags(ti *TagIndex) (err error) { } } - tagsLogger.Debugf(nil, "(%d) tags loaded.", count) + tagsLogger.Debugf(context.TODO(), "(%d) tags loaded.", count) return nil } diff --git a/tags_test.go b/tags_test.go index 01dcc65..12f24b8 100644 --- a/tags_test.go +++ b/tags_test.go @@ -3,7 +3,7 @@ package exif import ( "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestGet(t *testing.T) { @@ -12,7 +12,7 @@ func TestGet(t *testing.T) { it, err := ti.Get(IfdPathStandard, 0x10f) log.PanicIf(err) - if it.Is(IfdPathStandard, 0x10f) == false || it.IsName(IfdPathStandard, "Make") == false { + if !it.Is(IfdPathStandard, 0x10f) || !it.IsName(IfdPathStandard, "Make") { t.Fatalf("tag info not correct") } } @@ -23,7 +23,7 @@ func TestGetWithName(t *testing.T) { it, err := ti.GetWithName(IfdPathStandard, "Make") log.PanicIf(err) - if it.Is(IfdPathStandard, 0x10f) == false || it.Is(IfdPathStandard, 0x10f) == false { + if !it.Is(IfdPathStandard, 0x10f) { t.Fatalf("tag info not correct") } } diff --git a/tags_undefined.go b/tags_undefined.go index 63ba593..e1ac25c 100644 --- a/tags_undefined.go +++ b/tags_undefined.go @@ -2,13 +2,14 @@ package exif import ( "bytes" + "context" "fmt" "strings" "crypto/sha1" "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) const ( @@ -114,7 +115,7 @@ func (uc TagUnknownType_9298_UserComment) String() string { func (uc TagUnknownType_9298_UserComment) ValueBytes() (value []byte, err error) { encodingTypeBytes, found := TagUnknownType_9298_UserComment_Encodings[uc.EncodingType] - if found == false { + if !found { log.Panicf("encoding-type not valid for unknown-type tag 9298 (UserComment): (%d)", uc.EncodingType) } @@ -255,7 +256,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte var valueContextPtr *ValueContext - if vc, ok := valueContext.(*ValueContext); ok == true { + if vc, ok := valueContext.(*ValueContext); ok { // Legacy usage. valueContextPtr = vc @@ -266,7 +267,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte valueContextPtr = &valueContextValue } - typeLogger.Debugf(nil, "UndefinedValue: IFD-PATH=[%s] TAG-ID=(0x%02x)", ifdPath, tagId) + typeLogger.Debugf(context.TODO(), "UndefinedValue: IFD-PATH=[%s] TAG-ID=(0x%02x)", ifdPath, tagId) if ifdPath == IfdPathStandardExif { if tagId == 0x9000 { @@ -302,7 +303,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte encoding := valueBytes[:8] for encodingIndex, encodingBytes := range TagUnknownType_9298_UserComment_Encodings { - if bytes.Compare(encoding, encodingBytes) == 0 { + if bytes.Equal(encoding, encodingBytes) { uc := TagUnknownType_9298_UserComment{ EncodingType: encodingIndex, EncodingBytes: valueBytes[8:], @@ -312,7 +313,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte } } - typeLogger.Warningf(nil, "User-comment encoding not valid. Returning 'unknown' type (the default).") + typeLogger.Warningf(context.TODO(), "User-comment encoding not valid. Returning 'unknown' type (the default).") return unknownUc, nil } else if tagId == 0x927c { // MakerNote @@ -352,7 +353,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte log.PanicIf(err) for configurationId, configurationBytes := range TagUnknownType_9101_ComponentsConfiguration_Configurations { - if bytes.Compare(valueBytes, configurationBytes) == 0 { + if bytes.Equal(valueBytes, configurationBytes) { cc := TagUnknownType_9101_ComponentsConfiguration{ ConfigurationId: configurationId, ConfigurationBytes: valueBytes, diff --git a/tags_undefined_test.go b/tags_undefined_test.go index 0403178..43824f8 100644 --- a/tags_undefined_test.go +++ b/tags_undefined_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestUndefinedValue_ExifVersion(t *testing.T) { @@ -75,7 +75,7 @@ func TestUndefinedValue_ExifVersion(t *testing.T) { t.Fatalf("Tag type not correct: (%d)", ite.TagType) } else if ite.UnitCount != (uint32(len(valueString))) { t.Fatalf("Tag unit-count not correct: (%d)", ite.UnitCount) - } else if bytes.Compare(ite.RawValueOffset, []byte{'0', '2', '3', '0'}) != 0 { + } else if !bytes.Equal(ite.RawValueOffset, []byte{'0', '2', '3', '0'}) { t.Fatalf("Tag's value (as raw bytes) is not correct: [%x]", ite.RawValueOffset) } else if ite.ChildIfdPath != "" { t.Fatalf("Tag's child IFD-path should be empty: [%s]", ite.ChildIfdPath) diff --git a/type.go b/type.go index 2012b60..1dce50b 100644 --- a/type.go +++ b/type.go @@ -8,7 +8,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) type TagTypePrimitive uint16 @@ -132,7 +132,7 @@ func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder // Truncate the items if it's not bytes or a string and we just want the first. valueSuffix := "" - if justFirst == true && unitCount > 1 && tagType != TypeByte && tagType != TypeAscii && tagType != TypeAsciiNoNul { + if justFirst && unitCount > 1 && tagType != TypeByte && tagType != TypeAscii && tagType != TypeAsciiNoNul { unitCount = 1 valueSuffix = "..." } @@ -157,7 +157,7 @@ func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder log.PanicIf(err) if len(items) > 0 { - if justFirst == true { + if justFirst { return fmt.Sprintf("%v%s", items[0], valueSuffix), nil } else { return fmt.Sprintf("%v", items), nil @@ -170,7 +170,7 @@ func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder log.PanicIf(err) if len(items) > 0 { - if justFirst == true { + if justFirst { return fmt.Sprintf("%v%s", items[0], valueSuffix), nil } else { return fmt.Sprintf("%v", items), nil @@ -188,7 +188,7 @@ func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder parts[i] = fmt.Sprintf("%d/%d", r.Numerator, r.Denominator) } - if justFirst == true { + if justFirst { return fmt.Sprintf("%v%s", parts[0], valueSuffix), nil } else { return fmt.Sprintf("%v", parts), nil @@ -201,7 +201,7 @@ func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder log.PanicIf(err) if len(items) > 0 { - if justFirst == true { + if justFirst { return fmt.Sprintf("%v%s", items[0], valueSuffix), nil } else { return fmt.Sprintf("%v", items), nil @@ -219,7 +219,7 @@ func Format(rawBytes []byte, tagType TagTypePrimitive, justFirst bool, byteOrder } if len(items) > 0 { - if justFirst == true { + if justFirst { return fmt.Sprintf("%v%s", parts[0], valueSuffix), nil } else { return fmt.Sprintf("%v", parts), nil diff --git a/type_encode.go b/type_encode.go index 9ff7549..3768487 100644 --- a/type_encode.go +++ b/type_encode.go @@ -6,11 +6,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" -) - -var ( - typeEncodeLogger = log.NewLogger("exif.type_encode") + log "github.com/dsoprea/go-logging" ) // EncodedData encapsulates the compound output of an encoding operation. @@ -189,27 +185,27 @@ func (ve *ValueEncoder) Encode(value interface{}) (ed EncodedData, err error) { // TODO(dustin): This is redundant with EncodeWithType. Refactor one to use the other. - switch value.(type) { + switch v := value.(type) { case []byte: - ed, err = ve.encodeBytes(value.([]byte)) + ed, err = ve.encodeBytes(v) log.PanicIf(err) case string: - ed, err = ve.encodeAscii(value.(string)) + ed, err = ve.encodeAscii(v) log.PanicIf(err) case []uint16: - ed, err = ve.encodeShorts(value.([]uint16)) + ed, err = ve.encodeShorts(v) log.PanicIf(err) case []uint32: - ed, err = ve.encodeLongs(value.([]uint32)) + ed, err = ve.encodeLongs(v) log.PanicIf(err) case []Rational: - ed, err = ve.encodeRationals(value.([]Rational)) + ed, err = ve.encodeRationals(v) log.PanicIf(err) case []int32: - ed, err = ve.encodeSignedLongs(value.([]int32)) + ed, err = ve.encodeSignedLongs(v) log.PanicIf(err) case []SignedRational: - ed, err = ve.encodeSignedRationals(value.([]SignedRational)) + ed, err = ve.encodeSignedRationals(v) log.PanicIf(err) default: log.Panicf("value not encodable: [%s] [%v]", reflect.TypeOf(value), value) diff --git a/type_encode_test.go b/type_encode_test.go index 3f7acd6..62d46d5 100644 --- a/type_encode_test.go +++ b/type_encode_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestByteCycle(t *testing.T) { @@ -30,6 +30,7 @@ func TestByteCycle(t *testing.T) { tt := NewTagType(ed.Type, byteOrder) recovered, err := tt.ParseBytes(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") @@ -63,6 +64,7 @@ func TestAsciiCycle(t *testing.T) { tt := NewTagType(TypeAscii, byteOrder) recovered, err := tt.ParseAscii(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") @@ -95,6 +97,7 @@ func TestAsciiNoNulCycle(t *testing.T) { tt := NewTagType(TypeAsciiNoNul, byteOrder) recovered, err := tt.ParseAsciiNoNul(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, string(expected)) != true { t.Fatalf("Value not recovered correctly.") @@ -130,6 +133,7 @@ func TestShortCycle(t *testing.T) { tt := NewTagType(ed.Type, byteOrder) recovered, err := tt.ParseShorts(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") @@ -165,6 +169,7 @@ func TestLongCycle(t *testing.T) { tt := NewTagType(ed.Type, byteOrder) recovered, err := tt.ParseLongs(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") @@ -226,6 +231,7 @@ func TestRationalCycle(t *testing.T) { tt := NewTagType(ed.Type, byteOrder) recovered, err := tt.ParseRationals(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") @@ -261,6 +267,7 @@ func TestSignedLongCycle(t *testing.T) { tt := NewTagType(ed.Type, byteOrder) recovered, err := tt.ParseSignedLongs(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") @@ -322,6 +329,7 @@ func TestSignedRationalCycle(t *testing.T) { tt := NewTagType(ed.Type, byteOrder) recovered, err := tt.ParseSignedRationals(ed.Encoded, ed.UnitCount) + log.PanicIf(err) if reflect.DeepEqual(recovered, original) != true { t.Fatalf("Value not recovered correctly.") diff --git a/type_test.go b/type_test.go index 6039abc..04d6ac2 100644 --- a/type_test.go +++ b/type_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestTagType_EncodeDecode_Byte(t *testing.T) { @@ -17,14 +17,14 @@ func TestTagType_EncodeDecode_Byte(t *testing.T) { encoded, err := tt.Encode(data) log.PanicIf(err) - if bytes.Compare(encoded, data) != 0 { + if !bytes.Equal(encoded, data) { t.Fatalf("Data not encoded correctly.") } restored, err := tt.ParseBytes(encoded, uint32(len(data))) log.PanicIf(err) - if bytes.Compare(restored, data) != 0 { + if !bytes.Equal(restored, data) { t.Fatalf("Data not decoded correctly.") } } @@ -57,7 +57,7 @@ func TestTagType_EncodeDecode_Shorts(t *testing.T) { encoded, err := tt.Encode(data) log.PanicIf(err) - if bytes.Compare(encoded, []byte{0x00, 0x11, 0x00, 0x22, 0x00, 0x33}) != 0 { + if !bytes.Equal(encoded, []byte{0x00, 0x11, 0x00, 0x22, 0x00, 0x33}) { t.Fatalf("Data not encoded correctly.") } @@ -77,7 +77,7 @@ func TestTagType_EncodeDecode_Long(t *testing.T) { encoded, err := tt.Encode(data) log.PanicIf(err) - if bytes.Compare(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33}) != 0 { + if !bytes.Equal(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33}) { t.Fatalf("Data not encoded correctly.") } @@ -100,7 +100,7 @@ func TestTagType_EncodeDecode_Rational(t *testing.T) { encoded, err := tt.Encode(data) log.PanicIf(err) - if bytes.Compare(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x44}) != 0 { + if !bytes.Equal(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x44}) { t.Fatalf("Data not encoded correctly.") } @@ -120,7 +120,7 @@ func TestTagType_EncodeDecode_SignedLong(t *testing.T) { encoded, err := tt.Encode(data) log.PanicIf(err) - if bytes.Compare(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33}) != 0 { + if !bytes.Equal(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33}) { t.Fatalf("Data not encoded correctly.") } @@ -143,7 +143,7 @@ func TestTagType_EncodeDecode_SignedRational(t *testing.T) { encoded, err := tt.Encode(data) log.PanicIf(err) - if bytes.Compare(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x44}) != 0 { + if !bytes.Equal(encoded, []byte{0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x44}) { t.Fatalf("Data not encoded correctly.") } diff --git a/utility.go b/utility.go index 3d1ea24..8ea8e26 100644 --- a/utility.go +++ b/utility.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func DumpBytes(data []byte) { @@ -174,7 +174,7 @@ func GetFlatExifData(exifData []byte) (exifTags []ExifTag, err error) { it, err := ti.Get(ifd.IfdPath, ite.TagId) if err != nil { // If it's a non-standard tag, just leave the name blank. - if log.Is(err, ErrTagNotFound) != true { + if !log.Is(err, ErrTagNotFound) { log.PanicIf(err) } } else { @@ -209,9 +209,7 @@ func GetFlatExifData(exifData []byte) (exifTags []ExifTag, err error) { exifTags = append(exifTags, et) } - for _, childIfd := range ifd.Children { - q = append(q, childIfd) - } + q = append(q, ifd.Children...) if ifd.NextIfd != nil { q = append(q, ifd.NextIfd) diff --git a/v2/common/ifd.go b/v2/common/ifd.go index 9b93f04..037b720 100644 --- a/v2/common/ifd.go +++ b/v2/common/ifd.go @@ -5,11 +5,7 @@ import ( "fmt" "strings" - "github.com/dsoprea/go-logging" -) - -var ( - ifdLogger = log.NewLogger("exifcommon.ifd") + log "github.com/dsoprea/go-logging" ) var ( @@ -85,7 +81,7 @@ func (im *IfdMapping) Get(parentPlacement []uint16) (childIfd *MappedIfd, err er ptr := im.rootNode for _, tagId := range parentPlacement { - if descendantPtr, found := ptr.Children[tagId]; found == false { + if descendantPtr, found := ptr.Children[tagId]; !found { log.Panicf("ifd child with tag-ID (%04x) not registered: [%s]", tagId, ptr.PathPhrase()) } else { ptr = descendantPtr @@ -308,7 +304,7 @@ func (im *IfdMapping) Add(parentPlacement []uint16, tagId uint16, name string) ( Children: make(map[uint16]*MappedIfd), } - if _, found := ptr.Children[tagId]; found == true { + if _, found := ptr.Children[tagId]; found { log.Panicf("child IFD with tag-ID (%04x) already registered under IFD [%s] with tag-ID (%04x)", tagId, ptr.Name, ptr.TagId) } diff --git a/v2/common/parser.go b/v2/common/parser.go index bbdd8f5..eb2d3c3 100644 --- a/v2/common/parser.go +++ b/v2/common/parser.go @@ -2,10 +2,11 @@ package exifcommon import ( "bytes" + "context" "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -56,7 +57,7 @@ func (p *Parser) ParseAscii(data []byte, unitCount uint32) (value string, err er if len(data) == 0 || data[count-1] != 0 { s := string(data[:count]) - parserLogger.Warningf(nil, "ascii not terminated with nul as expected: [%v]", s) + parserLogger.Warningf(context.TODO(), "ascii not terminated with nul as expected: [%v]", s) return s, nil } diff --git a/v2/common/testing_common.go b/v2/common/testing_common.go index f04fa22..33e8da3 100644 --- a/v2/common/testing_common.go +++ b/v2/common/testing_common.go @@ -5,16 +5,13 @@ import ( "path" "encoding/binary" - "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( moduleRootPath = "" - testExifData []byte = nil - // EncodeDefaultByteOrder is the default byte-order for encoding operations. EncodeDefaultByteOrder = binary.BigEndian @@ -40,7 +37,7 @@ func GetModuleRootPath() string { tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT") _, err := os.Stat(tryStampFilepath) - if err != nil && os.IsNotExist(err) != true { + if err != nil && !os.IsNotExist(err) { log.Panic(err) } else if err == nil { break @@ -66,23 +63,3 @@ func GetTestAssetsPath() string { return assetsPath } - -func getTestImageFilepath() string { - assetsPath := GetTestAssetsPath() - testImageFilepath := path.Join(assetsPath, "NDM_8901.jpg") - return testImageFilepath -} - -func getTestExifData() []byte { - if testExifData == nil { - assetsPath := GetTestAssetsPath() - filepath := path.Join(assetsPath, "NDM_8901.jpg.exif") - - var err error - - testExifData, err = ioutil.ReadFile(filepath) - log.PanicIf(err) - } - - return testExifData -} diff --git a/v2/common/type.go b/v2/common/type.go index 86b38d0..b40612a 100644 --- a/v2/common/type.go +++ b/v2/common/type.go @@ -9,11 +9,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" -) - -var ( - typeLogger = log.NewLogger("exif.type") + log "github.com/dsoprea/go-logging" ) var ( @@ -172,7 +168,7 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error return "", nil } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." @@ -187,7 +183,7 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error return "", nil } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." @@ -206,12 +202,12 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error for i, r := range t { parts[i] = fmt.Sprintf("%d/%d", r.Numerator, r.Denominator) - if justFirst == true { + if justFirst { break } } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." @@ -226,7 +222,7 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error return "", nil } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." @@ -245,12 +241,12 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error for i, r := range t { parts[i] = fmt.Sprintf("%d/%d", r.Numerator, r.Denominator) - if justFirst == true { + if justFirst { break } } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." diff --git a/v2/common/value_context.go b/v2/common/value_context.go index feb078c..591777e 100644 --- a/v2/common/value_context.go +++ b/v2/common/value_context.go @@ -5,7 +5,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -147,7 +147,7 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) { unitSizeRaw := uint32(tagType.Size()) - if vc.isEmbedded() == true { + if vc.isEmbedded() { byteLength := unitSizeRaw * vc.unitCount return vc.rawValueOffset[:byteLength], nil } @@ -158,7 +158,7 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) { // GetFarOffset returns the offset if the value is not embedded [within the // pointer itself] or an error if an embedded value. func (vc *ValueContext) GetFarOffset() (offset uint32, err error) { - if vc.isEmbedded() == true { + if vc.isEmbedded() { return 0, ErrNotFarValue } diff --git a/v2/common/value_encoder.go b/v2/common/value_encoder.go index 52e0eac..dc0c931 100644 --- a/v2/common/value_encoder.go +++ b/v2/common/value_encoder.go @@ -7,11 +7,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" -) - -var ( - typeEncodeLogger = log.NewLogger("exif.type_encode") + log "github.com/dsoprea/go-logging" ) // EncodedData encapsulates the compound output of an encoding operation. @@ -190,27 +186,27 @@ func (ve *ValueEncoder) Encode(value interface{}) (ed EncodedData, err error) { } }() - switch value.(type) { + switch v := value.(type) { case []byte: - ed, err = ve.encodeBytes(value.([]byte)) + ed, err = ve.encodeBytes(v) log.PanicIf(err) case string: - ed, err = ve.encodeAscii(value.(string)) + ed, err = ve.encodeAscii(v) log.PanicIf(err) case []uint16: - ed, err = ve.encodeShorts(value.([]uint16)) + ed, err = ve.encodeShorts(v) log.PanicIf(err) case []uint32: - ed, err = ve.encodeLongs(value.([]uint32)) + ed, err = ve.encodeLongs(v) log.PanicIf(err) case []Rational: - ed, err = ve.encodeRationals(value.([]Rational)) + ed, err = ve.encodeRationals(v) log.PanicIf(err) case []int32: - ed, err = ve.encodeSignedLongs(value.([]int32)) + ed, err = ve.encodeSignedLongs(v) log.PanicIf(err) case []SignedRational: - ed, err = ve.encodeSignedRationals(value.([]SignedRational)) + ed, err = ve.encodeSignedRationals(v) log.PanicIf(err) case time.Time: // For convenience, if the user doesn't want to deal with translation diff --git a/v2/exif-read-tool/main.go b/v2/exif-read-tool/main.go index fde44d2..8fa8176 100644 --- a/v2/exif-read-tool/main.go +++ b/v2/exif-read-tool/main.go @@ -14,17 +14,19 @@ package main import ( + "context" "fmt" "os" "encoding/json" "io/ioutil" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" + + log "github.com/dsoprea/go-logging" "github.com/jessevdk/go-flags" "github.com/dsoprea/go-exif/v2" - "github.com/dsoprea/go-exif/v2/common" ) const ( @@ -76,7 +78,7 @@ func main() { os.Exit(-1) } - if arguments.IsVerbose == true { + if arguments.IsVerbose { cla := log.NewConsoleLogAdapter() log.AddAdapter("console", cla) @@ -102,7 +104,7 @@ func main() { log.Panic(err) } - mainLogger.Debugf(nil, "EXIF blob is (%d) bytes.", len(rawExif)) + mainLogger.Debugf(context.TODO(), "EXIF blob is (%d) bytes.", len(rawExif)) // Run the parse. @@ -120,7 +122,7 @@ func main() { log.PanicIf(err) var thumbnail []byte - if ifd, found := index.Lookup[exif.ThumbnailFqIfdPath]; found == true { + if ifd, found := index.Lookup[exif.ThumbnailFqIfdPath]; found { thumbnail, err = ifd.Thumbnail() if err != nil && err != exif.ErrNoThumbnail { log.Panic(err) @@ -128,9 +130,9 @@ func main() { } if thumbnail == nil { - mainLogger.Debugf(nil, "No thumbnails found.") + mainLogger.Debugf(context.TODO(), "No thumbnails found.") } else { - if arguments.PrintAsJson == false { + if !arguments.PrintAsJson { fmt.Printf("Writing (%d) bytes for thumbnail: [%s]\n", len(thumbnail), thumbnailOutputFilepath) fmt.Printf("\n") } @@ -140,8 +142,8 @@ func main() { } } - if arguments.DoNotPrintTags == false { - if arguments.PrintAsJson == true { + if !arguments.DoNotPrintTags { + if arguments.PrintAsJson { data, err := json.MarshalIndent(entries, "", " ") log.PanicIf(err) diff --git a/v2/exif-read-tool/main_test.go b/v2/exif-read-tool/main_test.go index fcf4d79..d90ecb4 100644 --- a/v2/exif-read-tool/main_test.go +++ b/v2/exif-read-tool/main_test.go @@ -144,12 +144,12 @@ func TestMainJson(t *testing.T) { err = json.Unmarshal(expectedRaw, &expected) log.PanicIf(err) - // if reflect.DeepEqual(actual, expected) == false { + // if !reflect.DeepEqual(actual, expected) { // t.Fatalf("Output not as expected:\nACTUAL:\n%s\nEXPECTED:\n%s", actualRaw, expectedRaw) // } for i, tagInfo := range actual { - if reflect.DeepEqual(tagInfo, expected[i]) == false { + if !reflect.DeepEqual(tagInfo, expected[i]) { actualBytes, err := json.MarshalIndent(tagInfo, "", " ") log.PanicIf(err) diff --git a/v2/exif.go b/v2/exif.go index 20b7237..c11322b 100644 --- a/v2/exif.go +++ b/v2/exif.go @@ -3,6 +3,7 @@ package exif import ( "bufio" "bytes" + "context" "errors" "fmt" "io" @@ -11,9 +12,8 @@ import ( "encoding/binary" "io/ioutil" - "github.com/dsoprea/go-logging" - - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) const ( @@ -99,7 +99,7 @@ func SearchAndExtractExifWithReader(r io.Reader) (rawExif []byte, err error) { _, err = ParseExifHeader(window) if err != nil { - if log.Is(err, ErrNoExif) == true { + if log.Is(err, ErrNoExif) { // No EXIF. Move forward by one byte. _, err := br.Discard(1) @@ -117,7 +117,7 @@ func SearchAndExtractExifWithReader(r io.Reader) (rawExif []byte, err error) { break } - exifLogger.Debugf(nil, "Found EXIF blob (%d) bytes from initial position.", discarded) + exifLogger.Debugf(context.TODO(), "Found EXIF blob (%d) bytes from initial position.", discarded) rawExif, err = ioutil.ReadAll(br) log.PanicIf(err) @@ -174,13 +174,13 @@ func ParseExifHeader(data []byte) (eh ExifHeader, err error) { // -> http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf if len(data) < ExifSignatureLength { - exifLogger.Warningf(nil, "Not enough data for EXIF header: (%d)", len(data)) + exifLogger.Warningf(context.TODO(), "Not enough data for EXIF header: (%d)", len(data)) return eh, ErrNoExif } - if bytes.Equal(data[:4], ExifBigEndianSignature[:]) == true { + if bytes.Equal(data[:4], ExifBigEndianSignature[:]) { eh.ByteOrder = binary.BigEndian - } else if bytes.Equal(data[:4], ExifLittleEndianSignature[:]) == true { + } else if bytes.Equal(data[:4], ExifLittleEndianSignature[:]) { eh.ByteOrder = binary.LittleEndian } else { return eh, ErrNoExif diff --git a/v2/exif_test.go b/v2/exif_test.go index 59f5e16..b40f4fb 100644 --- a/v2/exif_test.go +++ b/v2/exif_test.go @@ -48,7 +48,7 @@ func TestVisit(t *testing.T) { if _, err := ParseExifHeader(data[i:]); err == nil { foundAt = i break - } else if log.Is(err, ErrNoExif) == false { + } else if !log.Is(err, ErrNoExif) { log.Panic(err) } } @@ -164,7 +164,7 @@ func TestVisit(t *testing.T) { "IFD-PATH=[IFD1] ID=(0x0202) NAME=[JPEGInterchangeFormatLength] COUNT=(1) TYPE=[LONG] VALUE=[21491]", } - if reflect.DeepEqual(tags, expected) == false { + if !reflect.DeepEqual(tags, expected) { fmt.Printf("\n") fmt.Printf("ACTUAL:\n") fmt.Printf("\n") @@ -197,7 +197,7 @@ func TestSearchFileAndExtractExif(t *testing.T) { testExifData := getTestExifData() - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } @@ -213,7 +213,7 @@ func TestSearchAndExtractExif(t *testing.T) { testExifData := getTestExifData() - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } @@ -231,7 +231,7 @@ func TestSearchAndExtractExifWithReader(t *testing.T) { testExifData := getTestExifData() - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } diff --git a/v2/go.mod b/v2/go.mod index 38b40fd..733ef54 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -7,7 +7,6 @@ go 1.13 require ( github.com/dsoprea/go-logging v0.0.0-20200517223158-a10564966e9d - github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf // indirect github.com/golang/geo v0.0.0-20200319012246-673a6f80352d github.com/jessevdk/go-flags v1.4.0 golang.org/x/net v0.0.0-20200513185701-a91f0712d120 // indirect diff --git a/v2/go.sum b/v2/go.sum index 6fd800f..84afb23 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -1,37 +1,19 @@ -github.com/dsoprea/go-exif/v2 v2.0.0-20200321225314-640175a69fe4/go.mod h1:Lm2lMM2zx8p4a34ZemkaUV95AnMl4ZvLbCUbwOvLC2E= -github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696 h1:VGFnZAcLwPpt1sHlAxml+pGLZz9A2s+K/s1YNhPC91Y= -github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696/go.mod h1:Nm/x2ZUNRW6Fe5C3LxdY1PyZY5wmDv/s5dkPJ/VB3iA= -github.com/dsoprea/go-logging v0.0.0-20200502191043-ec333ec7635f h1:XM9MVftaUNA4CcjV97+4bSy7u9Ns04DEYbZkswUrRtc= -github.com/dsoprea/go-logging v0.0.0-20200502191043-ec333ec7635f/go.mod h1:7I+3Pe2o/YSU88W0hWlm9S22W7XI1JFNJ86U0zPKMf8= -github.com/dsoprea/go-logging v0.0.0-20200502201358-170ff607885f h1:FonKAuW3PmNtqk9tOR+Z7bnyQHytmnZBCmm5z1PQMss= -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-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/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= -github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.0.2 h1:xMxH9j2fNg/L4hLn/4y3M0IUsn0M6Wbu/Uh9QlOfBh4= github.com/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= -github.com/golang/geo v0.0.0-20190916061304-5b978397cfec h1:lJwO/92dFXWeXOZdoGXgptLmNLwynMSHUmU6besqtiw= -github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/geo v0.0.0-20200319012246-673a6f80352d h1:C/hKUcHT483btRbeGkrRjJz+Zbcj8audldIi9tRJDCc= github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5 h1:WQ8q63x+f/zpC8Ac1s9wLElVoHhm32p6tudrU72n1QA= golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= -gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/v2/gps.go b/v2/gps.go index d44ede1..7671059 100644 --- a/v2/gps.go +++ b/v2/gps.go @@ -5,10 +5,9 @@ import ( "fmt" "time" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" "github.com/golang/geo/s2" - - "github.com/dsoprea/go-exif/v2/common" ) var ( @@ -109,7 +108,7 @@ func (gi *GpsInfo) S2CellId() s2.CellID { ll := s2.LatLngFromDegrees(latitude, longitude) cellId := s2.CellIDFromLatLng(ll) - if cellId.IsValid() == false { + if !cellId.IsValid() { panic(ErrGpsCoordinatesNotValid) } diff --git a/v2/ifd_builder.go b/v2/ifd_builder.go index 64a0929..e3208c5 100644 --- a/v2/ifd_builder.go +++ b/v2/ifd_builder.go @@ -12,14 +12,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" - - "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/undefined" -) - -var ( - ifdBuilderLogger = log.NewLogger("exif.ifd_builder") + exifcommon "github.com/dsoprea/go-exif/v2/common" + exifundefined "github.com/dsoprea/go-exif/v2/undefined" + log "github.com/dsoprea/go-logging" ) var ( @@ -33,7 +28,7 @@ type IfdBuilderTagValue struct { } func (ibtv IfdBuilderTagValue) String() string { - if ibtv.IsBytes() == true { + if ibtv.IsBytes() { var valuePhrase string if len(ibtv.valueBytes) <= 8 { valuePhrase = fmt.Sprintf("%v", ibtv.valueBytes) @@ -42,7 +37,7 @@ func (ibtv IfdBuilderTagValue) String() string { } return fmt.Sprintf("IfdBuilderTagValue", valuePhrase, len(ibtv.valueBytes)) - } else if ibtv.IsIb() == true { + } else if ibtv.IsIb() { return fmt.Sprintf("IfdBuilderTagValue", ibtv.ib) } else { log.Panicf("IBTV state undefined") @@ -69,9 +64,9 @@ func (ibtv IfdBuilderTagValue) IsBytes() bool { } func (ibtv IfdBuilderTagValue) Bytes() []byte { - if ibtv.IsBytes() == false { + if !ibtv.IsBytes() { log.Panicf("this tag is not a byte-slice value") - } else if ibtv.IsIb() == true { + } else if ibtv.IsIb() { log.Panicf("this tag is an IFD-builder value not a byte-slice") } @@ -83,9 +78,9 @@ func (ibtv IfdBuilderTagValue) IsIb() bool { } func (ibtv IfdBuilderTagValue) Ib() *IfdBuilder { - if ibtv.IsIb() == false { + if !ibtv.IsIb() { log.Panicf("this tag is not an IFD-builder value") - } else if ibtv.IsBytes() == true { + } else if ibtv.IsBytes() { log.Panicf("this tag is a byte-slice, not a IFD-builder") } @@ -135,7 +130,7 @@ func (bt *BuilderTag) Value() (value *IfdBuilderTagValue) { func (bt *BuilderTag) String() string { var valueString string - if bt.value.IsBytes() == true { + if bt.value.IsBytes() { var err error valueString, err = exifcommon.FormatFromBytes(bt.value.Bytes(), bt.typeId, false, bt.byteOrder) @@ -191,7 +186,7 @@ func NewStandardBuilderTag(ifdPath string, it *IndexedTag, byteOrder binary.Byte tagType := it.GetEncodingType(value) var rawBytes []byte - if it.DoesSupportType(exifcommon.TypeUndefined) == true { + if it.DoesSupportType(exifcommon.TypeUndefined) { encodeable := value.(exifundefined.EncodeableValue) var err error @@ -315,7 +310,7 @@ func (ib *IfdBuilder) ChildWithTagId(childIfdTagId uint16) (childIb *IfdBuilder, }() for _, bt := range ib.tags { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { continue } @@ -397,7 +392,7 @@ func getOrCreateIbFromRootIbInner(rootIb *IfdBuilder, parentIb *IfdBuilder, curr var foundChild *IfdBuilder for _, bt := range thisIb.tags { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { continue } @@ -498,7 +493,7 @@ func (ib *IfdBuilder) SetThumbnail(data []byte) (err error) { // TODO(dustin): !! Add a test for this function. - if data == nil || len(data) == 0 { + if len(data) == 0 { log.Panic("thumbnail is empty") } @@ -555,18 +550,18 @@ func (ib *IfdBuilder) printTagTree(levels int) { _, err := ib.ifdMapping.GetChild(currentIb.IfdIdentity().UnindexedString(), tag.tagId) if err == nil { isChildIb = true - } else if log.Is(err, exifcommon.ErrChildIfdNotMapped) == false { + } else if !log.Is(err, exifcommon.ErrChildIfdNotMapped) { log.Panic(err) } tagName := "" // If a normal tag (not a child IFD) get the name. - if isChildIb == true { + if isChildIb { tagName = "" } else { it, err := ib.tagIndex.Get(ib.ifdIdentity, tag.tagId) - if log.Is(err, ErrTagNotFound) == true { + if log.Is(err, ErrTagNotFound) { tagName = "" } else if err != nil { log.Panic(err) @@ -577,14 +572,14 @@ func (ib *IfdBuilder) printTagTree(levels int) { value := tag.Value() - if value.IsIb() == true { + if value.IsIb() { fmt.Printf("%s (%d): [%s] %s\n", indent, i, tagName, value.Ib()) } else { fmt.Printf("%s (%d): [%s] %s\n", indent, i, tagName, tag) } - if isChildIb == true { - if tag.value.IsIb() == false { + if isChildIb { + if !tag.value.IsIb() { log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag) } @@ -624,12 +619,12 @@ func (ib *IfdBuilder) printIfdTree(levels int) { _, err := ib.ifdMapping.GetChild(currentIb.IfdIdentity().UnindexedString(), tag.tagId) if err == nil { isChildIb = true - } else if log.Is(err, exifcommon.ErrChildIfdNotMapped) == false { + } else if !log.Is(err, exifcommon.ErrChildIfdNotMapped) { log.Panic(err) } - if isChildIb == true { - if tag.value.IsIb() == false { + if isChildIb { + if !tag.value.IsIb() { log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag) } @@ -662,7 +657,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin for i, tag := range thisIb.tags { var childIb *IfdBuilder childIfdName := "" - if tag.value.IsIb() == true { + if tag.value.IsIb() { childIb = tag.value.Ib() childIfdName = childIb.IfdIdentity().UnindexedString() } @@ -676,7 +671,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin childPrefix := "" if prefix == "" { - childPrefix = fmt.Sprintf("%s", thisIb.IfdIdentity().UnindexedString()) + childPrefix = thisIb.IfdIdentity().UnindexedString() } else { childPrefix = fmt.Sprintf("%s->%s", prefix, thisIb.IfdIdentity().UnindexedString()) } @@ -759,7 +754,7 @@ func (ib *IfdBuilder) DeleteAll(tagId uint16) (n int, err error) { for { err = ib.DeleteN(tagId, 1) - if log.Is(err, ErrTagEntryNotFound) == true { + if log.Is(err, ErrTagEntryNotFound) { break } else if err != nil { log.Panic(err) @@ -815,7 +810,7 @@ func (ib *IfdBuilder) Set(bt *BuilderTag) (err error) { position, err := ib.Find(bt.tagId) if err == nil { ib.tags[position] = bt - } else if log.Is(err, ErrTagEntryNotFound) == true { + } else if log.Is(err, ErrTagEntryNotFound) { err = ib.add(bt) log.PanicIf(err) } else { @@ -930,7 +925,7 @@ func (ib *IfdBuilder) Add(bt *BuilderTag) (err error) { } }() - if bt.value.IsIb() == true { + if bt.value.IsIb() { log.Panicf("child IfdBuilders must be added via AddChildIb() or AddTagsFromExisting(), not Add()") } @@ -1001,17 +996,17 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl if err == nil { err = ib.SetThumbnail(thumbnailData) log.PanicIf(err) - } else if log.Is(err, ErrNoThumbnail) == false { + } else if !log.Is(err, ErrNoThumbnail) { log.Panic(err) } for i, ite := range ifd.Entries { - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { + if ite.IsThumbnailOffset() || ite.IsThumbnailSize() { // These will be added on-the-fly when we encode. continue } - if excludeTagIds != nil && len(excludeTagIds) > 0 { + if len(excludeTagIds) > 0 { found := false for _, excludedTagId := range excludeTagIds { if excludedTagId == ite.TagId() { @@ -1019,12 +1014,12 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl } } - if found == true { + if found { continue } } - if includeTagIds != nil && len(includeTagIds) > 0 { + if len(includeTagIds) > 0 { // Whether or not there was a list of excludes, if there is a list // of includes than the current tag has to be in it. @@ -1036,7 +1031,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl } } - if found == false { + if !found { continue } } @@ -1155,7 +1150,7 @@ func (ib *IfdBuilder) SetStandard(tagId uint16, value interface{}) (err error) { i, err := ib.Find(tagId) if err != nil { - if log.Is(err, ErrTagEntryNotFound) == false { + if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } @@ -1186,7 +1181,7 @@ func (ib *IfdBuilder) SetStandardWithName(tagName string, value interface{}) (er i, err := ib.Find(bt.tagId) if err != nil { - if log.Is(err, ErrTagEntryNotFound) == false { + if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } diff --git a/v2/ifd_builder_encode.go b/v2/ifd_builder_encode.go index a0bac3e..78f8a4a 100644 --- a/v2/ifd_builder_encode.go +++ b/v2/ifd_builder_encode.go @@ -7,9 +7,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) const ( @@ -219,7 +219,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * // Write unit-count. - if bt.value.IsBytes() == true { + if bt.value.IsBytes() { effectiveType := bt.typeId if bt.typeId == exifcommon.TypeUndefined { effectiveType = exifcommon.TypeByte @@ -235,7 +235,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * len_ := len(valueBytes) unitCount := uint32(len_) / typeSize - if _, found := tagsWithoutAlignment[bt.tagId]; found == false { + if _, found := tagsWithoutAlignment[bt.tagId]; !found { remainder := uint32(len_) % typeSize if remainder > 0 { @@ -262,7 +262,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * log.PanicIf(err) } } else { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { log.Panicf("tag value is not a byte-slice but also not a child IB: %v", bt) } @@ -364,7 +364,7 @@ func (ibe *IfdByteEncoder) encodeIfdToBytes(ib *IfdBuilder, ifdAddressableOffset // N the link from this IFD to the next IFD that will be written in the // next cycle. - if setNextIb == true { + if setNextIb { // Write address of next IFD in chain. This will be the original // allocation offset plus the size of everything we have allocated for // this IFD and its child-IFDs. diff --git a/v2/ifd_builder_encode_test.go b/v2/ifd_builder_encode_test.go index 0e30bdf..e0a9410 100644 --- a/v2/ifd_builder_encode_test.go +++ b/v2/ifd_builder_encode_test.go @@ -6,9 +6,9 @@ import ( "strings" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { @@ -18,7 +18,7 @@ func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { err := bw.writeAsBytes(uint8(0x12)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12}) { t.Fatalf("uint8 not encoded correctly.") } } @@ -30,7 +30,7 @@ func Test_ByteWriter_writeAsBytes_uint16(t *testing.T) { err := bw.writeAsBytes(uint16(0x1234)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34}) { t.Fatalf("uint16 not encoded correctly.") } } @@ -42,7 +42,7 @@ func Test_ByteWriter_writeAsBytes_uint32(t *testing.T) { err := bw.writeAsBytes(uint32(0x12345678)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) { t.Fatalf("uint32 not encoded correctly.") } } @@ -54,7 +54,7 @@ func Test_ByteWriter_WriteUint16(t *testing.T) { err := bw.WriteUint16(uint16(0x1234)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34}) { t.Fatalf("uint16 not encoded correctly (as bytes).") } } @@ -66,7 +66,7 @@ func Test_ByteWriter_WriteUint32(t *testing.T) { err := bw.WriteUint32(uint32(0x12345678)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) { t.Fatalf("uint32 not encoded correctly (as bytes).") } } @@ -78,7 +78,7 @@ func Test_ByteWriter_WriteFourBytes(t *testing.T) { err := bw.WriteFourBytes([]byte{0x11, 0x22, 0x33, 0x44}) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x11, 0x22, 0x33, 0x44}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x11, 0x22, 0x33, 0x44}) { t.Fatalf("four-bytes not encoded correctly.") } } @@ -114,7 +114,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset1(t *testing.T) { t.Fatalf("offset not bumped correctly (2): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3}) { t.Fatalf("buffer not correct after write (1)") } @@ -127,7 +127,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset1(t *testing.T) { t.Fatalf("offset not bumped correctly (3): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) { t.Fatalf("buffer not correct after write (2)") } } @@ -151,7 +151,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset2(t *testing.T) { t.Fatalf("offset not bumped correctly (2): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3}) { t.Fatalf("buffer not correct after write (1)") } @@ -164,7 +164,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset2(t *testing.T) { t.Fatalf("offset not bumped correctly (3): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) { t.Fatalf("buffer not correct after write (2)") } } @@ -214,7 +214,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_embedded1(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00}) { t.Fatalf("encoded tag-entry bytes not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation was done but not expected") @@ -248,7 +248,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_embedded2(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78}) { t.Fatalf("encoded tag-entry bytes not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation was done but not expected") @@ -282,11 +282,11 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (1)") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34}) { t.Fatalf("encoded tag-entry bytes not correct (1)") } else if ida.NextOffset() != addressableOffset+uint32(5) { t.Fatalf("allocation offset not expected (1)") - } else if bytes.Compare(ida.Bytes(), []byte{0x12, 0x34, 0x56, 0x78, 0x9A}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x12, 0x34, 0x56, 0x78, 0x9A}) { t.Fatalf("allocated data not correct (1)") } @@ -299,17 +299,17 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (2)") - } else if bytes.Compare(b.Bytes(), []byte{ + } else if !bytes.Equal(b.Bytes(), []byte{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34, // Tag 1 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x39, // Tag 2 - }) != 0 { + }) { t.Fatalf("encoded tag-entry bytes not correct (2)") } else if ida.NextOffset() != addressableOffset+uint32(10) { t.Fatalf("allocation offset not expected (2)") - } else if bytes.Compare(ida.Bytes(), []byte{ + } else if !bytes.Equal(ida.Bytes(), []byte{ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xbc, 0xde, 0xf0, 0x12, 0x34, - }) != 0 { + }) { t.Fatalf("allocated data not correct (2)") } } @@ -341,7 +341,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_childIfd__withoutAllocate(t *testing.T if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x87, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x87, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) { t.Fatalf("encoded tag-entry with child-IFD not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation offset not expected") @@ -548,7 +548,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_simpleTag_allocate(t *testing.T) { allocatedBytes := ida.Bytes() - if bytes.Compare(allocatedBytes, expectedBytes) != 0 { + if !bytes.Equal(allocatedBytes, expectedBytes) { t.Fatalf("Allocated bytes not correct: %v != %v", allocatedBytes, expectedBytes) } } @@ -608,7 +608,7 @@ func Test_IfdByteEncoder_encodeIfdToBytes_simple(t *testing.T) { 0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, } - if bytes.Compare(tableAndAllocated, expectedIfdAndDataBytes) != 0 { + if !bytes.Equal(tableAndAllocated, expectedIfdAndDataBytes) { t.Fatalf("IFD table and allocated data not correct: %v", exifcommon.DumpBytesClauseToString(tableAndAllocated)) } } diff --git a/v2/ifd_builder_test.go b/v2/ifd_builder_test.go index f7fe52c..fc12e6e 100644 --- a/v2/ifd_builder_test.go +++ b/v2/ifd_builder_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/undefined" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" + exifundefined "github.com/dsoprea/go-exif/v2/undefined" + log "github.com/dsoprea/go-logging" ) func TestIfdBuilder_Add(t *testing.T) { @@ -83,25 +83,25 @@ func TestIfdBuilder_Add(t *testing.T) { if tags[0].tagId != 0x11 { t.Fatalf("tag (0) tag-ID not correct") - } else if bytes.Compare(tags[0].value.Bytes(), []byte("test string")) != 0 { + } else if !bytes.Equal(tags[0].value.Bytes(), []byte("test string")) { t.Fatalf("tag (0) value not correct") } if tags[1].tagId != 0x22 { t.Fatalf("tag (1) tag-ID not correct") - } else if bytes.Compare(tags[1].value.Bytes(), []byte("test string2")) != 0 { + } else if !bytes.Equal(tags[1].value.Bytes(), []byte("test string2")) { t.Fatalf("tag (1) value not correct") } if tags[2].tagId != 0x33 { t.Fatalf("tag (2) tag-ID not correct") - } else if bytes.Compare(tags[2].value.Bytes(), []byte("test string3")) != 0 { + } else if !bytes.Equal(tags[2].value.Bytes(), []byte("test string3")) { t.Fatalf("tag (2) value not correct") } if tags[3].tagId != 0x44 { t.Fatalf("tag (3) tag-ID not correct") - } else if bytes.Compare(tags[3].value.Bytes(), originalBytes) != 0 { + } else if !bytes.Equal(tags[3].value.Bytes(), originalBytes) { t.Fatalf("tag (3) value not correct") } } @@ -473,12 +473,12 @@ func TestIfdBuilder_FindN__First_2_2Returned(t *testing.T) { tags := ib.Tags() bt = tags[found[0]] - if bt.tagId != 0x11 || bytes.Compare(bt.value.Bytes(), []byte("test string")) != 0 { + if bt.tagId != 0x11 || !bytes.Equal(bt.value.Bytes(), []byte("test string")) { log.Panicf("Found entry 0 is not correct: (0x%04x) [%s]", bt.tagId, bt.value) } bt = tags[found[1]] - if bt.tagId != 0x11 || bytes.Compare(bt.value.Bytes(), []byte("test string4")) != 0 { + if bt.tagId != 0x11 || !bytes.Equal(bt.value.Bytes(), []byte("test string4")) { log.Panicf("Found entry 1 is not correct: (0x%04x) [%s]", bt.tagId, bt.value) } } @@ -768,7 +768,7 @@ func TestIfdBuilder_Find__Miss(t *testing.T) { _, err = ib.Find(0x99) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -817,7 +817,7 @@ func TestIfdBuilder_Replace(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-replace tags are not correct.") } @@ -836,7 +836,7 @@ func TestIfdBuilder_Replace(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) { t.Fatalf("Post-replace tags are not correct.") } } @@ -885,7 +885,7 @@ func TestIfdBuilder_ReplaceN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-replace tags are not correct.") } @@ -904,7 +904,7 @@ func TestIfdBuilder_ReplaceN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) { t.Fatalf("Post-replace tags are not correct.") } } @@ -967,7 +967,7 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -983,7 +983,7 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Post-delete (1) tags not correct.") } @@ -999,14 +999,14 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete (2) tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1069,7 +1069,7 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1085,7 +1085,7 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Post-delete (1) tags not correct.") } @@ -1101,14 +1101,14 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete (2) tags not correct.") } err = ib.DeleteN(0x22, 1) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1171,7 +1171,7 @@ func TestIfdBuilder_DeleteN_Two(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1187,14 +1187,14 @@ func TestIfdBuilder_DeleteN_Two(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1257,7 +1257,7 @@ func TestIfdBuilder_DeleteAll(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1275,14 +1275,14 @@ func TestIfdBuilder_DeleteAll(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1381,7 +1381,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain(t *testing.T) { "TAG", } - if reflect.DeepEqual(actual, expected) == false { + if !reflect.DeepEqual(actual, expected) { fmt.Printf("ACTUAL:\n%s\n\nEXPECTED:\n%s\n", strings.Join(actual, "\n"), strings.Join(expected, "\n")) t.Fatalf("IB did not [correctly] duplicate the IFD structure.") } @@ -1660,7 +1660,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { // Check the thumbnail. - if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 { + if !bytes.Equal(recoveredThumbnailData, originalThumbnailData) { t.Fatalf("recovered thumbnail does not match original") } @@ -1710,7 +1710,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { for _, ite := range originalTags { // Adds a lot of noise if/when debugging, and we're already checking the // thumbnail bytes separately. - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() == true { + if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { continue } @@ -1734,7 +1734,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { for _, ite := range recoveredTags { // Adds a lot of noise if/when debugging, and we're already checking the // thumbnail bytes separately. - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() == true { + if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { continue } @@ -1834,7 +1834,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { // // Check the thumbnail. -// if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 { +// if !bytes.Equal(recoveredThumbnailData, originalThumbnailData) { // t.Fatalf("recovered thumbnail does not match original") // } @@ -1907,10 +1907,10 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { // expectedValueBytes = append(expectedValueBytes, []byte{'A', 'S', 'C', 'I', 'I', 0, 0, 0}...) // expectedValueBytes = append(expectedValueBytes, []byte("TEST COMMENT")...) -// if bytes.Compare(recoveredValueBytes, expectedValueBytes) != 0 { +// if !bytes.Equal(recoveredValueBytes, expectedValueBytes) { // t.Fatalf("Recovered UserComment does not have the right value: %v != %v", recoveredValueBytes, expectedValueBytes) // } -// } else if bytes.Compare(recoveredValueBytes, originalValueBytes) != 0 { +// } else if !bytes.Equal(recoveredValueBytes, originalValueBytes) { // t.Fatalf("bytes of tag content not correct: %v != %v ITE=%s", recoveredValueBytes, originalValueBytes, recoveredIte) // } // } @@ -2127,7 +2127,7 @@ func TestNewStandardBuilderTag__OneUnit(t *testing.T) { t.Fatalf("II in BuilderTag not correct") } else if bt.tagId != 0x8833 { t.Fatalf("tag-ID not correct") - } else if bytes.Compare(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) { t.Fatalf("value not correct") } } @@ -2144,9 +2144,9 @@ func TestNewStandardBuilderTag__TwoUnits(t *testing.T) { t.Fatalf("II in BuilderTag not correct") } else if bt.tagId != 0x8833 { t.Fatalf("tag-ID not correct") - } else if bytes.Compare(bt.value.Bytes(), []byte{ + } else if !bytes.Equal(bt.value.Bytes(), []byte{ 0x0, 0x0, 0x12, 0x34, - 0x0, 0x0, 0x56, 0x78}) != 0 { + 0x0, 0x0, 0x56, 0x78}) { t.Fatalf("value not correct") } } diff --git a/v2/ifd_enumerate.go b/v2/ifd_enumerate.go index 33a5f84..72934c6 100644 --- a/v2/ifd_enumerate.go +++ b/v2/ifd_enumerate.go @@ -2,6 +2,7 @@ package exif import ( "bytes" + "context" "errors" "fmt" "io" @@ -11,10 +12,10 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/undefined" + exifcommon "github.com/dsoprea/go-exif/v2/common" + exifundefined "github.com/dsoprea/go-exif/v2/undefined" ) var ( @@ -77,7 +78,6 @@ var ( type byteParser struct { byteOrder binary.ByteOrder addressableData []byte - ifdOffset uint32 currentOffset uint32 } @@ -220,7 +220,7 @@ func (ie *IfdEnumerate) parseTag(ii *exifcommon.IfdIdentity, tagPosition int, bp valueOffset, rawValueOffset, err := bp.getUint32() log.PanicIf(err) - if tagType.IsValid() == false { + if !tagType.IsValid() { ite = &IfdTagEntry{ tagId: tagId, tagType: tagType, @@ -255,7 +255,7 @@ func (ie *IfdEnumerate) parseTag(ii *exifcommon.IfdIdentity, tagPosition int, bp // We also need to set `tag.ChildFqIfdPath` but can't do it here // because we don't have the IFD index. - } else if log.Is(err, exifcommon.ErrChildIfdNotMapped) == false { + } else if !log.Is(err, exifcommon.ErrChildIfdNotMapped) { log.Panic(err) } @@ -300,7 +300,7 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat med.unknownTags[originalBt] = exifcommon.BasicTag{} } - utilityLogger.Debugf(nil, + utilityLogger.Debugf(context.TODO(), "Tag (0x%04x) is not valid for IFD [%s]. Attempting secondary "+ "lookup.", tagId, ii.String()) @@ -319,7 +319,7 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat // they want to specifically manage these types of tags, they // can use more advanced functionality to specifically -handle // unknown tags. - utilityLogger.Warningf(nil, + utilityLogger.Warningf(context.TODO(), "Tag with ID (0x%04x) in IFD [%s] is not recognized and "+ "will be ignored.", tagId, ii.String()) @@ -328,7 +328,7 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat ite.setTagName(it.Name) - utilityLogger.Warningf(nil, + utilityLogger.Warningf(context.TODO(), "Tag with ID (0x%04x) is not valid for IFD [%s], but it *is* "+ "valid as tag [%s] under IFD [%s] and has the same type "+ "[%s], so we will use that. This EXIF blob was probably "+ @@ -355,8 +355,8 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat // tag should ever be repeated, and b) all but one had an incorrect // type and caused parsing/conversion woes. So, this is a quick fix // for those scenarios. - if it.DoesSupportType(tagType) == false { - ifdEnumerateLogger.Warningf(nil, + if !it.DoesSupportType(tagType) { + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping tag [%s] (0x%04x) [%s] with an unexpected type: %v ∉ %v", ii.UnindexedString(), tagId, it.Name, tagType, it.SupportedTypes) @@ -379,7 +379,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis tagCount, _, err := bp.getUint16() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "IFD [%s] tag-count: (%d)", ii.String(), tagCount) + ifdEnumerateLogger.Debugf(context.TODO(), "IFD [%s] tag-count: (%d)", ii.String(), tagCount) entries = make([]*IfdTagEntry, 0) @@ -389,11 +389,11 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis for i := 0; i < int(tagCount); i++ { ite, err := ie.parseTag(ii, i, bp) if err != nil { - if log.Is(err, ErrTagTypeNotValid) == true { + if log.Is(err, ErrTagTypeNotValid) { // Technically, we have the type on-file in the tags-index, but // if the type stored alongside the data disagrees with it, // which it apparently does, all bets are off. - ifdEnumerateLogger.Warningf(nil, "Tag (0x%04x) in IFD [%s] at position (%d) has invalid type (%d) and will be skipped.", ite.tagId, ii, i, ite.tagType) + ifdEnumerateLogger.Warningf(context.TODO(), "Tag (0x%04x) in IFD [%s] at position (%d) has invalid type (%d) and will be skipped.", ite.tagId, ii, i, ite.tagType) continue } @@ -416,15 +416,15 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis log.PanicIf(err) } - if ite.IsThumbnailOffset() == true { - ifdEnumerateLogger.Debugf(nil, "Skipping the thumbnail offset tag (0x%04x). Use accessors to get it or set it.", tagId) + if ite.IsThumbnailOffset() { + ifdEnumerateLogger.Debugf(context.TODO(), "Skipping the thumbnail offset tag (0x%04x). Use accessors to get it or set it.", tagId) enumeratorThumbnailOffset = ite entries = append(entries, ite) continue - } else if ite.IsThumbnailSize() == true { - ifdEnumerateLogger.Debugf(nil, "Skipping the thumbnail size tag (0x%04x). Use accessors to get it or set it.", tagId) + } else if ite.IsThumbnailSize() { + ifdEnumerateLogger.Debugf(context.TODO(), "Skipping the thumbnail size tag (0x%04x). Use accessors to get it or set it.", tagId) enumeratorThumbnailSize = ite entries = append(entries, ite) @@ -453,8 +453,8 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis // (the standard IFD tag type), later, unless we skip it because it's // [likely] not even in the standard list of known tags. if ite.ChildIfdPath() != "" { - if doDescend == true { - ifdEnumerateLogger.Debugf(nil, "Descending from IFD [%s] to IFD [%s].", ii, ite.ChildIfdPath()) + if doDescend { + ifdEnumerateLogger.Debugf(context.TODO(), "Descending from IFD [%s] to IFD [%s].", ii, ite.ChildIfdPath()) currentIfdTag := ii.IfdTag() @@ -469,7 +469,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis err := ie.scan(iiChild, ite.getValueOffset(), visitor, med) log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Ascending from IFD [%s] to IFD [%s].", ite.ChildIfdPath(), ii) + ifdEnumerateLogger.Debugf(context.TODO(), "Ascending from IFD [%s] to IFD [%s].", ite.ChildIfdPath(), ii) } } @@ -486,7 +486,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis // This this case, the value is always a length. length := enumeratorThumbnailSize.getValueOffset() - ifdEnumerateLogger.Debugf(nil, "Found thumbnail in IFD [%s]. Its offset is (%d) and is (%d) bytes.", ii, offset, length) + ifdEnumerateLogger.Debugf(context.TODO(), "Found thumbnail in IFD [%s]. Its offset is (%d) and is (%d) bytes.", ii, offset, length) furthestOffset := offset + length @@ -498,7 +498,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis nextIfdOffset, _, err = bp.getUint32() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Next IFD at offset: (%08x)", nextIfdOffset) + ifdEnumerateLogger.Debugf(context.TODO(), "Next IFD at offset: (%08x)", nextIfdOffset) return nextIfdOffset, entries, thumbnailData, nil } @@ -544,12 +544,12 @@ func (ie *IfdEnumerate) scan(iiGeneral *exifcommon.IfdIdentity, ifdOffset uint32 for ifdIndex := 0; ; ifdIndex++ { iiSibling := iiGeneral.NewSibling(ifdIndex) - ifdEnumerateLogger.Debugf(nil, "Parsing IFD [%s] at offset (0x%04x) (scan).", iiSibling.String(), ifdOffset) + ifdEnumerateLogger.Debugf(context.TODO(), "Parsing IFD [%s] at offset (0x%04x) (scan).", iiSibling.String(), ifdOffset) bp, err := ie.getByteParser(ifdOffset) if err != nil { if err == ErrOffsetInvalid { - ifdEnumerateLogger.Errorf(nil, nil, "IFD [%s] at offset (0x%04x) is unreachable. Terminating scan.", iiSibling.String(), ifdOffset) + ifdEnumerateLogger.Errorf(context.TODO(), nil, "IFD [%s] at offset (0x%04x) is unreachable. Terminating scan.", iiSibling.String(), ifdOffset) break } @@ -605,7 +605,7 @@ func (ie *IfdEnumerate) Scan(iiRoot *exifcommon.IfdIdentity, ifdOffset uint32, v err = ie.scan(iiRoot, ifdOffset, visitor, med) log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Scan: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d) (Scan).", ie.FurthestOffset()) + ifdEnumerateLogger.Debugf(context.TODO(), "Scan: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d) (Scan).", ie.FurthestOffset()) return med, nil } @@ -683,7 +683,7 @@ func (ifd *Ifd) FindTagWithId(tagId uint16) (results []*IfdTagEntry, err error) }() results, found := ifd.EntriesByTagId[tagId] - if found != true { + if !found { log.Panic(ErrTagNotFound) } @@ -700,7 +700,7 @@ func (ifd *Ifd) FindTagWithName(tagName string) (results []*IfdTagEntry, err err }() it, err := ifd.tagIndex.GetWithName(ifd.ifdIdentity, tagName) - if log.Is(err, ErrTagNotFound) == true { + if log.Is(err, ErrTagNotFound) { log.Panic(ErrTagNotKnown) } else if err != nil { log.Panic(err) @@ -759,7 +759,7 @@ func (ifd *Ifd) dumpTags(tags []*IfdTagEntry) []*IfdTagEntry { ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -803,7 +803,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo } else { // This will just add noise to the output (byte-tags are fully // dumped). - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() == true { + if ite.IsThumbnailOffset() || ite.IsThumbnailSize() { continue } @@ -815,16 +815,16 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo } var valuePhrase string - if populateValues == true { + if populateValues { var err error valuePhrase, err = ite.Format() if err != nil { - if log.Is(err, exifcommon.ErrUnhandledUndefinedTypedTag) == true { - ifdEnumerateLogger.Warningf(nil, "Skipping non-standard undefined tag: [%s] (%04x)", ifd.ifdIdentity.UnindexedString(), ite.TagId()) + if log.Is(err, exifcommon.ErrUnhandledUndefinedTypedTag) { + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping non-standard undefined tag: [%s] (%04x)", ifd.ifdIdentity.UnindexedString(), ite.TagId()) continue } else if err == exifundefined.ErrUnparseableValue { - ifdEnumerateLogger.Warningf(nil, "Skipping unparseable undefined tag: [%s] (%04x) [%s]", ifd.ifdIdentity.UnindexedString(), ite.TagId(), it.Name) + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping unparseable undefined tag: [%s] (%04x) [%s]", ifd.ifdIdentity.UnindexedString(), ite.TagId(), it.Name) continue } @@ -842,7 +842,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -884,7 +884,7 @@ func (ifd *Ifd) printIfdTree(level int, nextLink bool) { ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -932,7 +932,7 @@ func (ifd *Ifd) dumpTree(tagsDump []string, level int) []string { ifdsFoundCount++ childIfd, found := ifd.ChildIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -977,31 +977,31 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { log.Panicf("GPS can only be read on GPS IFD: [%s] != [%s]", ifd.ifdIdentity.UnindexedString(), exifcommon.IfdGpsInfoStandardIfdIdentity.UnindexedString()) } - if tags, found := ifd.EntriesByTagId[TagGpsVersionId]; found == false { + if tags, found := ifd.EntriesByTagId[TagGpsVersionId]; !found { // We've seen this. We'll just have to default to assuming we're in a // 2.2.0.0 format. - ifdEnumerateLogger.Warningf(nil, "No GPS version tag (0x%04x) found.", TagGpsVersionId) + ifdEnumerateLogger.Warningf(context.TODO(), "No GPS version tag (0x%04x) found.", TagGpsVersionId) } else { versionBytes, err := tags[0].GetRawBytes() log.PanicIf(err) hit := false for _, acceptedGpsVersion := range ValidGpsVersions { - if bytes.Compare(versionBytes, acceptedGpsVersion[:]) == 0 { + if bytes.Equal(versionBytes, acceptedGpsVersion[:]) { hit = true break } } - if hit != true { - ifdEnumerateLogger.Warningf(nil, "GPS version not supported: %v", versionBytes) + if !hit { + ifdEnumerateLogger.Warningf(context.TODO(), "GPS version not supported: %v", versionBytes) log.Panic(ErrNoGpsTags) } } tags, found := ifd.EntriesByTagId[TagLatitudeId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "latitude not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "latitude not found") log.Panic(ErrNoGpsTags) } @@ -1010,8 +1010,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { // Look for whether North or South. tags, found = ifd.EntriesByTagId[TagLatitudeRefId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "latitude-ref not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "latitude-ref not found") log.Panic(ErrNoGpsTags) } @@ -1019,8 +1019,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { log.PanicIf(err) tags, found = ifd.EntriesByTagId[TagLongitudeId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "longitude not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "longitude not found") log.Panic(ErrNoGpsTags) } @@ -1029,8 +1029,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { // Look for whether West or East. tags, found = ifd.EntriesByTagId[TagLongitudeRefId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "longitude-ref not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "longitude-ref not found") log.Panic(ErrNoGpsTags) } @@ -1054,11 +1054,11 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { altitudeTags, foundAltitude := ifd.EntriesByTagId[TagAltitudeId] altitudeRefTags, foundAltitudeRef := ifd.EntriesByTagId[TagAltitudeRefId] - if foundAltitude == true && foundAltitudeRef == true { + if foundAltitude && foundAltitudeRef { altitudePhrase, err := altitudeTags[0].Format() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Altitude is [%s].", altitudePhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Altitude is [%s].", altitudePhrase) altitudeValue, err := altitudeTags[0].Value() log.PanicIf(err) @@ -1066,7 +1066,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { altitudeRefPhrase, err := altitudeRefTags[0].Format() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Altitude-reference is [%s].", altitudeRefPhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Altitude-reference is [%s].", altitudeRefPhrase) altitudeRefValue, err := altitudeRefTags[0].Value() log.PanicIf(err) @@ -1088,12 +1088,12 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { timestampTags, foundTimestamp := ifd.EntriesByTagId[TagTimestampId] datestampTags, foundDatestamp := ifd.EntriesByTagId[TagDatestampId] - if foundTimestamp == true && foundDatestamp == true { + if foundTimestamp && foundDatestamp { datestampValue, err := datestampTags[0].Value() log.PanicIf(err) datePhrase := datestampValue.(string) - ifdEnumerateLogger.Debugf(nil, "Date tag value is [%s].", datePhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Date tag value is [%s].", datePhrase) // Normalize the separators. datePhrase = strings.ReplaceAll(datePhrase, "-", ":") @@ -1111,7 +1111,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { timePhrase, err := timestampTags[0].Format() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Time tag value is [%s].", timePhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Time tag value is [%s].", timePhrase) timestampRaw := timestampValue.([]exifcommon.Rational) @@ -1216,7 +1216,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error queue = queue[1:] - ifdEnumerateLogger.Debugf(nil, "Parsing IFD [%s] (%d) at offset (0x%04x) (Collect).", ii.String(), ii.Index(), offset) + ifdEnumerateLogger.Debugf(context.TODO(), "Parsing IFD [%s] (%d) at offset (0x%04x) (Collect).", ii.String(), ii.Index(), offset) bp, err := ie.getByteParser(offset) if err != nil { @@ -1244,7 +1244,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error tagId := ite.TagId() tags, found := entriesByTagId[tagId] - if found == false { + if !found { tags = make([]*IfdTagEntry, 0) } @@ -1285,7 +1285,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error lookup[ii.String()] = ifd // Add a link from the previous IFD in the chain to us. - if previousIfd, found := edges[offset]; found == true { + if previousIfd, found := edges[offset]; found { previousIfd.NextIfd = ifd } @@ -1349,7 +1349,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error err = ie.setChildrenIndex(index.RootIfd) log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Collect: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d).", ie.FurthestOffset()) + ifdEnumerateLogger.Debugf(context.TODO(), "Collect: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d).", ie.FurthestOffset()) return index, nil } diff --git a/v2/ifd_enumerate_test.go b/v2/ifd_enumerate_test.go index 5c638d7..a02e7ca 100644 --- a/v2/ifd_enumerate_test.go +++ b/v2/ifd_enumerate_test.go @@ -57,7 +57,7 @@ func TestIfdTagEntry_RawBytes_RealData(t *testing.T) { if len(decodedBytes) != int(ite.UnitCount()) { t.Fatalf("Decoded bytes not the right count.") - } else if bytes.Compare(decodedBytes, expected) != 0 { + } else if !bytes.Equal(decodedBytes, expected) { t.Fatalf("Decoded bytes not correct.") } } @@ -109,7 +109,7 @@ func TestIfd_FindTagWithId_Miss(t *testing.T) { _, err = ifd.FindTagWithId(0xffff) if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotFound) == false { + } else if !log.Is(err, ErrTagNotFound) { log.Panic(err) } } @@ -163,7 +163,7 @@ func TestIfd_FindTagWithName_Miss(t *testing.T) { _, err = ifd.FindTagWithName("PlanarConfiguration") if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotFound) == false { + } else if !log.Is(err, ErrTagNotFound) { log.Panic(err) } } @@ -189,7 +189,7 @@ func TestIfd_FindTagWithName_NonStandard(t *testing.T) { _, err = ifd.FindTagWithName("GeorgeNotAtHome") if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotKnown) == false { + } else if !log.Is(err, ErrTagNotKnown) { log.Panic(err) } } @@ -226,7 +226,7 @@ func TestIfd_Thumbnail(t *testing.T) { expected, err := ioutil.ReadFile(expectedFilepath) log.PanicIf(err) - if bytes.Compare(actual, expected) != 0 { + if !bytes.Equal(actual, expected) { t.Fatalf("thumbnail not correct") } } diff --git a/v2/ifd_tag_entry.go b/v2/ifd_tag_entry.go index 789a998..3c5ddee 100644 --- a/v2/ifd_tag_entry.go +++ b/v2/ifd_tag_entry.go @@ -5,14 +5,10 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/undefined" -) - -var ( - iteLogger = log.NewLogger("exif.ifd_tag_entry") + exifcommon "github.com/dsoprea/go-exif/v2/common" + exifundefined "github.com/dsoprea/go-exif/v2/undefined" ) // IfdTagEntry refers to a tag in the loaded EXIF block. diff --git a/v2/ifd_tag_entry_test.go b/v2/ifd_tag_entry_test.go index d4890e4..f425c39 100644 --- a/v2/ifd_tag_entry_test.go +++ b/v2/ifd_tag_entry_test.go @@ -28,7 +28,7 @@ func TestIfdTagEntry_RawBytes_Allocated(t *testing.T) { value, err := ite.GetRawBytes() log.PanicIf(err) - if bytes.Compare(value, data) != 0 { + if !bytes.Equal(value, data) { t.Fatalf("Value not expected: [%s] != [%s]", value, data) } } @@ -59,7 +59,7 @@ func TestIfdTagEntry_RawBytes_Embedded(t *testing.T) { value, err := ite.GetRawBytes() log.PanicIf(err) - if bytes.Compare(value, data) != 0 { + if !bytes.Equal(value, data) { t.Fatalf("Value not expected: %v != %v", value, data) } } diff --git a/v2/tags.go b/v2/tags.go index f53d9ce..df01d38 100644 --- a/v2/tags.go +++ b/v2/tags.go @@ -1,12 +1,13 @@ package exif import ( + "context" "fmt" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" "gopkg.in/yaml.v2" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) const ( @@ -114,7 +115,7 @@ func (it *IndexedTag) Is(ifdPath string, id uint16) bool { // GetEncodingType returns the largest type that this tag's value can occupy. func (it *IndexedTag) GetEncodingType(value interface{}) exifcommon.TagTypePrimitive { // For convenience, we handle encoding a `time.Time` directly. - if IsTime(value) == true { + if IsTime(value) { // Timestamps are encoded as ASCII. value = "" } @@ -143,14 +144,14 @@ func (it *IndexedTag) GetEncodingType(value interface{}) exifcommon.TagTypePrimi // We specifically check for the cases that we know to expect. - if supportsLong == true && supportsShort == true { + if supportsLong && supportsShort { return exifcommon.TypeLong - } else if supportsRational == true && supportsSignedRational == true { + } else if supportsRational && supportsSignedRational { if value == nil { log.Panicf("GetEncodingType: require value to be given") } - if _, ok := value.(exifcommon.SignedRational); ok == true { + if _, ok := value.(exifcommon.SignedRational); ok { return exifcommon.TypeSignedRational } @@ -200,12 +201,12 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) { // Store by ID. family, found := ti.tagsByIfd[it.IfdPath] - if found == false { + if !found { family = make(map[uint16]*IndexedTag) ti.tagsByIfd[it.IfdPath] = family } - if _, found := family[it.Id]; found == true { + if _, found := family[it.Id]; found { log.Panicf("tag-ID defined more than once for IFD [%s]: (%02x)", it.IfdPath, it.Id) } @@ -214,12 +215,12 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) { // Store by name. familyR, found := ti.tagsByIfdR[it.IfdPath] - if found == false { + if !found { familyR = make(map[string]*IndexedTag) ti.tagsByIfdR[it.IfdPath] = familyR } - if _, found := familyR[it.Name]; found == true { + if _, found := familyR[it.Name]; found { log.Panicf("tag-name defined more than once for IFD [%s]: (%s)", it.IfdPath, it.Name) } @@ -245,12 +246,12 @@ func (ti *TagIndex) Get(ii *exifcommon.IfdIdentity, id uint16) (it *IndexedTag, ifdPath := ii.UnindexedString() family, found := ti.tagsByIfd[ifdPath] - if found == false { + if !found { return nil, ErrTagNotFound } it, found = family[id] - if found == false { + if !found { return nil, ErrTagNotFound } @@ -328,7 +329,7 @@ func (ti *TagIndex) GetWithName(ii *exifcommon.IfdIdentity, name string) (it *In ifdPath := ii.UnindexedString() it, found := ti.tagsByIfdR[ifdPath][name] - if found != true { + if !found { log.Panic(ErrTagNotFound) } @@ -378,8 +379,8 @@ func LoadStandardTags(ti *TagIndex) (err error) { // TODO(dustin): Discard unsupported types. This helps us with non-standard types that have actually been found in real data, that we ignore for right now. e.g. SSHORT, FLOAT, DOUBLE tagTypeId, found := exifcommon.GetTypeByName(tagTypeName) - if found == false { - tagsLogger.Warningf(nil, "Type [%s] for tag [%s] being loaded is not valid and is being ignored.", tagTypeName, tagName) + if !found { + tagsLogger.Warningf(context.TODO(), "Type [%s] for tag [%s] being loaded is not valid and is being ignored.", tagTypeName, tagName) continue } @@ -387,7 +388,7 @@ func LoadStandardTags(ti *TagIndex) (err error) { } if len(tagTypes) == 0 { - tagsLogger.Warningf(nil, "Tag [%s] (0x%04x) [%s] being loaded does not have any supported types and will not be registered.", ifdPath, tagId, tagName) + tagsLogger.Warningf(context.TODO(), "Tag [%s] (0x%04x) [%s] being loaded does not have any supported types and will not be registered.", ifdPath, tagId, tagName) continue } @@ -405,7 +406,7 @@ func LoadStandardTags(ti *TagIndex) (err error) { } } - tagsLogger.Debugf(nil, "(%d) tags loaded.", count) + tagsLogger.Debugf(context.TODO(), "(%d) tags loaded.", count) return nil } diff --git a/v2/tags_test.go b/v2/tags_test.go index bab602c..cca8121 100644 --- a/v2/tags_test.go +++ b/v2/tags_test.go @@ -261,7 +261,7 @@ func TestTagIndex_Get(t *testing.T) { it, err := ti.Get(exifcommon.IfdStandardIfdIdentity, 0x10f) log.PanicIf(err) - if it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) == false || it.IsName(exifcommon.IfdStandardIfdIdentity.UnindexedString(), "Make") == false { + if !it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) || !it.IsName(exifcommon.IfdStandardIfdIdentity.UnindexedString(), "Make") { t.Fatalf("tag info not correct") } } @@ -272,7 +272,7 @@ func TestTagIndex_GetWithName(t *testing.T) { it, err := ti.GetWithName(exifcommon.IfdStandardIfdIdentity, "Make") log.PanicIf(err) - if it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) == false { + if !it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) { t.Fatalf("tag info not correct") } } diff --git a/v2/testing_common.go b/v2/testing_common.go index fe69df9..d6abdac 100644 --- a/v2/testing_common.go +++ b/v2/testing_common.go @@ -7,9 +7,9 @@ import ( "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) var ( @@ -149,7 +149,7 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) { value, err := ite.Value() log.PanicIf(err) - if reflect.DeepEqual(value, expected[i].value) != true { + if !reflect.DeepEqual(value, expected[i].value) { t.Fatalf("Value for entry (%d) not correct: [%v] != [%v]", i, value, expected[i].value) } } diff --git a/v2/undefined/accessor.go b/v2/undefined/accessor.go index 3e82c0f..0f75684 100644 --- a/v2/undefined/accessor.go +++ b/v2/undefined/accessor.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) // Encode encodes the given encodeable undefined value to bytes. @@ -19,7 +19,7 @@ func Encode(value EncodeableValue, byteOrder binary.ByteOrder) (encoded []byte, encoderName := value.EncoderName() encoder, found := encoders[encoderName] - if found == false { + if !found { log.Panicf("no encoder registered for type [%s]", encoderName) } @@ -43,7 +43,7 @@ func Decode(valueContext *exifcommon.ValueContext) (value EncodeableValue, err e } decoder, found := decoders[uth] - if found == false { + if !found { // We have no choice but to return the error. We have no way of knowing how // much data there is without already knowing what data-type this tag is. return nil, exifcommon.ErrUnhandledUndefinedTypedTag diff --git a/v2/undefined/exif_8828_oecf.go b/v2/undefined/exif_8828_oecf.go index 796d17c..1ad7af0 100644 --- a/v2/undefined/exif_8828_oecf.go +++ b/v2/undefined/exif_8828_oecf.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type Tag8828Oecf struct { @@ -39,7 +39,7 @@ func (Codec8828Oecf) Encode(value interface{}, byteOrder binary.ByteOrder) (enco // TODO(dustin): Add test oecf, ok := value.(Tag8828Oecf) - if ok == false { + if !ok { log.Panicf("can only encode a Tag8828Oecf") } diff --git a/v2/undefined/exif_8828_oecf_test.go b/v2/undefined/exif_8828_oecf_test.go index 36fd0de..788ba02 100644 --- a/v2/undefined/exif_8828_oecf_test.go +++ b/v2/undefined/exif_8828_oecf_test.go @@ -5,9 +5,9 @@ import ( "reflect" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) func TestTag8828Oecf_String(t *testing.T) { @@ -28,7 +28,7 @@ func TestCodec8828Oecf_Encode(t *testing.T) { Columns: 2, Rows: 22, ColumnNames: []string{"aa", "bb"}, - Values: []exifcommon.SignedRational{{11, 22}}, + Values: []exifcommon.SignedRational{{Numerator: 11, Denominator: 22}}, } codec := Codec8828Oecf{} @@ -79,7 +79,7 @@ func TestCodec8828Oecf_Decode(t *testing.T) { Columns: 2, Rows: 22, ColumnNames: []string{"aa", "bb"}, - Values: []exifcommon.SignedRational{{11, 22}}, + Values: []exifcommon.SignedRational{{Numerator: 11, Denominator: 22}}, } if reflect.DeepEqual(value, expectedValue) != true { diff --git a/v2/undefined/exif_9000_exif_version.go b/v2/undefined/exif_9000_exif_version.go index 19cfcc9..f30b953 100644 --- a/v2/undefined/exif_9000_exif_version.go +++ b/v2/undefined/exif_9000_exif_version.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type Tag9000ExifVersion struct { @@ -31,7 +31,7 @@ func (Codec9000ExifVersion) Encode(value interface{}, byteOrder binary.ByteOrder }() s, ok := value.(Tag9000ExifVersion) - if ok == false { + if !ok { log.Panicf("can only encode a Tag9000ExifVersion") } diff --git a/v2/undefined/exif_9101_components_configuration.go b/v2/undefined/exif_9101_components_configuration.go index 16a4b38..f9a8bc6 100644 --- a/v2/undefined/exif_9101_components_configuration.go +++ b/v2/undefined/exif_9101_components_configuration.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) const ( @@ -74,7 +74,7 @@ func (CodecExif9101ComponentsConfiguration) Encode(value interface{}, byteOrder }() cc, ok := value.(TagExif9101ComponentsConfiguration) - if ok == false { + if !ok { log.Panicf("can only encode a TagExif9101ComponentsConfiguration") } @@ -94,7 +94,7 @@ func (CodecExif9101ComponentsConfiguration) Decode(valueContext *exifcommon.Valu log.PanicIf(err) for configurationId, configurationBytes := range TagUndefinedType_9101_ComponentsConfiguration_Configurations { - if bytes.Equal(configurationBytes, valueBytes) == true { + if bytes.Equal(configurationBytes, valueBytes) { cc := TagExif9101ComponentsConfiguration{ ConfigurationId: configurationId, ConfigurationBytes: valueBytes, diff --git a/v2/undefined/exif_927C_maker_note.go b/v2/undefined/exif_927C_maker_note.go index e0a52db..9c2e4ff 100644 --- a/v2/undefined/exif_927C_maker_note.go +++ b/v2/undefined/exif_927C_maker_note.go @@ -7,9 +7,9 @@ import ( "crypto/sha1" "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type Tag927CMakerNote struct { @@ -49,7 +49,7 @@ func (Codec927CMakerNote) Encode(value interface{}, byteOrder binary.ByteOrder) }() mn, ok := value.(Tag927CMakerNote) - if ok == false { + if !ok { log.Panicf("can only encode a Tag927CMakerNote") } diff --git a/v2/undefined/exif_9286_user_comment.go b/v2/undefined/exif_9286_user_comment.go index de07fe1..7d2069f 100644 --- a/v2/undefined/exif_9286_user_comment.go +++ b/v2/undefined/exif_9286_user_comment.go @@ -2,13 +2,14 @@ package exifundefined import ( "bytes" + "context" "fmt" "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) var ( @@ -74,12 +75,12 @@ func (Codec9286UserComment) Encode(value interface{}, byteOrder binary.ByteOrder }() uc, ok := value.(Tag9286UserComment) - if ok == false { + if !ok { log.Panicf("can only encode a Tag9286UserComment") } encodingTypeBytes, found := TagUndefinedType_9286_UserComment_Encodings[uc.EncodingType] - if found == false { + if !found { log.Panicf("encoding-type not valid for unknown-type tag 9286 (UserComment): (%d)", uc.EncodingType) } @@ -126,7 +127,7 @@ func (Codec9286UserComment) Decode(valueContext *exifcommon.ValueContext) (value } } - exif9286Logger.Warningf(nil, "User-comment encoding not valid. Returning 'unknown' type (the default).") + exif9286Logger.Warningf(context.TODO(), "User-comment encoding not valid. Returning 'unknown' type (the default).") return unknownUc, nil } diff --git a/v2/undefined/exif_A000_flashpix_version.go b/v2/undefined/exif_A000_flashpix_version.go index 28849cd..56b25b1 100644 --- a/v2/undefined/exif_A000_flashpix_version.go +++ b/v2/undefined/exif_A000_flashpix_version.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type TagA000FlashpixVersion struct { @@ -31,7 +31,7 @@ func (CodecA000FlashpixVersion) Encode(value interface{}, byteOrder binary.ByteO }() s, ok := value.(TagA000FlashpixVersion) - if ok == false { + if !ok { log.Panicf("can only encode a TagA000FlashpixVersion") } diff --git a/v2/undefined/exif_A20C_spatial_frequency_response.go b/v2/undefined/exif_A20C_spatial_frequency_response.go index d49c8c5..d1bf75b 100644 --- a/v2/undefined/exif_A20C_spatial_frequency_response.go +++ b/v2/undefined/exif_A20C_spatial_frequency_response.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type TagA20CSpatialFrequencyResponse struct { @@ -39,7 +39,7 @@ func (CodecA20CSpatialFrequencyResponse) Encode(value interface{}, byteOrder bin // TODO(dustin): Add test. sfr, ok := value.(TagA20CSpatialFrequencyResponse) - if ok == false { + if !ok { log.Panicf("can only encode a TagA20CSpatialFrequencyResponse") } diff --git a/v2/undefined/exif_A20C_spatial_frequency_response_test.go b/v2/undefined/exif_A20C_spatial_frequency_response_test.go index 73ebe5b..de2cd85 100644 --- a/v2/undefined/exif_A20C_spatial_frequency_response_test.go +++ b/v2/undefined/exif_A20C_spatial_frequency_response_test.go @@ -5,9 +5,8 @@ import ( "reflect" "testing" - "github.com/dsoprea/go-logging" - - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) func TestTagA20CSpatialFrequencyResponse_String(t *testing.T) { @@ -16,8 +15,8 @@ func TestTagA20CSpatialFrequencyResponse_String(t *testing.T) { Rows: 9, ColumnNames: []string{"column1", "column2"}, Values: []exifcommon.Rational{ - {1, 2}, - {3, 4}, + {Numerator: 1, Denominator: 2}, + {Numerator: 3, Denominator: 4}, }, } @@ -33,8 +32,8 @@ func TestCodecA20CSpatialFrequencyResponse_Encode(t *testing.T) { Rows: 9, ColumnNames: []string{"column1", "column2"}, Values: []exifcommon.Rational{ - {1, 2}, - {3, 4}, + {Numerator: 1, Denominator: 2}, + {Numerator: 3, Denominator: 4}, }, } @@ -67,8 +66,8 @@ func TestCodecA20CSpatialFrequencyResponse_Decode(t *testing.T) { Rows: 9, ColumnNames: []string{"column1", "column2"}, Values: []exifcommon.Rational{ - {1, 2}, - {3, 4}, + {Numerator: 1, Denominator: 2}, + {Numerator: 3, Denominator: 4}, }, } diff --git a/v2/undefined/exif_A300_file_source.go b/v2/undefined/exif_A300_file_source.go index 18a7cdf..bc8f1e3 100644 --- a/v2/undefined/exif_A300_file_source.go +++ b/v2/undefined/exif_A300_file_source.go @@ -5,9 +5,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type TagExifA300FileSource uint32 @@ -38,7 +38,7 @@ func (CodecExifA300FileSource) Encode(value interface{}, byteOrder binary.ByteOr }() st, ok := value.(TagExifA300FileSource) - if ok == false { + if !ok { log.Panicf("can only encode a TagExifA300FileSource") } diff --git a/v2/undefined/exif_A301_scene_type.go b/v2/undefined/exif_A301_scene_type.go index b4246da..3deaffb 100644 --- a/v2/undefined/exif_A301_scene_type.go +++ b/v2/undefined/exif_A301_scene_type.go @@ -5,9 +5,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type TagExifA301SceneType uint32 @@ -35,7 +35,7 @@ func (CodecExifA301SceneType) Encode(value interface{}, byteOrder binary.ByteOrd }() st, ok := value.(TagExifA301SceneType) - if ok == false { + if !ok { log.Panicf("can only encode a TagExif9101ComponentsConfiguration") } diff --git a/v2/undefined/exif_A302_cfa_pattern.go b/v2/undefined/exif_A302_cfa_pattern.go index beca78c..37aafbc 100644 --- a/v2/undefined/exif_A302_cfa_pattern.go +++ b/v2/undefined/exif_A302_cfa_pattern.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type TagA302CfaPattern struct { @@ -38,7 +38,7 @@ func (CodecA302CfaPattern) Encode(value interface{}, byteOrder binary.ByteOrder) // TODO(dustin): Add test. cp, ok := value.(TagA302CfaPattern) - if ok == false { + if !ok { log.Panicf("can only encode a TagA302CfaPattern") } diff --git a/v2/undefined/exif_iop_0002_interop_version.go b/v2/undefined/exif_iop_0002_interop_version.go index eca046b..155e3f2 100644 --- a/v2/undefined/exif_iop_0002_interop_version.go +++ b/v2/undefined/exif_iop_0002_interop_version.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type Tag0002InteropVersion struct { @@ -31,7 +31,7 @@ func (Codec0002InteropVersion) Encode(value interface{}, byteOrder binary.ByteOr }() s, ok := value.(Tag0002InteropVersion) - if ok == false { + if !ok { log.Panicf("can only encode a Tag0002InteropVersion") } diff --git a/v2/undefined/gps_001B_gps_processing_method.go b/v2/undefined/gps_001B_gps_processing_method.go index 8583bfb..fcfa69e 100644 --- a/v2/undefined/gps_001B_gps_processing_method.go +++ b/v2/undefined/gps_001B_gps_processing_method.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type Tag001BGPSProcessingMethod struct { @@ -31,7 +31,7 @@ func (Codec001BGPSProcessingMethod) Encode(value interface{}, byteOrder binary.B }() s, ok := value.(Tag001BGPSProcessingMethod) - if ok == false { + if !ok { log.Panicf("can only encode a Tag001BGPSProcessingMethod") } diff --git a/v2/undefined/gps_001C_gps_area_information.go b/v2/undefined/gps_001C_gps_area_information.go index 67acceb..32fdea5 100644 --- a/v2/undefined/gps_001C_gps_area_information.go +++ b/v2/undefined/gps_001C_gps_area_information.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/common" + log "github.com/dsoprea/go-logging" ) type Tag001CGPSAreaInformation struct { @@ -31,7 +31,7 @@ func (Codec001CGPSAreaInformation) Encode(value interface{}, byteOrder binary.By }() s, ok := value.(Tag001CGPSAreaInformation) - if ok == false { + if !ok { log.Panicf("can only encode a Tag001CGPSAreaInformation") } diff --git a/v2/undefined/registration.go b/v2/undefined/registration.go index cccc20a..82c712f 100644 --- a/v2/undefined/registration.go +++ b/v2/undefined/registration.go @@ -1,8 +1,6 @@ package exifundefined -import ( - "github.com/dsoprea/go-logging" -) +import log "github.com/dsoprea/go-logging" // UndefinedTagHandle defines one undefined-type tag with a corresponding // decoder. @@ -15,7 +13,7 @@ func registerEncoder(entity EncodeableValue, encoder UndefinedValueEncoder) { typeName := entity.EncoderName() _, found := encoders[typeName] - if found == true { + if found { log.Panicf("encoder already registered: %v", typeName) } @@ -29,7 +27,7 @@ func registerDecoder(ifdPath string, tagId uint16, decoder UndefinedValueDecoder } _, found := decoders[uth] - if found == true { + if found { log.Panicf("decoder already registered: %v", uth) } diff --git a/v3/command/exif-read-tool/main.go b/v3/command/exif-read-tool/main.go index 6a6b459..beac343 100644 --- a/v3/command/exif-read-tool/main.go +++ b/v3/command/exif-read-tool/main.go @@ -14,17 +14,19 @@ package main import ( + "context" "fmt" "os" "encoding/json" "io/ioutil" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" + + log "github.com/dsoprea/go-logging" "github.com/jessevdk/go-flags" "github.com/dsoprea/go-exif/v3" - "github.com/dsoprea/go-exif/v3/common" ) const ( @@ -78,7 +80,7 @@ func main() { os.Exit(-1) } - if arguments.IsVerbose == true { + if arguments.IsVerbose { cla := log.NewConsoleLogAdapter() log.AddAdapter("console", cla) @@ -104,14 +106,14 @@ func main() { log.Panic(err) } - mainLogger.Debugf(nil, "EXIF blob is (%d) bytes.", len(rawExif)) + mainLogger.Debugf(context.TODO(), "EXIF blob is (%d) bytes.", len(rawExif)) // Run the parse. entries, _, err := exif.GetFlatExifDataUniversalSearch(rawExif, nil, arguments.DoUniversalTagSearch) if err != nil { if arguments.SkipBlocks > 0 { - mainLogger.Warningf(nil, "Encountered an error. This might be related to the request to skip EXIF blocks.") + mainLogger.Warningf(context.TODO(), "Encountered an error. This might be related to the request to skip EXIF blocks.") } log.Panic(err) @@ -130,7 +132,7 @@ func main() { log.PanicIf(err) var thumbnail []byte - if ifd, found := index.Lookup[exif.ThumbnailFqIfdPath]; found == true { + if ifd, found := index.Lookup[exif.ThumbnailFqIfdPath]; found { thumbnail, err = ifd.Thumbnail() if err != nil && err != exif.ErrNoThumbnail { log.Panic(err) @@ -138,9 +140,9 @@ func main() { } if thumbnail == nil { - mainLogger.Debugf(nil, "No thumbnails found.") + mainLogger.Debugf(context.TODO(), "No thumbnails found.") } else { - if arguments.PrintAsJson == false { + if !arguments.PrintAsJson { fmt.Printf("Writing (%d) bytes for thumbnail: [%s]\n", len(thumbnail), thumbnailOutputFilepath) fmt.Printf("\n") } @@ -150,8 +152,8 @@ func main() { } } - if arguments.DoNotPrintTags == false { - if arguments.PrintAsJson == true { + if !arguments.DoNotPrintTags { + if arguments.PrintAsJson { data, err := json.MarshalIndent(entries, "", " ") log.PanicIf(err) diff --git a/v3/command/exif-read-tool/main_test.go b/v3/command/exif-read-tool/main_test.go index 2d3b7e1..0bb8b36 100644 --- a/v3/command/exif-read-tool/main_test.go +++ b/v3/command/exif-read-tool/main_test.go @@ -144,12 +144,12 @@ func TestMainJson(t *testing.T) { err = json.Unmarshal(expectedRaw, &expected) log.PanicIf(err) - // if reflect.DeepEqual(actual, expected) == false { + // if !reflect.DeepEqual(actual, expected) { // t.Fatalf("Output not as expected:\nACTUAL:\n%s\nEXPECTED:\n%s", actualRaw, expectedRaw) // } for i, tagInfo := range actual { - if reflect.DeepEqual(tagInfo, expected[i]) == false { + if !reflect.DeepEqual(tagInfo, expected[i]) { actualBytes, err := json.MarshalIndent(tagInfo, "", " ") log.PanicIf(err) diff --git a/v3/common/ifd.go b/v3/common/ifd.go index 01886e9..c07de4d 100644 --- a/v3/common/ifd.go +++ b/v3/common/ifd.go @@ -5,11 +5,7 @@ import ( "fmt" "strings" - "github.com/dsoprea/go-logging" -) - -var ( - ifdLogger = log.NewLogger("exifcommon.ifd") + log "github.com/dsoprea/go-logging" ) var ( @@ -84,7 +80,7 @@ func (im *IfdMapping) Get(parentPlacement []uint16) (childIfd *MappedIfd, err er ptr := im.rootNode for _, tagId := range parentPlacement { - if descendantPtr, found := ptr.Children[tagId]; found == false { + if descendantPtr, found := ptr.Children[tagId]; !found { log.Panicf("ifd child with tag-ID (%04x) not registered: [%s]", tagId, ptr.PathPhrase()) } else { ptr = descendantPtr @@ -307,7 +303,7 @@ func (im *IfdMapping) Add(parentPlacement []uint16, tagId uint16, name string) ( Children: make(map[uint16]*MappedIfd), } - if _, found := ptr.Children[tagId]; found == true { + if _, found := ptr.Children[tagId]; found { log.Panicf("child IFD with tag-ID (%04x) already registered under IFD [%s] with tag-ID (%04x)", tagId, ptr.Name, ptr.TagId) } diff --git a/v3/common/parser.go b/v3/common/parser.go index 76e8ef4..daf3e0b 100644 --- a/v3/common/parser.go +++ b/v3/common/parser.go @@ -2,12 +2,13 @@ package exifcommon import ( "bytes" + "context" "errors" "math" "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -62,14 +63,14 @@ func (p *Parser) ParseAscii(data []byte, unitCount uint32) (value string, err er if len(data) == 0 || data[count-1] != 0 { s := string(data[:count]) - parserLogger.Warningf(nil, "ASCII not terminated with NUL as expected: [%v]", s) + parserLogger.Warningf(context.TODO(), "ASCII not terminated with NUL as expected: [%v]", s) for i, c := range s { if c > 127 { // Binary t := s[:i] - parserLogger.Warningf(nil, "ASCII also had binary characters. Truncating: [%v]->[%s]", s, t) + parserLogger.Warningf(context.TODO(), "ASCII also had binary characters. Truncating: [%v]->[%s]", s, t) return t, nil } diff --git a/v3/common/testing_common.go b/v3/common/testing_common.go index f04fa22..33e8da3 100644 --- a/v3/common/testing_common.go +++ b/v3/common/testing_common.go @@ -5,16 +5,13 @@ import ( "path" "encoding/binary" - "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( moduleRootPath = "" - testExifData []byte = nil - // EncodeDefaultByteOrder is the default byte-order for encoding operations. EncodeDefaultByteOrder = binary.BigEndian @@ -40,7 +37,7 @@ func GetModuleRootPath() string { tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT") _, err := os.Stat(tryStampFilepath) - if err != nil && os.IsNotExist(err) != true { + if err != nil && !os.IsNotExist(err) { log.Panic(err) } else if err == nil { break @@ -66,23 +63,3 @@ func GetTestAssetsPath() string { return assetsPath } - -func getTestImageFilepath() string { - assetsPath := GetTestAssetsPath() - testImageFilepath := path.Join(assetsPath, "NDM_8901.jpg") - return testImageFilepath -} - -func getTestExifData() []byte { - if testExifData == nil { - assetsPath := GetTestAssetsPath() - filepath := path.Join(assetsPath, "NDM_8901.jpg.exif") - - var err error - - testExifData, err = ioutil.ReadFile(filepath) - log.PanicIf(err) - } - - return testExifData -} diff --git a/v3/common/type.go b/v3/common/type.go index e79bcb9..6632aca 100644 --- a/v3/common/type.go +++ b/v3/common/type.go @@ -10,11 +10,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" -) - -var ( - typeLogger = log.NewLogger("exif.type") + log "github.com/dsoprea/go-logging" ) var ( @@ -160,7 +156,7 @@ func isPrintableText(s string) bool { // unicode.IsPrint() returns false for newline characters. if c == 0x0d || c == 0x0a { continue - } else if unicode.IsPrint(rune(c)) == false { + } else if !unicode.IsPrint(rune(c)) { return false } } @@ -193,7 +189,7 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error } } - if isPrintableText(t) == false { + if !isPrintableText(t) { phrase = fmt.Sprintf("string with binary data (%d bytes)", len(t)) return phrase, nil } @@ -206,7 +202,7 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error return "", nil } - if justFirst == true { + if justFirst { var valueSuffix string if val.Len() > 1 { valueSuffix = "..." @@ -225,12 +221,12 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error for i, r := range t { parts[i] = fmt.Sprintf("%d/%d", r.Numerator, r.Denominator) - if justFirst == true { + if justFirst { break } } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." @@ -249,12 +245,12 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error for i, r := range t { parts[i] = fmt.Sprintf("%d/%d", r.Numerator, r.Denominator) - if justFirst == true { + if justFirst { break } } - if justFirst == true { + if justFirst { var valueSuffix string if len(t) > 1 { valueSuffix = "..." @@ -266,7 +262,7 @@ func FormatFromType(value interface{}, justFirst bool) (phrase string, err error return fmt.Sprintf("%v", parts), nil case fmt.Stringer: s := t.String() - if isPrintableText(s) == false { + if !isPrintableText(s) { phrase = fmt.Sprintf("stringable with binary data (%d bytes)", len(s)) return phrase, nil } diff --git a/v3/common/value_context.go b/v3/common/value_context.go index b9e6341..3ae1dc4 100644 --- a/v3/common/value_context.go +++ b/v3/common/value_context.go @@ -6,7 +6,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -151,7 +151,7 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) { unitSizeRaw := uint32(tagType.Size()) - if vc.isEmbedded() == true { + if vc.isEmbedded() { byteLength := unitSizeRaw * vc.unitCount return vc.rawValueOffset[:byteLength], nil } @@ -170,7 +170,7 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) { // GetFarOffset returns the offset if the value is not embedded [within the // pointer itself] or an error if an embedded value. func (vc *ValueContext) GetFarOffset() (offset uint32, err error) { - if vc.isEmbedded() == true { + if vc.isEmbedded() { return 0, ErrNotFarValue } diff --git a/v3/common/value_encoder.go b/v3/common/value_encoder.go index 2cd26cc..b4760ec 100644 --- a/v3/common/value_encoder.go +++ b/v3/common/value_encoder.go @@ -8,11 +8,7 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" -) - -var ( - typeEncodeLogger = log.NewLogger("exif.type_encode") + log "github.com/dsoprea/go-logging" ) // EncodedData encapsulates the compound output of an encoding operation. diff --git a/v3/data_layer.go b/v3/data_layer.go index 7883752..3ac9ad6 100644 --- a/v3/data_layer.go +++ b/v3/data_layer.go @@ -3,8 +3,8 @@ package exif import ( "io" - "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-utility/v2/filesystem" + log "github.com/dsoprea/go-logging" + rifs "github.com/dsoprea/go-utility/v2/filesystem" ) type ExifBlobSeeker interface { diff --git a/v3/exif.go b/v3/exif.go index f66e839..7856f9f 100644 --- a/v3/exif.go +++ b/v3/exif.go @@ -3,6 +3,7 @@ package exif import ( "bufio" "bytes" + "context" "errors" "fmt" "io" @@ -11,9 +12,8 @@ import ( "encoding/binary" "io/ioutil" - "github.com/dsoprea/go-logging" - - "github.com/dsoprea/go-exif/v3/common" + exifcommon "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) const ( @@ -96,23 +96,23 @@ func SearchAndExtractExifN(data []byte, n int) (rawExif []byte, err error) { log.Panic(err) } - exifLogger.Debugf(nil, "Read EXIF block (%d).", skips) + exifLogger.Debugf(context.TODO(), "Read EXIF block (%d).", skips) totalDiscarded += discarded if skips >= n { - exifLogger.Debugf(nil, "Reached requested EXIF block (%d).", n) + exifLogger.Debugf(context.TODO(), "Reached requested EXIF block (%d).", n) break } nextOffset := discarded + 1 - exifLogger.Debugf(nil, "Skipping EXIF block (%d) by seeking to position (%d).", skips, nextOffset) + exifLogger.Debugf(context.TODO(), "Skipping EXIF block (%d) by seeking to position (%d).", skips, nextOffset) data = data[nextOffset:] skips++ } - exifLogger.Debugf(nil, "Found EXIF blob (%d) bytes from initial position.", totalDiscarded) + exifLogger.Debugf(context.TODO(), "Found EXIF blob (%d) bytes from initial position.", totalDiscarded) return rawExif, nil } @@ -146,7 +146,7 @@ func searchAndExtractExifWithReaderWithDiscarded(r io.Reader) (rawExif []byte, d _, err = ParseExifHeader(window) if err != nil { - if log.Is(err, ErrNoExif) == true { + if log.Is(err, ErrNoExif) { // No EXIF. Move forward by one byte. _, err := br.Discard(1) @@ -164,7 +164,7 @@ func searchAndExtractExifWithReaderWithDiscarded(r io.Reader) (rawExif []byte, d break } - exifLogger.Debugf(nil, "Found EXIF blob (%d) bytes from initial position.", discarded) + exifLogger.Debugf(context.TODO(), "Found EXIF blob (%d) bytes from initial position.", discarded) rawExif, err = ioutil.ReadAll(br) log.PanicIf(err) @@ -245,16 +245,16 @@ func ParseExifHeader(data []byte) (eh ExifHeader, err error) { // -> http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf if len(data) < ExifSignatureLength { - exifLogger.Warningf(nil, "Not enough data for EXIF header: (%d)", len(data)) + exifLogger.Warningf(context.TODO(), "Not enough data for EXIF header: (%d)", len(data)) return eh, ErrNoExif } - if bytes.Equal(data[:4], ExifBigEndianSignature[:]) == true { - exifLogger.Debugf(nil, "Byte-order is big-endian.") + if bytes.Equal(data[:4], ExifBigEndianSignature[:]) { + exifLogger.Debugf(context.TODO(), "Byte-order is big-endian.") eh.ByteOrder = binary.BigEndian - } else if bytes.Equal(data[:4], ExifLittleEndianSignature[:]) == true { + } else if bytes.Equal(data[:4], ExifLittleEndianSignature[:]) { eh.ByteOrder = binary.LittleEndian - exifLogger.Debugf(nil, "Byte-order is little-endian.") + exifLogger.Debugf(context.TODO(), "Byte-order is little-endian.") } else { return eh, ErrNoExif } diff --git a/v3/exif_test.go b/v3/exif_test.go index 7737378..b2c5f9f 100644 --- a/v3/exif_test.go +++ b/v3/exif_test.go @@ -50,7 +50,7 @@ func TestVisit(t *testing.T) { if _, err := ParseExifHeader(data[i:]); err == nil { foundAt = i break - } else if log.Is(err, ErrNoExif) == false { + } else if !log.Is(err, ErrNoExif) { log.Panic(err) } } @@ -167,7 +167,7 @@ func TestVisit(t *testing.T) { "IFD-PATH=[IFD1] ID=(0x0202) NAME=[JPEGInterchangeFormatLength] COUNT=(1) TYPE=[LONG] VALUE=[21491]", } - if reflect.DeepEqual(tags, expected) == false { + if !reflect.DeepEqual(tags, expected) { fmt.Printf("\n") fmt.Printf("ACTUAL:\n") fmt.Printf("\n") @@ -200,7 +200,7 @@ func TestSearchFileAndExtractExif(t *testing.T) { testExifData := getTestExifData() - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } @@ -216,7 +216,7 @@ func TestSearchAndExtractExif(t *testing.T) { testExifData := getTestExifData() - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } @@ -234,7 +234,7 @@ func TestSearchAndExtractExifWithReader(t *testing.T) { testExifData := getTestExifData() - if bytes.Compare(rawExif[:len(testExifData)], testExifData) != 0 { + if !bytes.Equal(rawExif[:len(testExifData)], testExifData) { t.Fatalf("found EXIF data not correct") } } diff --git a/v3/go.mod b/v3/go.mod index e5a18f0..43d94b6 100644 --- a/v3/go.mod +++ b/v3/go.mod @@ -9,10 +9,7 @@ go 1.12 require ( github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 - github.com/go-errors/errors v1.4.2 // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 github.com/jessevdk/go-flags v1.5.0 - golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect - golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect gopkg.in/yaml.v2 v2.4.0 ) diff --git a/v3/go.sum b/v3/go.sum index f69540e..4791437 100644 --- a/v3/go.sum +++ b/v3/go.sum @@ -1,11 +1,17 @@ github.com/dsoprea/go-exif/v2 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= +github.com/dsoprea/go-exif/v3 v3.0.0-20210625224831-a6301f85c82b/go.mod h1:cg5SNYKHMmzxsr9X6ZeLh/nfBRHHp5PngtEPcujONtk= +github.com/dsoprea/go-exif/v3 v3.0.0-20221003160559-cf5cd88aa559/go.mod h1:rW6DMEv25U9zCtE5ukC7ttBRllXj7g7TAHl7tQrT5No= +github.com/dsoprea/go-exif/v3 v3.0.0-20221003171958-de6cb6e380a8/go.mod h1:akyZEJZ/k5bmbC9gA612ZLQkcED8enS9vuTiuAkENr0= github.com/dsoprea/go-logging v0.0.0-20190624164917-c4f10aab7696/go.mod h1:Nm/x2ZUNRW6Fe5C3LxdY1PyZY5wmDv/s5dkPJ/VB3iA= 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 v2.0.0-20200717064901-2fccff4aa15e/go.mod h1:uAzdkPTub5Y9yQwXe8W4m2XuP0tK4a9Q/dantD0+uaU= +github.com/dsoprea/go-utility/v2 v2.0.0-20221003142440-7a1927d49d9d/go.mod h1:LVjRU0RNUuMDqkPTxcALio0LWPFPXxxFCvVGVAwEpFc= +github.com/dsoprea/go-utility/v2 v2.0.0-20221003160719-7bc88537c05e/go.mod h1:VZ7cB0pTjm1ADBWhJUOHESu4ZYy9JN+ZPqjfiW09EPU= github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 h1:DilThiXje0z+3UQ5YjYiSRRzVdtamFpvBQXKwMglWqw= github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349/go.mod h1:4GC5sXji84i/p+irqghpPFZBF8tRN/Q7+700G0/DLe8= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= diff --git a/v3/gps.go b/v3/gps.go index 7a61cd9..418be99 100644 --- a/v3/gps.go +++ b/v3/gps.go @@ -5,10 +5,10 @@ import ( "fmt" "time" - "github.com/dsoprea/go-logging" - "github.com/golang/geo/s2" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" + "github.com/golang/geo/s2" ) var ( @@ -109,7 +109,7 @@ func (gi *GpsInfo) S2CellId() s2.CellID { ll := s2.LatLngFromDegrees(latitude, longitude) cellId := s2.CellIDFromLatLng(ll) - if cellId.IsValid() == false { + if !cellId.IsValid() { panic(ErrGpsCoordinatesNotValid) } diff --git a/v3/ifd_builder.go b/v3/ifd_builder.go index a404b36..6753a52 100644 --- a/v3/ifd_builder.go +++ b/v3/ifd_builder.go @@ -12,14 +12,10 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" + exifundefined "github.com/dsoprea/go-exif/v3/undefined" - "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/undefined" -) - -var ( - ifdBuilderLogger = log.NewLogger("exif.ifd_builder") + log "github.com/dsoprea/go-logging" ) var ( @@ -33,7 +29,7 @@ type IfdBuilderTagValue struct { } func (ibtv IfdBuilderTagValue) String() string { - if ibtv.IsBytes() == true { + if ibtv.IsBytes() { var valuePhrase string if len(ibtv.valueBytes) <= 8 { valuePhrase = fmt.Sprintf("%v", ibtv.valueBytes) @@ -42,7 +38,7 @@ func (ibtv IfdBuilderTagValue) String() string { } return fmt.Sprintf("IfdBuilderTagValue", valuePhrase, len(ibtv.valueBytes)) - } else if ibtv.IsIb() == true { + } else if ibtv.IsIb() { return fmt.Sprintf("IfdBuilderTagValue", ibtv.ib) } else { log.Panicf("IBTV state undefined") @@ -69,9 +65,9 @@ func (ibtv IfdBuilderTagValue) IsBytes() bool { } func (ibtv IfdBuilderTagValue) Bytes() []byte { - if ibtv.IsBytes() == false { + if !ibtv.IsBytes() { log.Panicf("this tag is not a byte-slice value") - } else if ibtv.IsIb() == true { + } else if ibtv.IsIb() { log.Panicf("this tag is an IFD-builder value not a byte-slice") } @@ -83,9 +79,9 @@ func (ibtv IfdBuilderTagValue) IsIb() bool { } func (ibtv IfdBuilderTagValue) Ib() *IfdBuilder { - if ibtv.IsIb() == false { + if !ibtv.IsIb() { log.Panicf("this tag is not an IFD-builder value") - } else if ibtv.IsBytes() == true { + } else if ibtv.IsBytes() { log.Panicf("this tag is a byte-slice, not a IFD-builder") } @@ -135,7 +131,7 @@ func (bt *BuilderTag) Value() (value *IfdBuilderTagValue) { func (bt *BuilderTag) String() string { var valueString string - if bt.value.IsBytes() == true { + if bt.value.IsBytes() { var err error valueString, err = exifcommon.FormatFromBytes(bt.value.Bytes(), bt.typeId, false, bt.byteOrder) @@ -191,7 +187,7 @@ func NewStandardBuilderTag(ifdPath string, it *IndexedTag, byteOrder binary.Byte tagType := it.GetEncodingType(value) var rawBytes []byte - if it.DoesSupportType(exifcommon.TypeUndefined) == true { + if it.DoesSupportType(exifcommon.TypeUndefined) { encodeable := value.(exifundefined.EncodeableValue) var err error @@ -315,7 +311,7 @@ func (ib *IfdBuilder) ChildWithTagId(childIfdTagId uint16) (childIb *IfdBuilder, }() for _, bt := range ib.tags { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { continue } @@ -397,7 +393,7 @@ func getOrCreateIbFromRootIbInner(rootIb *IfdBuilder, parentIb *IfdBuilder, curr var foundChild *IfdBuilder for _, bt := range thisIb.tags { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { continue } @@ -498,7 +494,7 @@ func (ib *IfdBuilder) SetThumbnail(data []byte) (err error) { // TODO(dustin): !! Add a test for this function. - if data == nil || len(data) == 0 { + if len(data) == 0 { log.Panic("thumbnail is empty") } @@ -555,18 +551,18 @@ func (ib *IfdBuilder) printTagTree(levels int) { _, err := ib.ifdMapping.GetChild(currentIb.IfdIdentity().UnindexedString(), tag.tagId) if err == nil { isChildIb = true - } else if log.Is(err, exifcommon.ErrChildIfdNotMapped) == false { + } else if !log.Is(err, exifcommon.ErrChildIfdNotMapped) { log.Panic(err) } tagName := "" // If a normal tag (not a child IFD) get the name. - if isChildIb == true { + if isChildIb { tagName = "" } else { it, err := ib.tagIndex.Get(ib.ifdIdentity, tag.tagId) - if log.Is(err, ErrTagNotFound) == true { + if log.Is(err, ErrTagNotFound) { tagName = "" } else if err != nil { log.Panic(err) @@ -577,14 +573,14 @@ func (ib *IfdBuilder) printTagTree(levels int) { value := tag.Value() - if value.IsIb() == true { + if value.IsIb() { fmt.Printf("%s (%d): [%s] %s\n", indent, i, tagName, value.Ib()) } else { fmt.Printf("%s (%d): [%s] %s\n", indent, i, tagName, tag) } - if isChildIb == true { - if tag.value.IsIb() == false { + if isChildIb { + if !tag.value.IsIb() { log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag) } @@ -624,12 +620,12 @@ func (ib *IfdBuilder) printIfdTree(levels int) { _, err := ib.ifdMapping.GetChild(currentIb.IfdIdentity().UnindexedString(), tag.tagId) if err == nil { isChildIb = true - } else if log.Is(err, exifcommon.ErrChildIfdNotMapped) == false { + } else if !log.Is(err, exifcommon.ErrChildIfdNotMapped) { log.Panic(err) } - if isChildIb == true { - if tag.value.IsIb() == false { + if isChildIb { + if !tag.value.IsIb() { log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag) } @@ -662,7 +658,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin for i, tag := range thisIb.tags { var childIb *IfdBuilder childIfdName := "" - if tag.value.IsIb() == true { + if tag.value.IsIb() { childIb = tag.value.Ib() childIfdName = childIb.IfdIdentity().UnindexedString() } @@ -676,7 +672,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin childPrefix := "" if prefix == "" { - childPrefix = fmt.Sprintf("%s", thisIb.IfdIdentity().UnindexedString()) + childPrefix = thisIb.IfdIdentity().UnindexedString() } else { childPrefix = fmt.Sprintf("%s->%s", prefix, thisIb.IfdIdentity().UnindexedString()) } @@ -759,7 +755,7 @@ func (ib *IfdBuilder) DeleteAll(tagId uint16) (n int, err error) { for { err = ib.DeleteN(tagId, 1) - if log.Is(err, ErrTagEntryNotFound) == true { + if log.Is(err, ErrTagEntryNotFound) { break } else if err != nil { log.Panic(err) @@ -815,7 +811,7 @@ func (ib *IfdBuilder) Set(bt *BuilderTag) (err error) { position, err := ib.Find(bt.tagId) if err == nil { ib.tags[position] = bt - } else if log.Is(err, ErrTagEntryNotFound) == true { + } else if log.Is(err, ErrTagEntryNotFound) { err = ib.add(bt) log.PanicIf(err) } else { @@ -930,7 +926,7 @@ func (ib *IfdBuilder) Add(bt *BuilderTag) (err error) { } }() - if bt.value.IsIb() == true { + if bt.value.IsIb() { log.Panicf("child IfdBuilders must be added via AddChildIb() or AddTagsFromExisting(), not Add()") } @@ -1001,17 +997,17 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl if err == nil { err = ib.SetThumbnail(thumbnailData) log.PanicIf(err) - } else if log.Is(err, ErrNoThumbnail) == false { + } else if !log.Is(err, ErrNoThumbnail) { log.Panic(err) } for i, ite := range ifd.Entries() { - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { + if ite.IsThumbnailOffset() || ite.IsThumbnailSize() { // These will be added on-the-fly when we encode. continue } - if excludeTagIds != nil && len(excludeTagIds) > 0 { + if len(excludeTagIds) > 0 { found := false for _, excludedTagId := range excludeTagIds { if excludedTagId == ite.TagId() { @@ -1019,12 +1015,12 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl } } - if found == true { + if found { continue } } - if includeTagIds != nil && len(includeTagIds) > 0 { + if len(includeTagIds) > 0 { // Whether or not there was a list of excludes, if there is a list // of includes than the current tag has to be in it. @@ -1036,7 +1032,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl } } - if found == false { + if !found { continue } } @@ -1155,7 +1151,7 @@ func (ib *IfdBuilder) SetStandard(tagId uint16, value interface{}) (err error) { i, err := ib.Find(tagId) if err != nil { - if log.Is(err, ErrTagEntryNotFound) == false { + if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } @@ -1186,7 +1182,7 @@ func (ib *IfdBuilder) SetStandardWithName(tagName string, value interface{}) (er i, err := ib.Find(bt.tagId) if err != nil { - if log.Is(err, ErrTagEntryNotFound) == false { + if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } diff --git a/v3/ifd_builder_encode.go b/v3/ifd_builder_encode.go index a0f4ff7..845aa92 100644 --- a/v3/ifd_builder_encode.go +++ b/v3/ifd_builder_encode.go @@ -7,9 +7,9 @@ import ( "encoding/binary" - "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 ( @@ -219,7 +219,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * // Write unit-count. - if bt.value.IsBytes() == true { + if bt.value.IsBytes() { effectiveType := bt.typeId if bt.typeId == exifcommon.TypeUndefined { effectiveType = exifcommon.TypeByte @@ -235,7 +235,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * len_ := len(valueBytes) unitCount := uint32(len_) / typeSize - if _, found := tagsWithoutAlignment[bt.tagId]; found == false { + if _, found := tagsWithoutAlignment[bt.tagId]; !found { remainder := uint32(len_) % typeSize if remainder > 0 { @@ -262,7 +262,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * log.PanicIf(err) } } else { - if bt.value.IsIb() == false { + if !bt.value.IsIb() { log.Panicf("tag value is not a byte-slice but also not a child IB: %v", bt) } @@ -364,7 +364,7 @@ func (ibe *IfdByteEncoder) encodeIfdToBytes(ib *IfdBuilder, ifdAddressableOffset // N the link from this IFD to the next IFD that will be written in the // next cycle. - if setNextIb == true { + if setNextIb { // Write address of next IFD in chain. This will be the original // allocation offset plus the size of everything we have allocated for // this IFD and its child-IFDs. diff --git a/v3/ifd_builder_encode_test.go b/v3/ifd_builder_encode_test.go index 0c4d0dd..8030b90 100644 --- a/v3/ifd_builder_encode_test.go +++ b/v3/ifd_builder_encode_test.go @@ -6,9 +6,9 @@ import ( "strings" "testing" - "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" ) func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { @@ -18,7 +18,7 @@ func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { err := bw.writeAsBytes(uint8(0x12)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12}) { t.Fatalf("uint8 not encoded correctly.") } } @@ -30,7 +30,7 @@ func Test_ByteWriter_writeAsBytes_uint16(t *testing.T) { err := bw.writeAsBytes(uint16(0x1234)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34}) { t.Fatalf("uint16 not encoded correctly.") } } @@ -42,7 +42,7 @@ func Test_ByteWriter_writeAsBytes_uint32(t *testing.T) { err := bw.writeAsBytes(uint32(0x12345678)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) { t.Fatalf("uint32 not encoded correctly.") } } @@ -54,7 +54,7 @@ func Test_ByteWriter_WriteUint16(t *testing.T) { err := bw.WriteUint16(uint16(0x1234)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34}) { t.Fatalf("uint16 not encoded correctly (as bytes).") } } @@ -66,7 +66,7 @@ func Test_ByteWriter_WriteUint32(t *testing.T) { err := bw.WriteUint32(uint32(0x12345678)) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x12, 0x34, 0x56, 0x78}) { t.Fatalf("uint32 not encoded correctly (as bytes).") } } @@ -78,7 +78,7 @@ func Test_ByteWriter_WriteFourBytes(t *testing.T) { err := bw.WriteFourBytes([]byte{0x11, 0x22, 0x33, 0x44}) log.PanicIf(err) - if bytes.Compare(b.Bytes(), []byte{0x11, 0x22, 0x33, 0x44}) != 0 { + if !bytes.Equal(b.Bytes(), []byte{0x11, 0x22, 0x33, 0x44}) { t.Fatalf("four-bytes not encoded correctly.") } } @@ -114,7 +114,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset1(t *testing.T) { t.Fatalf("offset not bumped correctly (2): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3}) { t.Fatalf("buffer not correct after write (1)") } @@ -127,7 +127,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset1(t *testing.T) { t.Fatalf("offset not bumped correctly (3): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) { t.Fatalf("buffer not correct after write (2)") } } @@ -151,7 +151,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset2(t *testing.T) { t.Fatalf("offset not bumped correctly (2): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3}) { t.Fatalf("buffer not correct after write (1)") } @@ -164,7 +164,7 @@ func Test_IfdDataAllocator_Allocate_InitialOffset2(t *testing.T) { t.Fatalf("offset not bumped correctly (3): (%d) != (%d)", offset, expected) } else if ida.NextOffset() != offset+uint32(3) { t.Fatalf("position counter not advanced properly") - } else if bytes.Compare(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}) { t.Fatalf("buffer not correct after write (2)") } } @@ -212,7 +212,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_embedded1(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00}) { t.Fatalf("encoded tag-entry bytes not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation was done but not expected") @@ -244,7 +244,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_embedded2(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78}) { t.Fatalf("encoded tag-entry bytes not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation was done but not expected") @@ -276,11 +276,11 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (1)") - } else if bytes.Compare(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34}) { t.Fatalf("encoded tag-entry bytes not correct (1)") } else if ida.NextOffset() != addressableOffset+uint32(5) { t.Fatalf("allocation offset not expected (1)") - } else if bytes.Compare(ida.Bytes(), []byte{0x12, 0x34, 0x56, 0x78, 0x9A}) != 0 { + } else if !bytes.Equal(ida.Bytes(), []byte{0x12, 0x34, 0x56, 0x78, 0x9A}) { t.Fatalf("allocated data not correct (1)") } @@ -293,17 +293,17 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (2)") - } else if bytes.Compare(b.Bytes(), []byte{ + } else if !bytes.Equal(b.Bytes(), []byte{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34, // Tag 1 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x39, // Tag 2 - }) != 0 { + }) { t.Fatalf("encoded tag-entry bytes not correct (2)") } else if ida.NextOffset() != addressableOffset+uint32(10) { t.Fatalf("allocation offset not expected (2)") - } else if bytes.Compare(ida.Bytes(), []byte{ + } else if !bytes.Equal(ida.Bytes(), []byte{ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xbc, 0xde, 0xf0, 0x12, 0x34, - }) != 0 { + }) { t.Fatalf("allocated data not correct (2)") } } @@ -333,7 +333,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_childIfd__withoutAllocate(t *testing.T if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated") - } else if bytes.Compare(b.Bytes(), []byte{0x87, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) != 0 { + } else if !bytes.Equal(b.Bytes(), []byte{0x87, 0x69, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}) { t.Fatalf("encoded tag-entry with child-IFD not correct") } else if ida.NextOffset() != addressableOffset { t.Fatalf("allocation offset not expected") @@ -536,7 +536,7 @@ func Test_IfdByteEncoder_encodeTagToBytes_simpleTag_allocate(t *testing.T) { allocatedBytes := ida.Bytes() - if bytes.Compare(allocatedBytes, expectedBytes) != 0 { + if !bytes.Equal(allocatedBytes, expectedBytes) { t.Fatalf("Allocated bytes not correct: %v != %v", allocatedBytes, expectedBytes) } } @@ -596,7 +596,7 @@ func Test_IfdByteEncoder_encodeIfdToBytes_simple(t *testing.T) { 0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, } - if bytes.Compare(tableAndAllocated, expectedIfdAndDataBytes) != 0 { + if !bytes.Equal(tableAndAllocated, expectedIfdAndDataBytes) { t.Fatalf("IFD table and allocated data not correct: %v", exifcommon.DumpBytesClauseToString(tableAndAllocated)) } } diff --git a/v3/ifd_builder_test.go b/v3/ifd_builder_test.go index 5a85f43..b86779f 100644 --- a/v3/ifd_builder_test.go +++ b/v3/ifd_builder_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/undefined" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" + exifundefined "github.com/dsoprea/go-exif/v3/undefined" + log "github.com/dsoprea/go-logging" ) func TestIfdBuilder_Add(t *testing.T) { @@ -81,25 +81,25 @@ func TestIfdBuilder_Add(t *testing.T) { if tags[0].tagId != 0x11 { t.Fatalf("tag (0) tag-ID not correct") - } else if bytes.Compare(tags[0].value.Bytes(), []byte("test string")) != 0 { + } else if !bytes.Equal(tags[0].value.Bytes(), []byte("test string")) { t.Fatalf("tag (0) value not correct") } if tags[1].tagId != 0x22 { t.Fatalf("tag (1) tag-ID not correct") - } else if bytes.Compare(tags[1].value.Bytes(), []byte("test string2")) != 0 { + } else if !bytes.Equal(tags[1].value.Bytes(), []byte("test string2")) { t.Fatalf("tag (1) value not correct") } if tags[2].tagId != 0x33 { t.Fatalf("tag (2) tag-ID not correct") - } else if bytes.Compare(tags[2].value.Bytes(), []byte("test string3")) != 0 { + } else if !bytes.Equal(tags[2].value.Bytes(), []byte("test string3")) { t.Fatalf("tag (2) value not correct") } if tags[3].tagId != 0x44 { t.Fatalf("tag (3) tag-ID not correct") - } else if bytes.Compare(tags[3].value.Bytes(), originalBytes) != 0 { + } else if !bytes.Equal(tags[3].value.Bytes(), originalBytes) { t.Fatalf("tag (3) value not correct") } } @@ -455,12 +455,12 @@ func TestIfdBuilder_FindN__First_2_2Returned(t *testing.T) { tags := ib.Tags() bt = tags[found[0]] - if bt.tagId != 0x11 || bytes.Compare(bt.value.Bytes(), []byte("test string")) != 0 { + if bt.tagId != 0x11 || !bytes.Equal(bt.value.Bytes(), []byte("test string")) { log.Panicf("Found entry 0 is not correct: (0x%04x) [%s]", bt.tagId, bt.value) } bt = tags[found[1]] - if bt.tagId != 0x11 || bytes.Compare(bt.value.Bytes(), []byte("test string4")) != 0 { + if bt.tagId != 0x11 || !bytes.Equal(bt.value.Bytes(), []byte("test string4")) { log.Panicf("Found entry 1 is not correct: (0x%04x) [%s]", bt.tagId, bt.value) } } @@ -740,7 +740,7 @@ func TestIfdBuilder_Find__Miss(t *testing.T) { _, err = ib.Find(0x99) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -787,7 +787,7 @@ func TestIfdBuilder_Replace(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-replace tags are not correct.") } @@ -806,7 +806,7 @@ func TestIfdBuilder_Replace(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) { t.Fatalf("Post-replace tags are not correct.") } } @@ -853,7 +853,7 @@ func TestIfdBuilder_ReplaceN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-replace tags are not correct.") } @@ -872,7 +872,7 @@ func TestIfdBuilder_ReplaceN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) { t.Fatalf("Post-replace tags are not correct.") } } @@ -933,7 +933,7 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -949,7 +949,7 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Post-delete (1) tags not correct.") } @@ -965,14 +965,14 @@ func TestIfdBuilder_DeleteFirst(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete (2) tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1033,7 +1033,7 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1049,7 +1049,7 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) { t.Fatalf("Post-delete (1) tags not correct.") } @@ -1065,14 +1065,14 @@ func TestIfdBuilder_DeleteN(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete (2) tags not correct.") } err = ib.DeleteN(0x22, 1) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1133,7 +1133,7 @@ func TestIfdBuilder_DeleteN_Two(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1149,14 +1149,14 @@ func TestIfdBuilder_DeleteN_Two(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1217,7 +1217,7 @@ func TestIfdBuilder_DeleteAll(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) { t.Fatalf("Pre-delete tags not correct.") } @@ -1235,14 +1235,14 @@ func TestIfdBuilder_DeleteAll(t *testing.T) { currentIds[i] = bt.tagId } - if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false { + if !reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) { t.Fatalf("Post-delete tags not correct.") } err = ib.DeleteFirst(0x22) if err == nil { t.Fatalf("Expected an error.") - } else if log.Is(err, ErrTagEntryNotFound) == false { + } else if !log.Is(err, ErrTagEntryNotFound) { log.Panic(err) } } @@ -1339,7 +1339,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain(t *testing.T) { "TAG", } - if reflect.DeepEqual(actual, expected) == false { + if !reflect.DeepEqual(actual, expected) { fmt.Printf("ACTUAL:\n%s\n\nEXPECTED:\n%s\n", strings.Join(actual, "\n"), strings.Join(expected, "\n")) t.Fatalf("IB did not [correctly] duplicate the IFD structure.") } @@ -1610,7 +1610,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { // Check the thumbnail. - if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 { + if !bytes.Equal(recoveredThumbnailData, originalThumbnailData) { t.Fatalf("recovered thumbnail does not match original") } @@ -1660,7 +1660,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { for _, ite := range originalTags { // Adds a lot of noise if/when debugging, and we're already checking the // thumbnail bytes separately. - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() == true { + if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { continue } @@ -1684,7 +1684,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { for _, ite := range recoveredTags { // Adds a lot of noise if/when debugging, and we're already checking the // thumbnail bytes separately. - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() == true { + if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { continue } @@ -1784,7 +1784,7 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { // // Check the thumbnail. -// if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 { +// if !bytes.Equal(recoveredThumbnailData, originalThumbnailData) { // t.Fatalf("recovered thumbnail does not match original") // } @@ -1857,10 +1857,10 @@ func TestIfdBuilder_NewIfdBuilderFromExistingChain_RealData(t *testing.T) { // expectedValueBytes = append(expectedValueBytes, []byte{'A', 'S', 'C', 'I', 'I', 0, 0, 0}...) // expectedValueBytes = append(expectedValueBytes, []byte("TEST COMMENT")...) -// if bytes.Compare(recoveredValueBytes, expectedValueBytes) != 0 { +// if !bytes.Equal(recoveredValueBytes, expectedValueBytes) { // t.Fatalf("Recovered UserComment does not have the right value: %v != %v", recoveredValueBytes, expectedValueBytes) // } -// } else if bytes.Compare(recoveredValueBytes, originalValueBytes) != 0 { +// } else if !bytes.Equal(recoveredValueBytes, originalValueBytes) { // t.Fatalf("bytes of tag content not correct: %v != %v ITE=%s", recoveredValueBytes, originalValueBytes, recoveredIte) // } // } @@ -2069,7 +2069,7 @@ func TestNewStandardBuilderTag__OneUnit(t *testing.T) { t.Fatalf("II in BuilderTag not correct") } else if bt.tagId != 0x8833 { t.Fatalf("tag-ID not correct") - } else if bytes.Compare(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) != 0 { + } else if !bytes.Equal(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) { t.Fatalf("value not correct") } } @@ -2086,9 +2086,9 @@ func TestNewStandardBuilderTag__TwoUnits(t *testing.T) { t.Fatalf("II in BuilderTag not correct") } else if bt.tagId != 0x8833 { t.Fatalf("tag-ID not correct") - } else if bytes.Compare(bt.value.Bytes(), []byte{ + } else if !bytes.Equal(bt.value.Bytes(), []byte{ 0x0, 0x0, 0x12, 0x34, - 0x0, 0x0, 0x56, 0x78}) != 0 { + 0x0, 0x0, 0x56, 0x78}) { t.Fatalf("value not correct") } } diff --git a/v3/ifd_enumerate.go b/v3/ifd_enumerate.go index 3167596..644f3e0 100644 --- a/v3/ifd_enumerate.go +++ b/v3/ifd_enumerate.go @@ -2,6 +2,7 @@ package exif import ( "bytes" + "context" "errors" "fmt" "io" @@ -11,10 +12,10 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "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 ( @@ -77,7 +78,6 @@ var ( type byteParser struct { byteOrder binary.ByteOrder rs io.ReadSeeker - ifdOffset uint32 currentOffset uint32 } @@ -231,11 +231,11 @@ func (ie *IfdEnumerate) parseTag(ii *exifcommon.IfdIdentity, tagPosition int, bp // Check whether the embedded type indicator is valid. - if tagType.IsValid() == false { + if !tagType.IsValid() { // Technically, we have the type on-file in the tags-index, but // if the type stored alongside the data disagrees with it, // which it apparently does, all bets are off. - ifdEnumerateLogger.Warningf(nil, + ifdEnumerateLogger.Warningf(context.TODO(), "Tag (0x%04x) in IFD [%s] at position (%d) has invalid type (0x%04x) and will be skipped.", tagId, ii, tagPosition, int(tagType)) @@ -252,8 +252,8 @@ func (ie *IfdEnumerate) parseTag(ii *exifcommon.IfdIdentity, tagPosition int, bp it, err := ie.tagIndex.Get(ii, tagId) if err != nil { - if log.Is(err, ErrTagNotFound) == true { - ifdEnumerateLogger.Warningf(nil, "Tag (0x%04x) is not known and will be skipped.", tagId) + if log.Is(err, ErrTagNotFound) { + ifdEnumerateLogger.Warningf(context.TODO(), "Tag (0x%04x) is not known and will be skipped.", tagId) ite = &IfdTagEntry{ tagId: tagId, @@ -268,13 +268,13 @@ func (ie *IfdEnumerate) parseTag(ii *exifcommon.IfdIdentity, tagPosition int, bp // If we're trying to be as forgiving as possible then use whatever type was // reported in the format. Otherwise, only accept a type that's expected for // this tag. - if ie.tagIndex.UniversalSearch() == false && it.DoesSupportType(tagType) == false { + if !ie.tagIndex.UniversalSearch() && !it.DoesSupportType(tagType) { // The type in the stream disagrees with the type that this tag is // expected to have. This can present issues with how we handle the // special-case tags (e.g. thumbnails, GPS, etc..) when those tags // suddenly have data that we no longer manipulate correctly/ // accurately. - ifdEnumerateLogger.Warningf(nil, + ifdEnumerateLogger.Warningf(context.TODO(), "Tag (0x%04x) in IFD [%s] at position (%d) has unsupported type (0x%02x) and will be skipped.", tagId, ii, tagPosition, int(tagType)) @@ -312,7 +312,7 @@ func (ie *IfdEnumerate) parseTag(ii *exifcommon.IfdIdentity, tagPosition int, bp // We also need to set `tag.ChildFqIfdPath` but can't do it here // because we don't have the IFD index. - } else if log.Is(err, exifcommon.ErrChildIfdNotMapped) == false { + } else if !log.Is(err, exifcommon.ErrChildIfdNotMapped) { log.Panic(err) } @@ -357,7 +357,7 @@ func (ie *IfdEnumerate) tagPostParse(ite *IfdTagEntry, med *MiscellaneousExifDat med.unknownTags[originalBt] = exifcommon.BasicTag{} } - utilityLogger.Debugf(nil, + utilityLogger.Debugf(context.TODO(), "Tag (0x%04x) is not valid for IFD [%s]. Attempting secondary "+ "lookup.", tagId, ii.String()) @@ -376,7 +376,7 @@ func (ie *IfdEnumerate) tagPostParse(ite *IfdTagEntry, med *MiscellaneousExifDat // they want to specifically manage these types of tags, they // can use more advanced functionality to specifically -handle // unknown tags. - utilityLogger.Warningf(nil, + utilityLogger.Warningf(context.TODO(), "Tag with ID (0x%04x) in IFD [%s] is not recognized and "+ "will be ignored.", tagId, ii.String()) @@ -385,7 +385,7 @@ func (ie *IfdEnumerate) tagPostParse(ite *IfdTagEntry, med *MiscellaneousExifDat ite.setTagName(it.Name) - utilityLogger.Warningf(nil, + utilityLogger.Warningf(context.TODO(), "Tag with ID (0x%04x) is not valid for IFD [%s], but it *is* "+ "valid as tag [%s] under IFD [%s] and has the same type "+ "[%s], so we will use that. This EXIF blob was probably "+ @@ -412,8 +412,8 @@ func (ie *IfdEnumerate) tagPostParse(ite *IfdTagEntry, med *MiscellaneousExifDat // tag should ever be repeated, and b) all but one had an incorrect // type and caused parsing/conversion woes. So, this is a quick fix // for those scenarios. - if ie.tagIndex.UniversalSearch() == false && it.DoesSupportType(tagType) == false { - ifdEnumerateLogger.Warningf(nil, + if !ie.tagIndex.UniversalSearch() && !it.DoesSupportType(tagType) { + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping tag [%s] (0x%04x) [%s] with an unexpected type: %v ∉ %v", ii.UnindexedString(), tagId, it.Name, tagType, it.SupportedTypes) @@ -436,7 +436,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis tagCount, _, err := bp.getUint16() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "IFD [%s] tag-count: (%d)", ii.String(), tagCount) + ifdEnumerateLogger.Debugf(context.TODO(), "IFD [%s] tag-count: (%d)", ii.String(), tagCount) entries = make([]*IfdTagEntry, 0) @@ -446,7 +446,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis for i := 0; i < int(tagCount); i++ { ite, err := ie.parseTag(ii, i, bp) if err != nil { - if log.Is(err, ErrTagNotFound) == true || log.Is(err, ErrTagTypeNotValid) == true { + if log.Is(err, ErrTagNotFound) || log.Is(err, ErrTagTypeNotValid) { // These tags should've been fully logged in parseTag(). The // ITE returned is nil so we can't print anything about them, now. continue @@ -471,15 +471,15 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis log.PanicIf(err) } - if ite.IsThumbnailOffset() == true { - ifdEnumerateLogger.Debugf(nil, "Skipping the thumbnail offset tag (0x%04x). Use accessors to get it or set it.", tagId) + if ite.IsThumbnailOffset() { + ifdEnumerateLogger.Debugf(context.TODO(), "Skipping the thumbnail offset tag (0x%04x). Use accessors to get it or set it.", tagId) enumeratorThumbnailOffset = ite entries = append(entries, ite) continue - } else if ite.IsThumbnailSize() == true { - ifdEnumerateLogger.Debugf(nil, "Skipping the thumbnail size tag (0x%04x). Use accessors to get it or set it.", tagId) + } else if ite.IsThumbnailSize() { + ifdEnumerateLogger.Debugf(context.TODO(), "Skipping the thumbnail size tag (0x%04x). Use accessors to get it or set it.", tagId) enumeratorThumbnailSize = ite entries = append(entries, ite) @@ -508,8 +508,8 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis // (the standard IFD tag type), later, unless we skip it because it's // [likely] not even in the standard list of known tags. if ite.ChildIfdPath() != "" { - if doDescend == true { - ifdEnumerateLogger.Debugf(nil, "Descending from IFD [%s] to IFD [%s].", ii, ite.ChildIfdPath()) + if doDescend { + ifdEnumerateLogger.Debugf(context.TODO(), "Descending from IFD [%s] to IFD [%s].", ii, ite.ChildIfdPath()) currentIfdTag := ii.IfdTag() @@ -524,7 +524,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis err := ie.scan(iiChild, ite.getValueOffset(), visitor, med) log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Ascending from IFD [%s] to IFD [%s].", ite.ChildIfdPath(), ii) + ifdEnumerateLogger.Debugf(context.TODO(), "Ascending from IFD [%s] to IFD [%s].", ite.ChildIfdPath(), ii) } } @@ -535,7 +535,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis thumbnailData, err = ie.parseThumbnail(enumeratorThumbnailOffset, enumeratorThumbnailSize) if err != nil { ifdEnumerateLogger.Errorf( - nil, err, + context.TODO(), err, "We tried to bump our furthest-offset counter but there was an issue first seeking past the thumbnail.") } else { // In this case, the value is always an offset. @@ -544,7 +544,7 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis // This this case, the value is always a length. length := enumeratorThumbnailSize.getValueOffset() - ifdEnumerateLogger.Debugf(nil, "Found thumbnail in IFD [%s]. Its offset is (%d) and is (%d) bytes.", ii, offset, length) + ifdEnumerateLogger.Debugf(context.TODO(), "Found thumbnail in IFD [%s]. Its offset is (%d) and is (%d) bytes.", ii, offset, length) furthestOffset := offset + length @@ -559,16 +559,16 @@ func (ie *IfdEnumerate) parseIfd(ii *exifcommon.IfdIdentity, bp *byteParser, vis _, alreadyVisited := ie.visitedIfdOffsets[nextIfdOffset] - if alreadyVisited == true { - ifdEnumerateLogger.Warningf(nil, "IFD at offset (0x%08x) has been linked-to more than once. There might be a cycle in the IFD chain. Not reparsing.", nextIfdOffset) + if alreadyVisited { + ifdEnumerateLogger.Warningf(context.TODO(), "IFD at offset (0x%08x) has been linked-to more than once. There might be a cycle in the IFD chain. Not reparsing.", nextIfdOffset) nextIfdOffset = 0 } if nextIfdOffset != 0 { ie.visitedIfdOffsets[nextIfdOffset] = struct{}{} - ifdEnumerateLogger.Debugf(nil, "[%s] Next IFD at offset: (0x%08x)", ii.String(), nextIfdOffset) + ifdEnumerateLogger.Debugf(context.TODO(), "[%s] Next IFD at offset: (0x%08x)", ii.String(), nextIfdOffset) } else { - ifdEnumerateLogger.Debugf(nil, "[%s] IFD chain has terminated.", ii.String()) + ifdEnumerateLogger.Debugf(context.TODO(), "[%s] IFD chain has terminated.", ii.String()) } return nextIfdOffset, entries, thumbnailData, nil @@ -615,12 +615,12 @@ func (ie *IfdEnumerate) scan(iiGeneral *exifcommon.IfdIdentity, ifdOffset uint32 for ifdIndex := 0; ; ifdIndex++ { iiSibling := iiGeneral.NewSibling(ifdIndex) - ifdEnumerateLogger.Debugf(nil, "Parsing IFD [%s] at offset (0x%04x) (scan).", iiSibling.String(), ifdOffset) + ifdEnumerateLogger.Debugf(context.TODO(), "Parsing IFD [%s] at offset (0x%04x) (scan).", iiSibling.String(), ifdOffset) bp, err := ie.getByteParser(ifdOffset) if err != nil { if err == ErrOffsetInvalid { - ifdEnumerateLogger.Errorf(nil, nil, "IFD [%s] at offset (0x%04x) is unreachable. Terminating scan.", iiSibling.String(), ifdOffset) + ifdEnumerateLogger.Errorf(context.TODO(), nil, "IFD [%s] at offset (0x%04x) is unreachable. Terminating scan.", iiSibling.String(), ifdOffset) break } @@ -681,7 +681,7 @@ func (ie *IfdEnumerate) Scan(iiRoot *exifcommon.IfdIdentity, ifdOffset uint32, v err = ie.scan(iiRoot, ifdOffset, visitor, med) log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Scan: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d) (Scan).", ie.FurthestOffset()) + ifdEnumerateLogger.Debugf(context.TODO(), "Scan: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d) (Scan).", ie.FurthestOffset()) return med, nil } @@ -818,7 +818,7 @@ func (ifd *Ifd) FindTagWithId(tagId uint16) (results []*IfdTagEntry, err error) }() results, found := ifd.entriesByTagId[tagId] - if found != true { + if !found { log.Panic(ErrTagNotFound) } @@ -835,7 +835,7 @@ func (ifd *Ifd) FindTagWithName(tagName string) (results []*IfdTagEntry, err err }() it, err := ifd.tagIndex.GetWithName(ifd.ifdIdentity, tagName) - if log.Is(err, ErrTagNotFound) == true { + if log.Is(err, ErrTagNotFound) { log.Panic(ErrTagNotKnown) } else if err != nil { log.Panic(err) @@ -894,7 +894,7 @@ func (ifd *Ifd) dumpTags(tags []*IfdTagEntry) []*IfdTagEntry { ifdsFoundCount++ childIfd, found := ifd.childIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -938,7 +938,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo } else { // This will just add noise to the output (byte-tags are fully // dumped). - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() == true { + if ite.IsThumbnailOffset() || ite.IsThumbnailSize() { continue } @@ -950,16 +950,16 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo } var valuePhrase string - if populateValues == true { + if populateValues { var err error valuePhrase, err = ite.Format() if err != nil { - if log.Is(err, exifcommon.ErrUnhandledUndefinedTypedTag) == true { - ifdEnumerateLogger.Warningf(nil, "Skipping non-standard undefined tag: [%s] (%04x)", ifd.ifdIdentity.UnindexedString(), ite.TagId()) + if log.Is(err, exifcommon.ErrUnhandledUndefinedTypedTag) { + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping non-standard undefined tag: [%s] (%04x)", ifd.ifdIdentity.UnindexedString(), ite.TagId()) continue } else if err == exifundefined.ErrUnparseableValue { - ifdEnumerateLogger.Warningf(nil, "Skipping unparseable undefined tag: [%s] (%04x) [%s]", ifd.ifdIdentity.UnindexedString(), ite.TagId(), it.Name) + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping unparseable undefined tag: [%s] (%04x) [%s]", ifd.ifdIdentity.UnindexedString(), ite.TagId(), it.Name) continue } @@ -977,7 +977,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo ifdsFoundCount++ childIfd, found := ifd.childIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -1019,7 +1019,7 @@ func (ifd *Ifd) printIfdTree(level int, nextLink bool) { ifdsFoundCount++ childIfd, found := ifd.childIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -1067,7 +1067,7 @@ func (ifd *Ifd) dumpTree(tagsDump []string, level int) []string { ifdsFoundCount++ childIfd, found := ifd.childIfdIndex[childIfdPath] - if found != true { + if !found { log.Panicf("alien child IFD referenced by a tag: [%s]", childIfdPath) } @@ -1108,35 +1108,35 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { gi = new(GpsInfo) - if ifd.ifdIdentity.Equals(exifcommon.IfdGpsInfoStandardIfdIdentity) == false { + if !ifd.ifdIdentity.Equals(exifcommon.IfdGpsInfoStandardIfdIdentity) { log.Panicf("GPS can only be read on GPS IFD: [%s]", ifd.ifdIdentity.UnindexedString()) } - if tags, found := ifd.entriesByTagId[TagGpsVersionId]; found == false { + if tags, found := ifd.entriesByTagId[TagGpsVersionId]; !found { // We've seen this. We'll just have to default to assuming we're in a // 2.2.0.0 format. - ifdEnumerateLogger.Warningf(nil, "No GPS version tag (0x%04x) found.", TagGpsVersionId) + ifdEnumerateLogger.Warningf(context.TODO(), "No GPS version tag (0x%04x) found.", TagGpsVersionId) } else { versionBytes, err := tags[0].GetRawBytes() log.PanicIf(err) hit := false for _, acceptedGpsVersion := range ValidGpsVersions { - if bytes.Compare(versionBytes, acceptedGpsVersion[:]) == 0 { + if bytes.Equal(versionBytes, acceptedGpsVersion[:]) { hit = true break } } - if hit != true { - ifdEnumerateLogger.Warningf(nil, "GPS version not supported: %v", versionBytes) + if !hit { + ifdEnumerateLogger.Warningf(context.TODO(), "GPS version not supported: %v", versionBytes) log.Panic(ErrNoGpsTags) } } tags, found := ifd.entriesByTagId[TagLatitudeId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "latitude not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "latitude not found") log.Panic(ErrNoGpsTags) } @@ -1145,8 +1145,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { // Look for whether North or South. tags, found = ifd.entriesByTagId[TagLatitudeRefId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "latitude-ref not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "latitude-ref not found") log.Panic(ErrNoGpsTags) } @@ -1154,8 +1154,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { log.PanicIf(err) tags, found = ifd.entriesByTagId[TagLongitudeId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "longitude not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "longitude not found") log.Panic(ErrNoGpsTags) } @@ -1164,8 +1164,8 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { // Look for whether West or East. tags, found = ifd.entriesByTagId[TagLongitudeRefId] - if found == false { - ifdEnumerateLogger.Warningf(nil, "longitude-ref not found") + if !found { + ifdEnumerateLogger.Warningf(context.TODO(), "longitude-ref not found") log.Panic(ErrNoGpsTags) } @@ -1189,11 +1189,11 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { altitudeTags, foundAltitude := ifd.entriesByTagId[TagAltitudeId] altitudeRefTags, foundAltitudeRef := ifd.entriesByTagId[TagAltitudeRefId] - if foundAltitude == true && foundAltitudeRef == true { + if foundAltitude && foundAltitudeRef { altitudePhrase, err := altitudeTags[0].Format() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Altitude is [%s].", altitudePhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Altitude is [%s].", altitudePhrase) altitudeValue, err := altitudeTags[0].Value() log.PanicIf(err) @@ -1201,7 +1201,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { altitudeRefPhrase, err := altitudeRefTags[0].Format() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Altitude-reference is [%s].", altitudeRefPhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Altitude-reference is [%s].", altitudeRefPhrase) altitudeRefValue, err := altitudeRefTags[0].Value() log.PanicIf(err) @@ -1223,12 +1223,12 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { timestampTags, foundTimestamp := ifd.entriesByTagId[TagTimestampId] datestampTags, foundDatestamp := ifd.entriesByTagId[TagDatestampId] - if foundTimestamp == true && foundDatestamp == true { + if foundTimestamp && foundDatestamp { datestampValue, err := datestampTags[0].Value() log.PanicIf(err) datePhrase := datestampValue.(string) - ifdEnumerateLogger.Debugf(nil, "Date tag value is [%s].", datePhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Date tag value is [%s].", datePhrase) // Normalize the separators. datePhrase = strings.ReplaceAll(datePhrase, "-", ":") @@ -1246,7 +1246,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { timePhrase, err := timestampTags[0].Format() log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Time tag value is [%s].", timePhrase) + ifdEnumerateLogger.Debugf(context.TODO(), "Time tag value is [%s].", timePhrase) timestampRaw := timestampValue.([]exifcommon.Rational) @@ -1351,7 +1351,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error queue = queue[1:] - ifdEnumerateLogger.Debugf(nil, "Parsing IFD [%s] (%d) at offset (0x%04x) (Collect).", ii.String(), ii.Index(), offset) + ifdEnumerateLogger.Debugf(context.TODO(), "Parsing IFD [%s] (%d) at offset (0x%04x) (Collect).", ii.String(), ii.Index(), offset) bp, err := ie.getByteParser(offset) if err != nil { @@ -1379,7 +1379,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error tagId := ite.TagId() tags, found := entriesByTagId[tagId] - if found == false { + if !found { tags = make([]*IfdTagEntry, 0) } @@ -1420,7 +1420,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error lookup[ii.String()] = ifd // Add a link from the previous IFD in the chain to us. - if previousIfd, found := edges[offset]; found == true { + if previousIfd, found := edges[offset]; found { previousIfd.nextIfd = ifd } @@ -1484,7 +1484,7 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error err = ie.setChildrenIndex(index.RootIfd) log.PanicIf(err) - ifdEnumerateLogger.Debugf(nil, "Collect: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d).", ie.FurthestOffset()) + ifdEnumerateLogger.Debugf(context.TODO(), "Collect: It looks like the furthest offset that contained EXIF data in the EXIF blob was (%d).", ie.FurthestOffset()) return index, nil } diff --git a/v3/ifd_enumerate_test.go b/v3/ifd_enumerate_test.go index 5d44036..16a6c1c 100644 --- a/v3/ifd_enumerate_test.go +++ b/v3/ifd_enumerate_test.go @@ -55,7 +55,7 @@ func TestIfdTagEntry_RawBytes_RealData(t *testing.T) { if len(decodedBytes) != int(ite.UnitCount()) { t.Fatalf("Decoded bytes not the right count.") - } else if bytes.Compare(decodedBytes, expected) != 0 { + } else if !bytes.Equal(decodedBytes, expected) { t.Fatalf("Decoded bytes not correct.") } } @@ -103,7 +103,7 @@ func TestIfd_FindTagWithId_Miss(t *testing.T) { _, err = ifd.FindTagWithId(0xffff) if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotFound) == false { + } else if !log.Is(err, ErrTagNotFound) { log.Panic(err) } } @@ -153,7 +153,7 @@ func TestIfd_FindTagWithName_Miss(t *testing.T) { _, err = ifd.FindTagWithName("PlanarConfiguration") if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotFound) == false { + } else if !log.Is(err, ErrTagNotFound) { log.Panic(err) } } @@ -177,7 +177,7 @@ func TestIfd_FindTagWithName_NonStandard(t *testing.T) { _, err = ifd.FindTagWithName("GeorgeNotAtHome") if err == nil { t.Fatalf("Expected error for not-found tag.") - } else if log.Is(err, ErrTagNotKnown) == false { + } else if !log.Is(err, ErrTagNotKnown) { log.Panic(err) } } @@ -212,7 +212,7 @@ func TestIfd_Thumbnail(t *testing.T) { expected, err := ioutil.ReadFile(expectedFilepath) log.PanicIf(err) - if bytes.Compare(actual, expected) != 0 { + if !bytes.Equal(actual, expected) { t.Fatalf("thumbnail not correct") } } diff --git a/v3/ifd_tag_entry.go b/v3/ifd_tag_entry.go index ed6ba22..39f58fc 100644 --- a/v3/ifd_tag_entry.go +++ b/v3/ifd_tag_entry.go @@ -6,14 +6,10 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/undefined" -) - -var ( - iteLogger = log.NewLogger("exif.ifd_tag_entry") + exifcommon "github.com/dsoprea/go-exif/v3/common" + exifundefined "github.com/dsoprea/go-exif/v3/undefined" ) // IfdTagEntry refers to a tag in the loaded EXIF block. diff --git a/v3/ifd_tag_entry_test.go b/v3/ifd_tag_entry_test.go index 458be10..107f0b0 100644 --- a/v3/ifd_tag_entry_test.go +++ b/v3/ifd_tag_entry_test.go @@ -30,7 +30,7 @@ func TestIfdTagEntry_RawBytes_Allocated(t *testing.T) { value, err := ite.GetRawBytes() log.PanicIf(err) - if bytes.Compare(value, data) != 0 { + if !bytes.Equal(value, data) { t.Fatalf("Value not expected: [%s] != [%s]", value, data) } } @@ -61,7 +61,7 @@ func TestIfdTagEntry_RawBytes_Embedded(t *testing.T) { value, err := ite.GetRawBytes() log.PanicIf(err) - if bytes.Compare(value, data) != 0 { + if !bytes.Equal(value, data) { t.Fatalf("Value not expected: %v != %v", value, data) } } diff --git a/v3/tags.go b/v3/tags.go index aca902c..7afac1f 100644 --- a/v3/tags.go +++ b/v3/tags.go @@ -1,13 +1,14 @@ package exif import ( + "context" "fmt" "sync" - "github.com/dsoprea/go-logging" - "gopkg.in/yaml.v2" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" + "gopkg.in/yaml.v2" ) const ( @@ -115,7 +116,7 @@ func (it *IndexedTag) Is(ifdPath string, id uint16) bool { // GetEncodingType returns the largest type that this tag's value can occupy. func (it *IndexedTag) GetEncodingType(value interface{}) exifcommon.TagTypePrimitive { // For convenience, we handle encoding a `time.Time` directly. - if exifcommon.IsTime(value) == true { + if exifcommon.IsTime(value) { // Timestamps are encoded as ASCII. value = "" } @@ -144,14 +145,14 @@ func (it *IndexedTag) GetEncodingType(value interface{}) exifcommon.TagTypePrimi // We specifically check for the cases that we know to expect. - if supportsLong == true && supportsShort == true { + if supportsLong && supportsShort { return exifcommon.TypeLong - } else if supportsRational == true && supportsSignedRational == true { + } else if supportsRational && supportsSignedRational { if value == nil { log.Panicf("GetEncodingType: require value to be given") } - if _, ok := value.(exifcommon.SignedRational); ok == true { + if _, ok := value.(exifcommon.SignedRational); ok { return exifcommon.TypeSignedRational } @@ -218,12 +219,12 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) { // Store by ID. family, found := ti.tagsByIfd[it.IfdPath] - if found == false { + if !found { family = make(map[uint16]*IndexedTag) ti.tagsByIfd[it.IfdPath] = family } - if _, found := family[it.Id]; found == true { + if _, found := family[it.Id]; found { log.Panicf("tag-ID defined more than once for IFD [%s]: (%02x)", it.IfdPath, it.Id) } @@ -232,12 +233,12 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) { // Store by name. familyR, found := ti.tagsByIfdR[it.IfdPath] - if found == false { + if !found { familyR = make(map[string]*IndexedTag) ti.tagsByIfdR[it.IfdPath] = familyR } - if _, found := familyR[it.Name]; found == true { + if _, found := familyR[it.Name]; found { log.Panicf("tag-name defined more than once for IFD [%s]: (%s)", it.IfdPath, it.Name) } @@ -262,12 +263,12 @@ func (ti *TagIndex) getOne(ifdPath string, id uint16) (it *IndexedTag, err error defer ti.mutex.Unlock() family, found := ti.tagsByIfd[ifdPath] - if found == false { + if !found { return nil, ErrTagNotFound } it, found = family[id] - if found == false { + if !found { return nil, ErrTagNotFound } @@ -292,7 +293,7 @@ func (ti *TagIndex) Get(ii *exifcommon.IfdIdentity, id uint16) (it *IndexedTag, log.Panic(err) } - if ti.doUniversalSearch == false { + if !ti.doUniversalSearch { return nil, ErrTagNotFound } @@ -300,7 +301,7 @@ func (ti *TagIndex) Get(ii *exifcommon.IfdIdentity, id uint16) (it *IndexedTag, skipIfdPath := ii.UnindexedString() - for currentIfdPath, _ := range ti.tagsByIfd { + for currentIfdPath := range ti.tagsByIfd { if currentIfdPath == skipIfdPath { // Skip the primary IFD, which has already been checked. continue @@ -308,7 +309,7 @@ func (ti *TagIndex) Get(ii *exifcommon.IfdIdentity, id uint16) (it *IndexedTag, it, err = ti.getOne(currentIfdPath, id) if err == nil { - tagsLogger.Warningf(nil, + tagsLogger.Warningf(context.TODO(), "Found tag (0x%02x) in the wrong IFD: [%s] != [%s]", id, currentIfdPath, ifdPath) @@ -392,7 +393,7 @@ func (ti *TagIndex) GetWithName(ii *exifcommon.IfdIdentity, name string) (it *In ifdPath := ii.UnindexedString() it, found := ti.tagsByIfdR[ifdPath][name] - if found != true { + if !found { log.Panic(ErrTagNotFound) } @@ -442,8 +443,8 @@ func LoadStandardTags(ti *TagIndex) (err error) { // TODO(dustin): Discard unsupported types. This helps us with non-standard types that have actually been found in real data, that we ignore for right now. e.g. SSHORT, FLOAT, DOUBLE tagTypeId, found := exifcommon.GetTypeByName(tagTypeName) - if found == false { - tagsLogger.Warningf(nil, "Type [%s] for tag [%s] being loaded is not valid and is being ignored.", tagTypeName, tagName) + if !found { + tagsLogger.Warningf(context.TODO(), "Type [%s] for tag [%s] being loaded is not valid and is being ignored.", tagTypeName, tagName) continue } @@ -451,7 +452,7 @@ func LoadStandardTags(ti *TagIndex) (err error) { } if len(tagTypes) == 0 { - tagsLogger.Warningf(nil, "Tag [%s] (0x%04x) [%s] being loaded does not have any supported types and will not be registered.", ifdPath, tagId, tagName) + tagsLogger.Warningf(context.TODO(), "Tag [%s] (0x%04x) [%s] being loaded does not have any supported types and will not be registered.", ifdPath, tagId, tagName) continue } @@ -469,7 +470,7 @@ func LoadStandardTags(ti *TagIndex) (err error) { } } - tagsLogger.Debugf(nil, "(%d) tags loaded.", count) + tagsLogger.Debugf(context.TODO(), "(%d) tags loaded.", count) return nil } diff --git a/v3/tags_test.go b/v3/tags_test.go index 2f6f1c4..0e3ae6f 100644 --- a/v3/tags_test.go +++ b/v3/tags_test.go @@ -261,7 +261,7 @@ func TestTagIndex_Get(t *testing.T) { it, err := ti.Get(exifcommon.IfdStandardIfdIdentity, 0x10f) log.PanicIf(err) - if it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) == false || it.IsName(exifcommon.IfdStandardIfdIdentity.UnindexedString(), "Make") == false { + if !it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) || !it.IsName(exifcommon.IfdStandardIfdIdentity.UnindexedString(), "Make") { t.Fatalf("tag info not correct") } } @@ -272,7 +272,7 @@ func TestTagIndex_GetWithName(t *testing.T) { it, err := ti.GetWithName(exifcommon.IfdStandardIfdIdentity, "Make") log.PanicIf(err) - if it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) == false { + if !it.Is(exifcommon.IfdStandardIfdIdentity.UnindexedString(), 0x10f) { t.Fatalf("tag info not correct") } } diff --git a/v3/testing_common.go b/v3/testing_common.go index 0612764..40e2c47 100644 --- a/v3/testing_common.go +++ b/v3/testing_common.go @@ -7,9 +7,9 @@ import ( "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" ) var ( @@ -149,7 +149,7 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) { value, err := ite.Value() log.PanicIf(err) - if reflect.DeepEqual(value, expected[i].value) != true { + if !reflect.DeepEqual(value, expected[i].value) { t.Fatalf("Value for entry (%d) not correct: [%v] != [%v]", i, value, expected[i].value) } } diff --git a/v3/undefined/accessor.go b/v3/undefined/accessor.go index 11a21e1..4bf3f39 100644 --- a/v3/undefined/accessor.go +++ b/v3/undefined/accessor.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) // Encode encodes the given encodeable undefined value to bytes. @@ -19,7 +19,7 @@ func Encode(value EncodeableValue, byteOrder binary.ByteOrder) (encoded []byte, encoderName := value.EncoderName() encoder, found := encoders[encoderName] - if found == false { + if !found { log.Panicf("no encoder registered for type [%s]", encoderName) } @@ -43,7 +43,7 @@ func Decode(valueContext *exifcommon.ValueContext) (value EncodeableValue, err e } decoder, found := decoders[uth] - if found == false { + if !found { // We have no choice but to return the error. We have no way of knowing how // much data there is without already knowing what data-type this tag is. return nil, exifcommon.ErrUnhandledUndefinedTypedTag diff --git a/v3/undefined/exif_8828_oecf.go b/v3/undefined/exif_8828_oecf.go index 26f3675..0c71896 100644 --- a/v3/undefined/exif_8828_oecf.go +++ b/v3/undefined/exif_8828_oecf.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type Tag8828Oecf struct { @@ -39,7 +39,7 @@ func (Codec8828Oecf) Encode(value interface{}, byteOrder binary.ByteOrder) (enco // TODO(dustin): Add test oecf, ok := value.(Tag8828Oecf) - if ok == false { + if !ok { log.Panicf("can only encode a Tag8828Oecf") } diff --git a/v3/undefined/exif_8828_oecf_test.go b/v3/undefined/exif_8828_oecf_test.go index 8c9af3e..573ebda 100644 --- a/v3/undefined/exif_8828_oecf_test.go +++ b/v3/undefined/exif_8828_oecf_test.go @@ -5,10 +5,10 @@ import ( "reflect" "testing" - "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-utility/v2/filesystem" + log "github.com/dsoprea/go-logging" + rifs "github.com/dsoprea/go-utility/v2/filesystem" - "github.com/dsoprea/go-exif/v3/common" + exifcommon "github.com/dsoprea/go-exif/v3/common" ) func TestTag8828Oecf_String(t *testing.T) { @@ -29,7 +29,7 @@ func TestCodec8828Oecf_Encode(t *testing.T) { Columns: 2, Rows: 22, ColumnNames: []string{"aa", "bb"}, - Values: []exifcommon.SignedRational{{11, 22}}, + Values: []exifcommon.SignedRational{{Numerator: 11, Denominator: 22}}, } codec := Codec8828Oecf{} @@ -81,7 +81,7 @@ func TestCodec8828Oecf_Decode(t *testing.T) { Columns: 2, Rows: 22, ColumnNames: []string{"aa", "bb"}, - Values: []exifcommon.SignedRational{{11, 22}}, + Values: []exifcommon.SignedRational{{Numerator: 11, Denominator: 22}}, } if reflect.DeepEqual(value, expectedValue) != true { diff --git a/v3/undefined/exif_9000_exif_version.go b/v3/undefined/exif_9000_exif_version.go index 8f18c81..bfc4b8f 100644 --- a/v3/undefined/exif_9000_exif_version.go +++ b/v3/undefined/exif_9000_exif_version.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type Tag9000ExifVersion struct { @@ -31,7 +31,7 @@ func (Codec9000ExifVersion) Encode(value interface{}, byteOrder binary.ByteOrder }() s, ok := value.(Tag9000ExifVersion) - if ok == false { + if !ok { log.Panicf("can only encode a Tag9000ExifVersion") } diff --git a/v3/undefined/exif_9101_components_configuration.go b/v3/undefined/exif_9101_components_configuration.go index e357fe0..e340ed4 100644 --- a/v3/undefined/exif_9101_components_configuration.go +++ b/v3/undefined/exif_9101_components_configuration.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) const ( @@ -74,7 +74,7 @@ func (CodecExif9101ComponentsConfiguration) Encode(value interface{}, byteOrder }() cc, ok := value.(TagExif9101ComponentsConfiguration) - if ok == false { + if !ok { log.Panicf("can only encode a TagExif9101ComponentsConfiguration") } @@ -94,7 +94,7 @@ func (CodecExif9101ComponentsConfiguration) Decode(valueContext *exifcommon.Valu log.PanicIf(err) for configurationId, configurationBytes := range TagUndefinedType_9101_ComponentsConfiguration_Configurations { - if bytes.Equal(configurationBytes, valueBytes) == true { + if bytes.Equal(configurationBytes, valueBytes) { cc := TagExif9101ComponentsConfiguration{ ConfigurationId: configurationId, ConfigurationBytes: valueBytes, diff --git a/v3/undefined/exif_927C_maker_note.go b/v3/undefined/exif_927C_maker_note.go index f9cd278..943d85a 100644 --- a/v3/undefined/exif_927C_maker_note.go +++ b/v3/undefined/exif_927C_maker_note.go @@ -7,9 +7,9 @@ import ( "crypto/sha1" "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type Tag927CMakerNote struct { @@ -49,7 +49,7 @@ func (Codec927CMakerNote) Encode(value interface{}, byteOrder binary.ByteOrder) }() mn, ok := value.(Tag927CMakerNote) - if ok == false { + if !ok { log.Panicf("can only encode a Tag927CMakerNote") } diff --git a/v3/undefined/exif_9286_user_comment.go b/v3/undefined/exif_9286_user_comment.go index 320edc1..f34ed6d 100644 --- a/v3/undefined/exif_9286_user_comment.go +++ b/v3/undefined/exif_9286_user_comment.go @@ -2,13 +2,14 @@ package exifundefined import ( "bytes" + "context" "fmt" "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) var ( @@ -74,12 +75,12 @@ func (Codec9286UserComment) Encode(value interface{}, byteOrder binary.ByteOrder }() uc, ok := value.(Tag9286UserComment) - if ok == false { + if !ok { log.Panicf("can only encode a Tag9286UserComment") } encodingTypeBytes, found := TagUndefinedType_9286_UserComment_Encodings[uc.EncodingType] - if found == false { + if !found { log.Panicf("encoding-type not valid for unknown-type tag 9286 (UserComment): (%d)", uc.EncodingType) } @@ -116,7 +117,7 @@ func (Codec9286UserComment) Decode(valueContext *exifcommon.ValueContext) (value encoding := valueBytes[:8] for encodingIndex, encodingBytes := range TagUndefinedType_9286_UserComment_Encodings { - if bytes.Compare(encoding, encodingBytes) == 0 { + if bytes.Equal(encoding, encodingBytes) { uc := Tag9286UserComment{ EncodingType: encodingIndex, EncodingBytes: valueBytes[8:], @@ -126,7 +127,7 @@ func (Codec9286UserComment) Decode(valueContext *exifcommon.ValueContext) (value } } - exif9286Logger.Warningf(nil, "User-comment encoding not valid. Returning 'unknown' type (the default).") + exif9286Logger.Warningf(context.TODO(), "User-comment encoding not valid. Returning 'unknown' type (the default).") return unknownUc, nil } diff --git a/v3/undefined/exif_A000_flashpix_version.go b/v3/undefined/exif_A000_flashpix_version.go index 4a0fefa..44cbe00 100644 --- a/v3/undefined/exif_A000_flashpix_version.go +++ b/v3/undefined/exif_A000_flashpix_version.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type TagA000FlashpixVersion struct { @@ -31,7 +31,7 @@ func (CodecA000FlashpixVersion) Encode(value interface{}, byteOrder binary.ByteO }() s, ok := value.(TagA000FlashpixVersion) - if ok == false { + if !ok { log.Panicf("can only encode a TagA000FlashpixVersion") } diff --git a/v3/undefined/exif_A20C_spatial_frequency_response.go b/v3/undefined/exif_A20C_spatial_frequency_response.go index 0311175..0bc813f 100644 --- a/v3/undefined/exif_A20C_spatial_frequency_response.go +++ b/v3/undefined/exif_A20C_spatial_frequency_response.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type TagA20CSpatialFrequencyResponse struct { @@ -39,7 +39,7 @@ func (CodecA20CSpatialFrequencyResponse) Encode(value interface{}, byteOrder bin // TODO(dustin): Add test. sfr, ok := value.(TagA20CSpatialFrequencyResponse) - if ok == false { + if !ok { log.Panicf("can only encode a TagA20CSpatialFrequencyResponse") } diff --git a/v3/undefined/exif_A20C_spatial_frequency_response_test.go b/v3/undefined/exif_A20C_spatial_frequency_response_test.go index 1644752..a8d0fda 100644 --- a/v3/undefined/exif_A20C_spatial_frequency_response_test.go +++ b/v3/undefined/exif_A20C_spatial_frequency_response_test.go @@ -5,10 +5,9 @@ import ( "reflect" "testing" - "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-utility/v2/filesystem" - - "github.com/dsoprea/go-exif/v3/common" + exifcommon "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" + rifs "github.com/dsoprea/go-utility/v2/filesystem" ) func TestTagA20CSpatialFrequencyResponse_String(t *testing.T) { @@ -17,8 +16,8 @@ func TestTagA20CSpatialFrequencyResponse_String(t *testing.T) { Rows: 9, ColumnNames: []string{"column1", "column2"}, Values: []exifcommon.Rational{ - {1, 2}, - {3, 4}, + {Numerator: 1, Denominator: 2}, + {Numerator: 3, Denominator: 4}, }, } @@ -34,8 +33,8 @@ func TestCodecA20CSpatialFrequencyResponse_Encode(t *testing.T) { Rows: 9, ColumnNames: []string{"column1", "column2"}, Values: []exifcommon.Rational{ - {1, 2}, - {3, 4}, + {Numerator: 1, Denominator: 2}, + {Numerator: 3, Denominator: 4}, }, } @@ -68,8 +67,8 @@ func TestCodecA20CSpatialFrequencyResponse_Decode(t *testing.T) { Rows: 9, ColumnNames: []string{"column1", "column2"}, Values: []exifcommon.Rational{ - {1, 2}, - {3, 4}, + {Numerator: 1, Denominator: 2}, + {Numerator: 3, Denominator: 4}, }, } diff --git a/v3/undefined/exif_A300_file_source.go b/v3/undefined/exif_A300_file_source.go index f4f3a49..0c67a1b 100644 --- a/v3/undefined/exif_A300_file_source.go +++ b/v3/undefined/exif_A300_file_source.go @@ -5,9 +5,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type TagExifA300FileSource uint32 @@ -38,7 +38,7 @@ func (CodecExifA300FileSource) Encode(value interface{}, byteOrder binary.ByteOr }() st, ok := value.(TagExifA300FileSource) - if ok == false { + if !ok { log.Panicf("can only encode a TagExifA300FileSource") } diff --git a/v3/undefined/exif_A301_scene_type.go b/v3/undefined/exif_A301_scene_type.go index a29fd76..f742279 100644 --- a/v3/undefined/exif_A301_scene_type.go +++ b/v3/undefined/exif_A301_scene_type.go @@ -5,9 +5,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type TagExifA301SceneType uint32 @@ -35,7 +35,7 @@ func (CodecExifA301SceneType) Encode(value interface{}, byteOrder binary.ByteOrd }() st, ok := value.(TagExifA301SceneType) - if ok == false { + if !ok { log.Panicf("can only encode a TagExif9101ComponentsConfiguration") } diff --git a/v3/undefined/exif_A302_cfa_pattern.go b/v3/undefined/exif_A302_cfa_pattern.go index 8897629..8a264ed 100644 --- a/v3/undefined/exif_A302_cfa_pattern.go +++ b/v3/undefined/exif_A302_cfa_pattern.go @@ -6,9 +6,9 @@ import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type TagA302CfaPattern struct { @@ -38,7 +38,7 @@ func (CodecA302CfaPattern) Encode(value interface{}, byteOrder binary.ByteOrder) // TODO(dustin): Add test. cp, ok := value.(TagA302CfaPattern) - if ok == false { + if !ok { log.Panicf("can only encode a TagA302CfaPattern") } diff --git a/v3/undefined/exif_iop_0002_interop_version.go b/v3/undefined/exif_iop_0002_interop_version.go index 09ec987..6d48994 100644 --- a/v3/undefined/exif_iop_0002_interop_version.go +++ b/v3/undefined/exif_iop_0002_interop_version.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type Tag0002InteropVersion struct { @@ -31,7 +31,7 @@ func (Codec0002InteropVersion) Encode(value interface{}, byteOrder binary.ByteOr }() s, ok := value.(Tag0002InteropVersion) - if ok == false { + if !ok { log.Panicf("can only encode a Tag0002InteropVersion") } diff --git a/v3/undefined/gps_001B_gps_processing_method.go b/v3/undefined/gps_001B_gps_processing_method.go index 6f54d2f..15ba6df 100644 --- a/v3/undefined/gps_001B_gps_processing_method.go +++ b/v3/undefined/gps_001B_gps_processing_method.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type Tag001BGPSProcessingMethod struct { @@ -31,7 +31,7 @@ func (Codec001BGPSProcessingMethod) Encode(value interface{}, byteOrder binary.B }() s, ok := value.(Tag001BGPSProcessingMethod) - if ok == false { + if !ok { log.Panicf("can only encode a Tag001BGPSProcessingMethod") } diff --git a/v3/undefined/gps_001C_gps_area_information.go b/v3/undefined/gps_001C_gps_area_information.go index ffdeb90..025ac9d 100644 --- a/v3/undefined/gps_001C_gps_area_information.go +++ b/v3/undefined/gps_001C_gps_area_information.go @@ -3,9 +3,9 @@ package exifundefined import ( "encoding/binary" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/common" + log "github.com/dsoprea/go-logging" ) type Tag001CGPSAreaInformation struct { @@ -31,7 +31,7 @@ func (Codec001CGPSAreaInformation) Encode(value interface{}, byteOrder binary.By }() s, ok := value.(Tag001CGPSAreaInformation) - if ok == false { + if !ok { log.Panicf("can only encode a Tag001CGPSAreaInformation") } diff --git a/v3/undefined/registration.go b/v3/undefined/registration.go index cccc20a..82c712f 100644 --- a/v3/undefined/registration.go +++ b/v3/undefined/registration.go @@ -1,8 +1,6 @@ package exifundefined -import ( - "github.com/dsoprea/go-logging" -) +import log "github.com/dsoprea/go-logging" // UndefinedTagHandle defines one undefined-type tag with a corresponding // decoder. @@ -15,7 +13,7 @@ func registerEncoder(entity EncodeableValue, encoder UndefinedValueEncoder) { typeName := entity.EncoderName() _, found := encoders[typeName] - if found == true { + if found { log.Panicf("encoder already registered: %v", typeName) } @@ -29,7 +27,7 @@ func registerDecoder(ifdPath string, tagId uint16, decoder UndefinedValueDecoder } _, found := decoders[uth] - if found == true { + if found { log.Panicf("decoder already registered: %v", uth) } diff --git a/v3/utility.go b/v3/utility.go index f0b5e63..b94f5b1 100644 --- a/v3/utility.go +++ b/v3/utility.go @@ -1,15 +1,16 @@ package exif import ( + "context" "fmt" "io" "math" - "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-utility/v2/filesystem" + exifcommon "github.com/dsoprea/go-exif/v3/common" + exifundefined "github.com/dsoprea/go-exif/v3/undefined" - "github.com/dsoprea/go-exif/v3/common" - "github.com/dsoprea/go-exif/v3/undefined" + log "github.com/dsoprea/go-logging" + rifs "github.com/dsoprea/go-utility/v2/filesystem" ) var ( @@ -148,7 +149,7 @@ func getFlatExifDataUniversalSearchWithReadSeeker(rs io.ReadSeeker, so *ScanOpti ti := NewTagIndex() - if doUniversalSearch == true { + if doUniversalSearch { ti.SetUniversalSearch(true) } @@ -175,8 +176,8 @@ func getFlatExifDataUniversalSearchWithReadSeeker(rs io.ReadSeeker, so *ScanOpti if err != nil { if err == exifcommon.ErrUnhandledUndefinedTypedTag { value = exifundefined.UnparseableUnknownTagValuePlaceholder - } else if log.Is(err, exifcommon.ErrParseFail) == true { - utilityLogger.Warningf(nil, + } else if log.Is(err, exifcommon.ErrParseFail) { + utilityLogger.Warningf(context.TODO(), "Could not parse value for tag [%s] (%04x) [%s].", ite.IfdPath(), ite.TagId(), ite.TagName()) diff --git a/value_context.go b/value_context.go index 3fce352..c8c3dec 100644 --- a/value_context.go +++ b/value_context.go @@ -3,7 +3,7 @@ package exif import ( "encoding/binary" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) var ( @@ -110,7 +110,7 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) { unitSizeRaw := uint32(tagType.Size()) - if vc.isEmbedded() == true { + if vc.isEmbedded() { byteLength := unitSizeRaw * vc.unitCount return vc.rawValueOffset[:byteLength], nil } else { diff --git a/value_context_test.go b/value_context_test.go index 3d4df86..348c3e7 100644 --- a/value_context_test.go +++ b/value_context_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" ) func TestValueContext_ReadAscii(t *testing.T) { @@ -51,7 +51,7 @@ func TestValueContext_ReadAscii(t *testing.T) { expected := []byte("Canon EOS 5D Mark III") - if bytes.Compare(decodedBytes, expected) != 0 { + if !bytes.Equal(decodedBytes, expected) { t.Fatalf("Decoded bytes not correct.") } } @@ -106,7 +106,7 @@ func TestValueContext_Undefined(t *testing.T) { expected := []byte("0230") - if bytes.Compare(decodedBytes, expected) != 0 { + if !bytes.Equal(decodedBytes, expected) { t.Fatalf("Decoded bytes not correct.") } }