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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user