aboutsummaryrefslogtreecommitdiff
path: root/utils/io.go
blob: fcc341ed560f54d77beda698ab92a74730ffc226 (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
37
38
39
package utils

import (
	"compress/zlib"
	"io"
)

// NopCloser returns a WriteCloser with a no-op Close method wrapping
// the provided Writer w.
func NopCloser(w io.Writer) io.WriteCloser {
	return nopCloser{w}
}

type nopCloser struct {
	io.Writer
}

func (nopCloser) Close() error { return nil }

type ReadWrapper func(r io.Reader) (io.ReadCloser, error)
type WriteWrapper func(w io.Writer) io.WriteCloser

// ZlibReader wraps a reader with a new zlib.Reader.
func ZlibReader(r io.Reader) (io.ReadCloser, error) {
	return zlib.NewReader(r)
}

// ZlibWrier wraps a writer with a new zlib.Writer.
func ZlibWriter(w io.Writer) io.WriteCloser {
	return zlib.NewWriter(w)
}

func NopReadWrapper(r io.Reader) (io.ReadCloser, error) {
	return io.NopCloser(r), nil
}

func NopWriteWrapper(w io.Writer) io.WriteCloser {
	return NopCloser(w)
}