blob: e408b01d20ea47f4f33eec43a13c591acd388a37 (
plain)
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
|
package transform
import (
"io"
"bytes"
)
type chain struct {
transformers []Transformer
}
func NewChain(trs ...Transformer) Transformer {
return &chain{transformers: trs}
}
func (c *chain) Apply(r io.Reader, w io.Writer) (err error) {
in := r
for _, tr := range c.transformers {
out := new(bytes.Buffer)
err = tr.Apply(in, out)
if err != nil {
return
}
in = bytes.NewBuffer(out.Bytes())
}
_, err = io.Copy(w, in)
return
}
|