The problem was getting the data out of the memory stream.
outStream.ToArray();
returnes the compressed bytes.
Working Compression Method:
public static byte[] CompressData(string fileName)
{
byte[] uncompressedFileData = new byte[0];
byte[] compressedFileData = new byte[0];
try
{
var stopwatch = new Stopwatch();
stopwatch.Reset();
stopwatch.Start();
if (!File.Exists(fileName))
{
throw new FileNotFoundException(fileName + " not found");
}
uncompressedFileData = File.ReadAllBytes(fileName);
using (var outStream = new MemoryStream())
{
using (var compress = new DeflateStream(outStream, CompressionMode.Compress, true))
{
compress.Write(uncompressedFileData, 0, uncompressedFileData.Length);
compress.Flush();
compress.Close();
}
compressedFileData = outStream.ToArray();
}
stopwatch.Stop();
#if DEBUG
Console.WriteLine("Compressed {0} bytes to {1} bytes in {2} seconds", uncompressedFileData.Length, compressedFileData.Length, stopwatch.Elapsed.TotalSeconds);
#endif
}
catch (Exception ex)
{
m_Log.Error(ex.Message, ex);
}
return compressedFileData;
}