Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read a file and zip its content in RAM
FileInfo fi = new FileInfo(fullpath);
String b64ZippedData = String.Empty;
using (FileStream filestream = fi.OpenRead()) // source
{
using (MemoryStream memorystream = new MemoryStream()) // destination
{
using (GZipStream gzipstream = new GZipStream(memorystream, CompressionMode.Compress, false)) // compression engine
{
filestream.CopyTo(gzipstream);
}
b64ZippedData = System.Convert.ToBase64String(memorystream.ToArray());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment