I believe "size" returns the size of the current buffer, not necessarily the size written. Can you test it? We may need to keep a separate counter to measure the amount of data read.