summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/djherbis/buffer/discard.go
blob: ecf44987bab52e177c104ef88b208160f3ec8fba (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
35
36
package buffer

import (
	"encoding/gob"
	"io"
	"io/ioutil"
	"math"
)

type discard struct{}

// Discard is a Buffer which writes to ioutil.Discard and read's return 0, io.EOF.
// All of its methods are concurrent safe.
var Discard Buffer = discard{}

func (buf discard) Len() int64 {
	return 0
}

func (buf discard) Cap() int64 {
	return math.MaxInt64
}

func (buf discard) Reset() {}

func (buf discard) Read(p []byte) (n int, err error) {
	return 0, io.EOF
}

func (buf discard) Write(p []byte) (int, error) {
	return ioutil.Discard.Write(p)
}

func init() {
	gob.Register(&discard{})
}