hugo/transform/chain.go

31 lines
399 B
Go
Raw Normal View History

package transform
import (
"bytes"
2013-10-02 02:59:35 +00:00
"io"
)
type trans func([]byte) []byte
type link trans
type chain []link
func NewChain(trs ...link) chain {
return trs
}
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
buffer := new(bytes.Buffer)
buffer.ReadFrom(r)
b := buffer.Bytes()
for _, tr := range *c {
b = tr(b)
}
buffer.Reset()
buffer.Write(b)
buffer.WriteTo(w)
return
}