Rolling text file to GZip Trace Listener

This writes to a text file, then after 10MB is written, the log file is gzipped and a new one is created. This is a blocking operation, so be aware you may get the occasional short delay. If the app is interrupted the file contents will be there in plain text up to that point, […]

GZip with Pako

GZip is a super-fast compression technique, usable anywhere. In javascript, you can use the Pako library to compress your data. Browser <!DOCTYPE html><html><head> <title>Test Zip</title> </head> <body> <textarea id=”inputText” style=”width: 90%; height: 300px;”></textarea> <textarea id=”outputText” style=”width: 90%; height: 300px;”></textarea> <br> <input type=”button” value=”Go” onclick=”go();”> <script src=”https://cdn.jsdelivr.net/pako/1.0.5/pako.min.js”></script&gt; <script> function go() { console.log(document.getElementById(“inputText”).value.length); var compressedBytes = pako.gzip(document.getElementById(“inputText”).value); […]

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 […]

GZip in .NET

GZip in .NET is really simple and straightforward. Below you can find a helper class that gives you the ability to compress and decompress a stream, byte array, string, or file – you can easily modify these to suit your needs. View code on GitHub