Domain.com has a file server named Certkiller -SR07 that stores old inventory files. Domain.com has given you the task of creating an application to archive these old inventory files.
The inventory files have to be compressed prior to being uploaded to Domain.com’s Web server.
You are currently writing a method that will receive a byte array and compress it into a new file.
You need to ensure that a data corruption check takes place during the decompression process.
What should you do?
A.
Use the following code:
public void CompressFileWrite(string file, byte[] data){
FileStream fs = new FileStream(file, FileMode.Create);
DeflateStream cs = new DeflateStream( fs, Compressionmode.Compress, true);
cs.Write (data, 0, data.Length);
cs.Close();
}
B.
Use the following code:
public void CompressFileWrite(string file, byte[] data){
FileStream fs = new FileStream (file, FileMode.Create);
GZipStream cs = new GZipStream( fs, Compressionmode.Compress, true);
cs.Compress (data, 0, data.Length);
cs.Close ();
}
C.
Use the following code:
public void CompressFileWrite(string file, byte[] data){
FileStream fs = new FileStream(file, FileMode.Create);
DeflateStream cs = new DeflateStream( fs, Compressionmode.Compress, true);
cs.Compress(data, 0, data.Length);
cs.Close ();
}
D.
Use the following code:
public void CompressFileWrite (string file, byte[] data){
FileStream fs = new FileStream(file, FileMode.Create);
GZipStream cs = new GZipStream( fs, Compressionmode.Compress, true);
cs.Write(data, 0, data.Length);
cs.Close();
}
Explanation:
Incorrect Answers:
A, B, C: You should not use the code fragments that specify the DeflateStream class because this data format does not ensure that a data corruption check occurs during decompression. You should also not use the code that invokes the Compress method because no such method exists in the GZipStream or the DeflateStream classes.
I choose D