-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresconv.go
51 lines (39 loc) · 975 Bytes
/
presconv.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package presconv
import (
"bytes"
"io"
)
// Converter describes types intended for processing presentation slide
// files.
type Converter interface {
ConvertPres(io.Writer, io.Reader) error
}
type ConverterFunc func(io.Writer, io.Reader) error
func (c ConverterFunc) ConvertPres(dst io.Writer, src io.Reader) error {
return c(dst, src)
}
// PresConv manages converters for parsing presentation slide files.
type PresConv struct {
cs []Converter
}
// New constructs an instance of PresConv.
func New(cs ...Converter) *PresConv {
c := PresConv{
cs: cs,
}
return &c
}
// ConvertPres leverages the underlying converters queue to process presentation
// slide files.
func (c *PresConv) ConvertPres(dst io.Writer, src io.Reader) error {
var buf *bytes.Buffer
i := len(c.cs) - 1
for _, cc := range c.cs[:i] {
buf = &bytes.Buffer{}
if err := cc.ConvertPres(buf, src); err != nil {
return err
}
src = buf
}
return c.cs[i].ConvertPres(dst, src)
}