Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.