Implement copying a buffer to an output stream.