01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.ComponentModel;
04.
using
System.Data;
05.
using
System.Drawing;
06.
using
System.Text;
07.
using
System.IO;
08.
using
System.IO.Compression;
09.
using
System.Windows.Forms;
10.
11.
namespace
Zipping
12.
{
13.
public
partial
class
Form1 : Form
14.
{
15.
public
Form1()
16.
{
17.
InitializeComponent();
18.
}
19.
20.
private
void
btnBrowse_Click(
object
sender, EventArgs e)
21.
{
22.
23.
if
(openFile.ShowDialog() == DialogResult.OK)
24.
{
25.
txtPath.Text = openFile.FileName;
26.
}
27.
}
28.
29.
private
void
btnCompress_Click(
object
sender, EventArgs e)
30.
{
31.
32.
if
(saveFile.ShowDialog() == DialogResult.OK)
33.
{
34.
35.
byte
[] bufferWrite;
36.
37.
FileStream fsSource;
38.
39.
FileStream fsDest;
40.
GZipStream gzCompressed;
41.
fsSource =
new
FileStream(txtPath.Text, FileMode.Open, FileAccess.Read, FileShare.Read);
42.
43.
bufferWrite =
new
byte
[fsSource.Length];
44.
45.
fsSource.Read(bufferWrite, 0, bufferWrite.Length);
46.
47.
fsDest =
new
FileStream(saveFile.FileName, FileMode.OpenOrCreate, FileAccess.Write);
48.
49.
50.
gzCompressed =
new
GZipStream(fsDest, CompressionMode.Compress,
true
);
51.
52.
53.
gzCompressed.Write(bufferWrite, 0, bufferWrite.Length);
54.
55.
56.
fsSource.Close();
57.
gzCompressed.Close();
58.
fsDest.Close();
59.
}
60.
}
61.
}
62.
}