I think the Hans Passant requirement for an error in MemoryStream.WriteTo () is incorrect; it does not "ignore the return value of Write ()". Stream.Write () returns void, which implies that all bytes of the count are written, which implies that Stream.Write () will block as needed to complete the operation, for example, NetworkStream, or discard if it ultimately fails .
Is this really different than write () in? nix and its many emulations in libc, etc., which can return a "short record". I suspect that Hans came to the conclusion that Stream.Write () followed this, which I expected, but apparently does not.
It can be assumed that Stream.Write () can perform a “short record” without returning any indication of this, requiring the caller to check whether the Position Stream property has really been advanced in the account. This would be a very error prone API, and I doubt that it does, but I have not tested it completely. (Testing would be a little more complicated: I think you need to connect a TCP NetworkStream with a reader on the other end that is locked forever, and write enough to fill the wire buffers. Or something like that ...)
Comments for Stream.Write () are not entirely clear:
Summary: When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position in this stream by the number of bytes written. Parameters: buffer: An array of bytes. This method copies the number of bytes from the buffer into the current stream.
Compare this to the Linux work page for writing (2):
write () writes to count the bytes from the buffer specified in buf to the file specified by the file descriptor fd.
Pay attention to the "do". This proposal is followed by an explanation of some of the conditions under which a “short record” may occur, which makes it very obvious that this can happen.
This is really a critical issue: we need to know how Stream.Write () behaves, without a doubt.
Kafka
source share