1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-11-13 23:24:27 -05:00

buffered reader and writer

This commit is contained in:
v2ray
2016-02-26 23:45:33 +01:00
parent 7fa96a4d2c
commit be09847bbd
5 changed files with 203 additions and 0 deletions

View File

@@ -95,6 +95,10 @@ func (b *Buffer) Len() int {
return len(b.Value)
}
func (b *Buffer) IsEmpty() bool {
return b.Len() == 0
}
// IsFull returns true if the buffer has no more room to grow.
func (b *Buffer) IsFull() bool {
return len(b.Value) == cap(b.Value)
@@ -120,6 +124,14 @@ func (b *Buffer) Read(data []byte) (int, error) {
return nBytes, nil
}
func (b *Buffer) FillFrom(reader io.Reader) (int, error) {
begin := b.Len()
b.Value = b.Value[:cap(b.Value)]
nBytes, err := reader.Read(b.Value[begin:])
b.Value = b.Value[:begin+nBytes]
return nBytes, err
}
type bufferPool struct {
chain chan []byte
allocator *sync.Pool