You are writing a method to compress an array of bytes. The array is passed to the method in a parameter named document. You need to compress the incoming array of bytes and return the result as an array of bytes. Which code segment should you use?
A.
MemoryStream strm = new MemoryStream(document);
DeflateStream deflate = new DeflateStream(strm, CompressionMode.Compress);
byte[] result = new byte[document.Length];
deflate.Write(result, 0, result.Length);
return result;
B.
MemoryStream strm = new MemoryStream(document);
DeflateStream deflate = new DeflateStream(strm, CompressionMode.Compress);
deflate.Write(document, 0, document.Length);
deflate.Close();
return strm.ToArray();
C.
MemoryStream strm = new MemoryStream();
DeflateStream deflate = new DeflateStream(strm, CompressionMode.Compress);
deflate.Write(document, 0, document.Length);
deflate.Close();
return strm.ToArray();
D.
MemoryStream inStream = new MemoryStream(document);
DeflateStream deflate = new DeflateStream(inStream, CompressionMode.Compress);
MemoryStream outStream = new MemoryStream();
int b;
while ((b = deflate.ReadByte()) != -1) {
outStream.WriteByte((byte)b);
}
return outStream.ToArray();