-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
xmp.go
37 lines (33 loc) · 851 Bytes
/
xmp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Package xmp provides support for dealing with XMP files and packets.
package xmp
import (
"encoding/xml"
"io"
"strings"
)
// IsSidecarForExt checks if a reader is the sidecar for a given file extension.
func IsSidecarForExt(r io.Reader, ext string) bool {
test := func(name xml.Name) bool {
return name.Local == "SidecarForExtension" &&
(name.Space == "http://ns.adobe.com/photoshop/1.0/" || name.Space == "photoshop")
}
dec := xml.NewDecoder(r)
for {
t, err := dec.Token()
if err != nil {
return err == io.EOF // assume yes
}
if s, ok := t.(xml.StartElement); ok {
if test(s.Name) {
t, _ := dec.Token()
v, ok := t.(xml.CharData)
return ok && strings.EqualFold(ext, "."+string(v))
}
for _, a := range s.Attr {
if test(a.Name) {
return strings.EqualFold(ext, "."+a.Value)
}
}
}
}
}