Welcome to mirror list, hosted at ThFree Co, Russian Federation.

chain.go « transform - github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c673c5d6a6729d52f470b9ecff9edcc0d7e15a02 (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
30
31
32
33
34
package transform

import (
	"bytes"
	"io"
)

type trans func([]byte) []byte

type link trans

type chain []link

func NewChain(trs ...link) chain {
	return trs
}

func NewEmptyTransforms() []link {
	return make([]link, 0, 20)
}

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
}