Home
Manage Your Code
Snippet: Using ZIPLIB (C#)
Title: Using ZIPLIB Language: C#
Description: How to use the ziplib on the fly Views: 146
Author: Tim Waters Date Added: 5/27/2008
Copy Code  
1using System;
2using System.IO;
3
4using ICSharpCode.SharpZipLib.Core;
5using ICSharpCode.SharpZipLib.Zip;
6
7class MainClass
8{
9    public static void Main(string[] args)
10    {
11        string[] filenames = Directory.GetFiles(args[0]);
12        byte[] buffer = new byte[4096];
13
14        using ( ZipOutputStream s = new ZipOutputStream(File.Create(args[1])) ) {
15
16            s.SetLevel(9); // 0 - store only to 9 - means best compression

17
18            foreach (string file in filenames) {
19                ZipEntry entry = new ZipEntry(file);
20                s.PutNextEntry(entry);
21
22                using (FileStream fs = File.OpenRead(file)) {
23                    StreamUtils.Copy(fs, s, buffer);
24                }
25            }
26        }
27    }
28}
29