Skip to content

Commit

Permalink
return correct number of bytes written
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Nov 19, 2016
1 parent 18cd10b commit 1169476
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common/io/chain_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@ func (this *ChainWriter) Write(payload []byte) (int, error) {
return 0, io.ErrClosedPipe
}

bytesWritten := 0
size := len(payload)
for size > 0 {
buffer := alloc.NewBuffer().Clear()
if size > alloc.BufferSize {
buffer.Append(payload[:alloc.BufferSize])
size -= alloc.BufferSize
payload = payload[alloc.BufferSize:]
bytesWritten += alloc.BufferSize
} else {
buffer.Append(payload)
bytesWritten += size
size = 0
}
err := this.writer.Write(buffer)
if err != nil {
return 0, err
return bytesWritten, err
}
}

return size, nil
return bytesWritten, nil
}

func (this *ChainWriter) Release() {
Expand Down

0 comments on commit 1169476

Please sign in to comment.