GZip in .NET

public class Gzip {
    public static void Compress(Stream inputStream, Stream outputStream) {
        using (var gzip = new GZipStream(outputStream, CompressionMode.Compress)) {
            byte[] buffer = new byte[8192];
            int count;
            while ((count = inputStream.Read(buffer, 0, buffer.Length)) > 0) {
                gzip.Write(buffer, 0, count);
            }
        }
    }
 
    public static void Decompress(Stream inputStream, Stream outputStream) {
        using (var gzip = new GZipStream(inputStream, CompressionMode.Decompress)) {
            byte[] buffer = new byte[8192];
            int count;
            while ((count = gzip.Read(buffer, 0, buffer.Length)) > 0) {
                outputStream.Write(buffer, 0, count);
            }
        }
    }
}

Comments

Popular posts from this blog

C# Record Serialization

Add timestamp to photo using ImageMagick

Read/write large blob to SQL Server from C#