Created
August 23, 2017 15:02
-
-
Save pste/f06b7226f81d3906d58c2b814bc01be0 to your computer and use it in GitHub Desktop.
Read a file and zip its content in RAM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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