1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00

use normal byte array

This commit is contained in:
Darien Raymond 2017-04-19 23:30:18 +02:00
parent a7abac2eaf
commit 5a30e27f04
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 8 additions and 5 deletions

View File

@ -83,7 +83,7 @@ func NewReader(reader io.Reader) Reader {
return &BytesToBufferReader{
reader: reader,
buffer: NewLocal(32 * 1024),
buffer: make([]byte, 32*1024),
}
}

View File

@ -9,20 +9,23 @@ import (
// BytesToBufferReader is a Reader that adjusts its reading speed automatically.
type BytesToBufferReader struct {
reader io.Reader
buffer *Buffer
buffer []byte
}
// Read implements Reader.Read().
func (r *BytesToBufferReader) Read() (MultiBuffer, error) {
if err := r.buffer.Reset(ReadFrom(r.reader)); err != nil {
nBytes, err := r.reader.Read(r.buffer)
if err != nil {
return nil, err
}
mb := NewMultiBuffer()
for !r.buffer.IsEmpty() {
p := r.buffer[:nBytes]
for len(p) > 0 {
b := New()
b.AppendSupplier(ReadFrom(r.buffer))
nBytes, _ := b.Write(p)
mb.Append(b)
p = p[nBytes:]
}
return mb, nil
}