Here's the GZipStream I used but the support dept wants me to use Zip instead of GZip cuz Windows doesnt support GZip and customers don't know how to open it.
Basically what I have is PDF bytes in memory and attached it to email.
So, I had to convert it to Zip but having trouble to do so. I tried ZipArchive
but it require disk. I tried Deflate
but got 0 bytes in the end.
So, what do you guys do to make it work?
[Original]
public static byte[] CompressFile(byte[] parmRawBytes)
{
using (var memoryStream = new MemoryStream())
{
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
{
gzipStream.Write(parmRawBytes.ToArray(), 0, parmRawBytes.ToArray().Length);
}
return memoryStream.ToArray();
}
}
[New]
public static byte[] CompressFile(byte[] parmRawBytes)
{
using (var sourceMemoryStream = new MemoryStream(parmRawBytes))
{
sourceMemoryStream.Position = 0; //Reset memory-stream pointer...
using (var targetMemoryStream = new MemoryStream())
{
//using (var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, false))
//{
// var zipArchiveEntry = zipArchive.CreateEntry("foo.pdf");
//
// using (var stream = zipArchiveEntry.Open())
// {
// memoryStream.CopyTo(stream);
// }
//}
using (var deflateStream = new DeflateStream(sourceMemoryStream, CompressionMode.Compress))
{
targetMemoryStream.CopyTo(deflateStream);
}
return targetMemoryStream.ToArray();
}
}
}