hugo/transform/chain.go
Noah Campbell 80009b427f Change the order of Apply to be more Unixy
Typically the destination is on the left and the src is on the right.
2013-10-08 18:37:50 +02:00

30 lines
451 B
Go

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