Last active
December 13, 2015 19:38
-
-
Save yetanotherchris/4964019 to your computer and use it in GitHub Desktop.
GZIP writing example
This file contains 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
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