diff options
Diffstat (limited to 'transform/chain.go')
-rw-r--r-- | transform/chain.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/transform/chain.go b/transform/chain.go new file mode 100644 index 000000000..e408b01d2 --- /dev/null +++ b/transform/chain.go @@ -0,0 +1,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 +} |