I have an instance of MemoryStream that is closed (don’t ask, can’t change that and it is not that poor design as it seems at first glance :).
Anyway I found that I can take the byte[] using something like:
MemoryStream ms = SomeClass.GetMemoryStream();
byte[] myData = ms.GetBuffer();
Everything seems just great so far, the only problem I have is that the byte array returned from GetBuffer() is resized and contains unallocated space (byte)0;
Like so:
12,32,43,43,2,3,0,0,0,0,0,0,0
My question is is it safe to assume that I can read the array until I encounter the first 0?
Do you know any case in wich there will be (byte)0 in the middle of the data?
The data is a MIME Email Message.
Try
ms.ToArray(): http://msdn.microsoft.com/en-us/library/system.io.memorystream.toarray.aspxIt works on a closed stream and returns a copy of the data, without the unused part of the buffer.