forked from djherbis/buffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_compatible.go
More file actions
40 lines (32 loc) · 977 Bytes
/
buffer_compatible.go
File metadata and controls
40 lines (32 loc) · 977 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 buffer
import "io"
// Buffer is used to Write() data which will be Read() later.
type BufferCompatible interface {
Len() int // How much data is Buffered in bytes
Cap() int // How much data can be Buffered at once in bytes.
Len64() int64 // How much data is Buffered in bytes
Cap64() int64 // How much data can be Buffered at once in bytes.
io.Reader // Read() will read from the top of the buffer [io.EOF if empty]
io.Writer // Write() will write to the end of the buffer [io.ErrShortWrite if not enough space]
Reset() // Truncates the buffer, Len() == 0.
}
func MakeBufferCompatibe(b Buffer) BufferCompatible {
return compatible{
Buffer: b,
}
}
type compatible struct {
Buffer
}
func (c compatible) Len() int {
return int(c.Buffer.Len())
}
func (c compatible) Cap() int {
return int(c.Buffer.Cap())
}
func (c compatible) Len64() int64 {
return c.Buffer.Len()
}
func (c compatible) Cap64() int64 {
return c.Buffer.Cap()
}