Write up to count bytes from buffer at offset to the output stream. The number of bytes written will be returned.