/
inputstream.go
65 lines (51 loc) · 1.25 KB
/
inputstream.go
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
57
58
59
60
61
62
63
64
65
package store
import (
"errors"
"io"
)
var _ IndexInput = &InputStream{}
// InputStream A DataInput wrapping a plain InputStream.
type InputStream struct {
*BaseDataInput
eof bool
is io.Reader
}
func NewInputStream(is io.Reader) *InputStream {
input := &InputStream{is: is}
input.BaseDataInput = NewBaseDataInput(input)
return input
}
func (i *InputStream) Seek(offset int64, whence int) (int64, error) {
return 0, errors.New("unsupported operate")
}
func (i *InputStream) GetFilePointer() int64 {
return -1
}
func (i *InputStream) Slice(sliceDescription string, offset, length int64) (IndexInput, error) {
return nil, errors.New("unsupported operate")
}
func (i *InputStream) Length() int64 {
return 0
}
func (i *InputStream) RandomAccessSlice(offset int64, length int64) (RandomAccessInput, error) {
return nil, errors.New("unsupported operate")
}
func (i *InputStream) Clone() CloneReader {
return i
}
func (i *InputStream) ReadByte() (byte, error) {
bs := [1]byte{}
if _, err := i.Read(bs[:]); err != nil {
return 0, err
}
return bs[0], nil
}
func (i *InputStream) Read(b []byte) (int, error) {
return i.is.Read(b)
}
func (i *InputStream) Close() error {
if closer, ok := i.is.(io.Closer); ok {
return closer.Close()
}
return nil
}