// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.IO.Compression; using System.Text; namespace E { public class GZipTest { private const int NLIN = 10000; private const int LINLEN = 20; private const string VALS = "ABCDEFGH"; public static void Write(StreamWriter sw) { Random rng = new Random(123567); for(int i = 0; i < NLIN; i++) { StringBuilder sb = new StringBuilder(); for(int j = 0; j < LINLEN; j++) { if(j > 0 && rng.NextDouble() > 0.5) { sb.Append(sb[j-1]); } else { sb.Append(VALS[rng.Next(VALS.Length)]); } } sw.WriteLine(sb.ToString()); } } public static void Standard(string fnm) { using(FileStream fs = File.Create(fnm)) using(GZipStream gzs = new GZipStream(fs, CompressionMode.Compress)) using(StreamWriter sw = new StreamWriter(gzs)) Write(sw); } public static void Buffer(string fnm) { using(FileStream fs = File.Create(fnm)) using(GZipStream gzs = new GZipStream(fs, CompressionMode.Compress)) using(BufferedStream bs = new BufferedStream(gzs, 100000)) using(StreamWriter sw = new StreamWriter(bs)) Write(sw); } public static void Main(string[] args) { Standard(@"C:\standard.gz"); Buffer(@"C:\buffer.gz"); } } }