`write` does not guarantee to write all the bytes on first call