File: input_collector.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (56 lines) | stat: -rw-r--r-- 989 bytes parent folder | download
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
52
53
54
55
56
package command

import (
	"github.com/ProtonMail/gluon/rfcparser"
)

type InputCollector struct {
	source rfcparser.Reader
	bytes  []byte
}

func NewInputCollector(source rfcparser.Reader) *InputCollector {
	return &InputCollector{
		source: source,
		bytes:  make([]byte, 0, 128),
	}
}

func (i *InputCollector) Bytes() []byte {
	return i.bytes
}

func (i *InputCollector) Read(dst []byte) (int, error) {
	n, err := i.source.Read(dst)
	if err == nil {
		i.bytes = append(i.bytes, dst[0:n]...)
	}

	return n, err
}

func (i *InputCollector) ReadByte() (byte, error) {
	b, err := i.source.ReadByte()
	if err == nil {
		i.bytes = append(i.bytes, b)
	}

	return b, err
}

func (i *InputCollector) ReadBytes(delim byte) ([]byte, error) {
	b, err := i.source.ReadBytes(delim)
	if err == nil {
		i.bytes = append(i.bytes, b...)
	}

	return b, err
}

func (i *InputCollector) Reset() {
	i.bytes = i.bytes[:0]
}

func (i *InputCollector) SetSource(source rfcparser.Reader) {
	i.source = source
}