ZipOutputStream Class

SharpZip Compression Library

SharpZip Compression Library

ZipOutputStream Class

This is a DeflaterOutputStream that writes the files into a zip archive one after another. It has a special method to start a new zip entry. The zip entries contains information about the file name size, compressed size, CRC, etc. It includes support for Stored and Deflated entries. This class is not thread safe.

Author of the original java version : Jochen Hoenicke

For a list of all members of this type, see ZipOutputStream Members.

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
            ICSharpCode.SharpZipLib.Zip.ZipOutputStream

public class ZipOutputStream : DeflaterOutputStream

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Example

This sample shows how to create a zip file

using System;
using System.IO;

using ICSharpCode.SharpZipLib.Zip;

class MainClass
{
    public static void Main(string[] args)
    {
        string[] filenames = Directory.GetFiles(args[0]);
        
        ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
        
        s.SetLevel(5); // 0 - store only to 9 - means best compression
        
        foreach (string file in filenames) {
            FileStream fs = File.OpenRead(file);
            
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            
            ZipEntry entry = new ZipEntry(file);
            
            s.PutNextEntry(entry);
            
            s.Write(buffer, 0, buffer.Length);
            
        }
        
        s.Finish();
        s.Close();
    }
}    

Requirements

Namespace: ICSharpCode.SharpZipLib.Zip

Assembly: ICSharpCode.SharpZipLib (in ICSharpCode.SharpZipLib.dll)

See Also

ZipOutputStream Members | ICSharpCode.SharpZipLib.Zip Namespace