2016년 12월 16일 금요일 오전 11시 5분 53초 UTC+9, Peng Wang 님의 말:
Actually I don't really care about that, just don't want break the 
interface requirement
in the doc it says "WriteAt writes len(p) bytes from p to the underlying 
data stream at offset off. It returns the number of bytes written from p (0 
<= n <= len(p)) and any error encountered that caused the write to stop 
early."
but using binary.Write I lost that infomation. So what's the right way to 
do it ? or just ignore it and return 0? 

Write should inform the caller of the number of bytes written even though 
some error happens during the write operation. 
(https://golang.org/pkg/io/#Writer states explicitly). It's recommended for 
the WriteTo method to return a proper n, not 0.

binary.Write dosen't return how many bytes are written, but not mean you 
have to miss the information, because binary.Write calls internally to 
io.Write.

As Tamás Gulácsi says, you can wrap w in countWriter. And if error occurs, 
examine countWriter.N field to get information about the number of bytes 
written.

I couldn't understand this wrapping could break the interface requirements. 
The program you're writing need some even complicated behavior i couldn't 
guess at?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to