aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/ulikunitz/xz/lzma/breader.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/ulikunitz/xz/lzma/breader.go')
-rw-r--r--vendor/github.com/ulikunitz/xz/lzma/breader.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/ulikunitz/xz/lzma/breader.go b/vendor/github.com/ulikunitz/xz/lzma/breader.go
new file mode 100644
index 0000000..5350d81
--- /dev/null
+++ b/vendor/github.com/ulikunitz/xz/lzma/breader.go
@@ -0,0 +1,39 @@
1// Copyright 2014-2017 Ulrich Kunitz. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package lzma
6
7import (
8 "errors"
9 "io"
10)
11
12// breader provides the ReadByte function for a Reader. It doesn't read
13// more data from the reader than absolutely necessary.
14type breader struct {
15 io.Reader
16 // helper slice to save allocations
17 p []byte
18}
19
20// ByteReader converts an io.Reader into an io.ByteReader.
21func ByteReader(r io.Reader) io.ByteReader {
22 br, ok := r.(io.ByteReader)
23 if !ok {
24 return &breader{r, make([]byte, 1)}
25 }
26 return br
27}
28
29// ReadByte read byte function.
30func (r *breader) ReadByte() (c byte, err error) {
31 n, err := r.Reader.Read(r.p)
32 if n < 1 {
33 if err == nil {
34 err = errors.New("breader.ReadByte: no data")
35 }
36 return 0, err
37 }
38 return r.p[0], nil
39}