File: discard.go

package info (click to toggle)
golang-github-djherbis-buffer 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 160 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 590 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
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{})
}