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:
parent
a7abac2eaf
commit
5a30e27f04
@ -83,7 +83,7 @@ func NewReader(reader io.Reader) Reader {
|
||||
|
||||
return &BytesToBufferReader{
|
||||
reader: reader,
|
||||
buffer: NewLocal(32 * 1024),
|
||||
buffer: make([]byte, 32*1024),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user