I am trying to use GZipStream with MemoryStream. I write all bytes I need and then close gzip stream so after that I need to get compressed buffer from memory stream without allocation additional memory (method ToArray returns necessary bytes array but it creates new byte array and then copies all bytes from buffer into the new array). As far as I understand I can only use GetBuffer() which returns entire buffer so in this case I have yet another question: Is it true that all zero bytes in the end of the buffer doesn't belong to the compressed data? In other words can I use GetBuffer with assume that the compressed buffer ends with last non-zero byte?
Also in many cases I can use Length of MemoryStream before closing GZip stream and just add 10 to it after GZip stream is closed is it true for all cases?