Skip to content

Instantly share code, notes, and snippets.

@pste
Created August 23, 2017 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pste/f06b7226f81d3906d58c2b814bc01be0 to your computer and use it in GitHub Desktop.
Save pste/f06b7226f81d3906d58c2b814bc01be0 to your computer and use it in GitHub Desktop.
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