clear logic in v2io.Pipe

pull/168/head
v2ray 2016-05-11 11:54:29 -07:00
parent e9ae553f78
commit 7fd94e1116
1 changed files with 8 additions and 4 deletions

View File

@ -3,12 +3,16 @@ package io
func Pipe(reader Reader, writer Writer) error {
for {
buffer, err := reader.Read()
if buffer.Len() > 0 {
err = writer.Write(buffer)
} else {
buffer.Release()
if err != nil {
return nil
}
if buffer.IsEmpty() {
buffer.Release()
continue
}
err = writer.Write(buffer)
if err != nil {
return nil
}