using System;
using System.IO;
using System.IO.Compression;
using System.Text;

public class DeflateTest
{
   private static string file = @"C:\temp\file.txt";
   private static string zipfile = @"C:\temp\zipfile.zip";
   private static string unzipfile = @"C:\temp\unzipfile.txt";

   public static void DecompressFile()
   {
      //Größe der Basisdatei auslesen
      FileStream basefile = new FileStream(file, FileMode.Open);
      byte[] buffer = new byte[basefile.Length];

      //Gezippte Datei einlesen und Dekomprimieren
      FileStream zippedfile = new FileStream(zipfile, FileMode.Open);
      DeflateStream ds = new DeflateStream(zippedfile, CompressionMode.Decompress);
      //GZipStream ds = new GZipStream(zippedfile, CompressionMode.Decompress);
      ds.Read(buffer, 0, buffer.Length);
      zippedfile.Close();
      ds.Close();

      //Dekomprimierte Daten in Datei schreiben.
      FileStream unzippedfile = new FileStream(unzipfile, FileMode.Create);
      unzippedfile.Write(buffer, 0, buffer.Length);
      unzippedfile.Close();
   }

   public static void CompressFile()
   {
      //Basisdatei lesen
      FileStream basefile = new FileStream(file, FileMode.Open);
      byte[] buffer = new byte[basefile.Length];
      int count = basefile.Read(buffer, 0, buffer.Length);
      basefile.Close();

      //Gezippte Datei schreiben
      FileStream zippedfile = new FileStream(zipfile, FileMode.Create);

      DeflateStream ds = new DeflateStream(zippedfile, CompressionMode.Compress);
      //GZipStream ds = new GZipStream(zippedfile, CompressionMode.Compress);
      ds.Write(buffer, 0, buffer.Length);
      ds.Close();
      zippedfile.Close();
   }
   public static void Main(string[] args)
   {
      File.Delete(file);
      File.Delete(unzipfile);
      File.Delete(zipfile);

      FileStream fs = new FileStream(file, FileMode.Append);
      StreamWriter sw = new StreamWriter(fs);
      for (int i = 0; i < 1000; i++)
      {
         sw.Write("Text in Datei");
      }
      sw.Close();
      fs.Close();

      CompressFile();
      DecompressFile();

      Console.WriteLine("Fertig");
      Console.ReadLine();
   }
}