@@ -25,10 +25,10 @@ var ErrNotExist = errors.New("file does not exist")
25
25
26
26
// Exiftool is the exiftool utility wrapper
27
27
type Exiftool struct {
28
- lock sync.Mutex
29
- stdin io.WriteCloser
30
- stdout io.ReadCloser
31
- scanout * bufio.Scanner
28
+ lock sync.Mutex
29
+ stdin io.WriteCloser
30
+ stdMergedOut io.ReadCloser
31
+ scanMergedOut * bufio.Scanner
32
32
}
33
33
34
34
// NewExiftool instanciates a new Exiftool with configuration functions. If anything went
@@ -43,18 +43,19 @@ func NewExiftool(opts ...func(*Exiftool) error) (*Exiftool, error) {
43
43
}
44
44
45
45
cmd := exec .Command (binary , initArgs ... )
46
+ r , w := io .Pipe ()
47
+ e .stdMergedOut = r
48
+
49
+ cmd .Stdout = w
50
+ cmd .Stderr = w
46
51
47
52
var err error
48
53
if e .stdin , err = cmd .StdinPipe (); err != nil {
49
54
return nil , fmt .Errorf ("error when piping stdin: %w" , err )
50
55
}
51
56
52
- if e .stdout , err = cmd .StdoutPipe (); err != nil {
53
- return nil , fmt .Errorf ("error when piping stdout: %w" , err )
54
- }
55
-
56
- e .scanout = bufio .NewScanner (e .stdout )
57
- e .scanout .Split (splitReadyToken )
57
+ e .scanMergedOut = bufio .NewScanner (r )
58
+ e .scanMergedOut .Split (splitReadyToken )
58
59
59
60
if err = cmd .Start (); err != nil {
60
61
return nil , fmt .Errorf ("error when executing commande: %w" , err )
@@ -76,8 +77,8 @@ func (e *Exiftool) Close() error {
76
77
}
77
78
78
79
var errs []error
79
- if err := e .stdout .Close (); err != nil {
80
- errs = append (errs , fmt .Errorf ("error while closing stdout : %w" , err ))
80
+ if err := e .stdMergedOut .Close (); err != nil {
81
+ errs = append (errs , fmt .Errorf ("error while closing stdMergedOut : %w" , err ))
81
82
}
82
83
83
84
if err := e .stdin .Close (); err != nil {
@@ -119,19 +120,19 @@ func (e *Exiftool) ExtractMetadata(files ...string) []FileMetadata {
119
120
fmt .Fprintln (e .stdin , f )
120
121
fmt .Fprintln (e .stdin , executeArg )
121
122
122
- if ! e .scanout .Scan () {
123
- fms [i ].Err = fmt .Errorf ("nothing on stdout " )
123
+ if ! e .scanMergedOut .Scan () {
124
+ fms [i ].Err = fmt .Errorf ("nothing on stdMergedOut " )
124
125
continue
125
126
}
126
127
127
- if e .scanout .Err () != nil {
128
- fms [i ].Err = fmt .Errorf ("error while reading stdout : %w" , e .scanout .Err ())
128
+ if e .scanMergedOut .Err () != nil {
129
+ fms [i ].Err = fmt .Errorf ("error while reading stdMergedOut : %w" , e .scanMergedOut .Err ())
129
130
continue
130
131
}
131
132
132
133
var m []map [string ]interface {}
133
- if err := json .Unmarshal (e .scanout .Bytes (), & m ); err != nil {
134
- fms [i ].Err = fmt .Errorf ("error during unmarshaling (%v): %w)" , e .scanout .Bytes (), err )
134
+ if err := json .Unmarshal (e .scanMergedOut .Bytes (), & m ); err != nil {
135
+ fms [i ].Err = fmt .Errorf ("error during unmarshaling (%v): %w)" , e .scanMergedOut .Bytes (), err )
135
136
continue
136
137
}
137
138
0 commit comments