I want to compress a file that has binary data and save the compressed data in another file:
FileStream fileStream = new FileStream("compressed_file.bin", FileMode.Create, FileAccess.Write);
GZipStream compressionStream = new GZipStream(fileStream, CompressionMode.Compress);
StreamWriter writer = new StreamWriter(compressionStream);
writer.Write(File.ReadAllBytes("file_to_be_compressed.bin"), 0, File.ReadAllBytes("file_to_be_compressed.bin").Length);
writer.Close();
I get following error:
cannot convert from 'byte[]' to 'char[]'
in line:
writer.Write(File.ReadAllBytes("file_to_be_compressed.bin"), 0, File.ReadAllBytes("file_to_be_compressed.bin").Length)
And is it fine to convert the binary data of file to byte array, or is it better to pass binary data of file as stream?
Note: CopyTo is not available in .NET 2.0