using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Compression;

public partial class GZIPTestForm1 : Form
{
    private String currentDir = Directory.GetCurrentDirectory();

    public GZIPTestForm1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        openFileDialog1.Filter = "txt files |*.txt";
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
                FileStream source = File.OpenRead(openFileDialog1.FileName);
                FileStream destination = File.Create(currentDir+"\\stream.txt");
                GZipStream myCompressionStream = new GZipStream(destination, CompressionMode.Compress);

                byte[] bytes = new byte[10];
                int n;

                while((n = source.Read(bytes, 0, bytes.Length)) != 0) 
                    myCompressionStream.Write(bytes, 0, n);

                destination.Close();
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
            FileStream dest2 = File.OpenRead(currentDir + "\\stream.txt");
            GZipStream myDecompressionStream = new GZipStream(dest2, CompressionMode.Decompress);
            FileStream extractedFile = File.Create(currentDir + "\\decompressed.txt");
            
            byte[] bytes = new byte[10];
            int n;

            while((n = myDecompressionStream.Read(bytes, 0, bytes.Length)) != 0)
            while ((n = dest2.Read(bytes, 0, bytes.Length)) != 0)
                extractedFile.Write(bytes, 0, n);

            extractedFile.Close();
    }
}