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
|
// Copyright 2019 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uio
import (
"io"
)
type multiCloser struct {
io.Writer
writers []io.Writer
}
// Close implements io.Closer and closes any io.Writers that are also
// io.Closers.
func (mc *multiCloser) Close() error {
var allErr error
for _, w := range mc.writers {
if c, ok := w.(io.Closer); ok {
if err := c.Close(); err != nil {
allErr = err
}
}
}
return allErr
}
// MultiWriteCloser is an io.MultiWriter that has an io.Closer and attempts to
// close those w's that have optional io.Closers.
func MultiWriteCloser(w ...io.Writer) io.WriteCloser {
return &multiCloser{
Writer: io.MultiWriter(w...),
writers: w,
}
}
|