Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active December 13, 2015 19:38
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 yetanotherchris/4964019 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4964019 to your computer and use it in GitHub Desktop.
GZIP writing example
byte[] buffer;
using (FileStream fileStream = new FileStream(@"c:\out.html", FileMode.Open))
{
// Read the file's contents into a byte array
buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, buffer.Length);
}
using (MemoryStream memoryStream = new MemoryStream())
{
// The GZipStream uses the MemoryStream to write its compressed version
// of the byte array.
using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
{
gzipStream.
gzipStream.Write(buffer, 0, buffer.Length);
}
// Write back to a file.
using (FileStream fileStreamOut = new FileStream(@"c:\out.zip", FileMode.Create))
memoryStream.WriteTo(fileStreamOut);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment