You are writing a method to compress an array of bytes.

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 = gcnew MemoryStream(document);
    DeflateStream^ deflate = gcnew DeflateStream(strm,
    CompressionMode::Compress);
    array<Byte>^ result = gcnew array<Byte>(document->Length);
    deflate->Write(result, 0, result->Length);
    return result;
B. MemoryStream^ strm = gcnew MemoryStream(document);
    DeflateStream^ deflate = gcnew DeflateStream(strm,
    CompressionMode::Compress);
    deflate->Write(document, 0, document->Length);
    deflate->Close();return strm->ToArray();
C. MemoryStream^ strm = gcnew MemoryStream();
    DeflateStream^ deflate = gcnew
    DeflateStream(strm,CompressionMode::Compress);deflate->Write(document, 0, document-    
    >Length);
    deflate->Close();
    return strm->ToArray();
D. MemoryStream^ inStream = gcnew MemoryStream(document);DeflateStream^
    deflate = gcnew DeflateStream(inStream,
    CompressionMode::Compress);
    MemoryStream^ outStream = gcnew MemoryStream()
    ;int b;
    while ((b = deflate->ReadByte()) != -1) {
    outStream->WriteByte((Byte)b);
    }
    return outStream->ToArray();
   

Answer: C

No comments:

Post a Comment