-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreader.go
More file actions
40 lines (33 loc) · 903 Bytes
/
reader.go
File metadata and controls
40 lines (33 loc) · 903 Bytes
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
package rtmp
import (
"bufio"
"io"
)
type Reader struct {
io.Reader
reader *bufio.Reader
n uint64
}
// Read reads exactly len(p) bytes from the underlying bufio.Reader into p.
// It returns the number of bytes copied and an error if fewer bytes were read.
// The error is EOF only if no bytes were read.
// If an EOF happens after reading some but not all the bytes,
// Read returns ErrUnexpectedEOF.
// On return, n == len(buf) if and only if err == nil.
func (r *Reader) Read(p []byte) (n int, err error) {
n, err = io.ReadFull(r.reader, p)
r.n += uint64(n)
return n, err
}
// ReadByte reads and returns a single byte from the underlying bufio.Reader.
// If no byte is available, returns an error.
func (r *Reader) ReadByte() (byte, error) {
b, err := r.reader.ReadByte()
if err == nil {
r.n++
}
return b, err
}
func (r *Reader) getNumberOfReadBytes() uint64 {
return r.n
}