ICSharpCode::SharpZipLib::Zip::ZipOutputStream Class Reference

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. More...

Inheritance diagram for ICSharpCode::SharpZipLib::Zip::ZipOutputStream:

ICSharpCode::SharpZipLib::Zip::Compression::Streams::DeflaterOutputStream List of all members.

Public Member Functions

 ZipOutputStream (Stream baseOutputStream)
 Creates a new Zip output stream, writing a zip archive.
void SetComment (string comment)
 Set the zip file comment.
void SetLevel (int level)
 Sets default compression level. The new level will be activated immediately.
int GetLevel ()
 Get the current deflate compression level.
void PutNextEntry (ZipEntry entry)
 Starts a new Zip entry. It automatically closes the previous entry if present. All entry elements bar name are optional, but must be correct if present. If the compression method is stored and the output is not patchable the compression for that entry is automatically changed to deflate level 0.
void CloseEntry ()
 Closes the current entry, updating header and footer information as required.
override void Write (byte[] b, int off, int len)
 Writes the given buffer to the current entry.
override void Finish ()
 Finishes the stream. This will write the central directory at the end of the zip file and flush the stream.

Properties

bool IsFinished
 Gets boolean indicating central header has been added for this archive... No further entries can be added once this has been done.
bool patchEntryHeader = false
long headerPatchPos = -1

Private Member Functions

void WriteLeShort (int value)
 Write an unsigned short in little endian byte order.
void WriteLeInt (int value)
 Write an int in little endian byte order.
void WriteLeLong (long value)
 Write an int in little endian byte order.
void WriteEncryptionHeader (long crcValue)

Private Attributes

ArrayList entries = new ArrayList()
Crc32 crc = new Crc32()
ZipEntry curEntry = null
int defaultCompressionLevel = Deflater.DEFAULT_COMPRESSION
CompressionMethod curMethod = CompressionMethod.Deflated
long size
long offset = 0
byte[] zipComment = new byte[0]

Detailed Description

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

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();
                }
            }   

Definition at line 99 of file ZipOutputStream.cs.


Constructor & Destructor Documentation

ICSharpCode::SharpZipLib::Zip::ZipOutputStream::ZipOutputStream Stream  baseOutputStream  )  [inline]
 

Creates a new Zip output stream, writing a zip archive.

Parameters:
baseOutputStream The output stream to which the archive contents are written.

Definition at line 130 of file ZipOutputStream.cs.


Member Function Documentation

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::CloseEntry  )  [inline]
 

Closes the current entry, updating header and footer information as required.

Exceptions:
System.IO.IOException An I/O error occurs.
System.InvalidOperationException No entry is active.

Definition at line 374 of file ZipOutputStream.cs.

override void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::Finish  )  [inline, virtual]
 

Finishes the stream. This will write the central directory at the end of the zip file and flush the stream.

This is automatically called when the stream is closed.

Exceptions:
System.IO.IOException An I/O error occurs.
ZipException Comment exceeds the maximum length
Entry name exceeds the maximum length

Reimplemented from ICSharpCode::SharpZipLib::Zip::Compression::Streams::DeflaterOutputStream.

Definition at line 512 of file ZipOutputStream.cs.

int ICSharpCode::SharpZipLib::Zip::ZipOutputStream::GetLevel  )  [inline]
 

Get the current deflate compression level.

Returns:
The current compression level

Definition at line 170 of file ZipOutputStream.cs.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::PutNextEntry ZipEntry  entry  )  [inline]
 

Starts a new Zip entry. It automatically closes the previous entry if present. All entry elements bar name are optional, but must be correct if present. If the compression method is stored and the output is not patchable the compression for that entry is automatically changed to deflate level 0.

Parameters:
entry the entry.
Exceptions:
System.IO.IOException if an I/O error occured.
System.InvalidOperationException if stream was finished
ZipException Too many entries in the Zip file
Entry name is too long
Finish has already been called

Definition at line 228 of file ZipOutputStream.cs.

References ICSharpCode::SharpZipLib::Zip::ZipEntry::CompressedSize, ICSharpCode::SharpZipLib::Zip::ZipEntry::CompressionMethod, ICSharpCode::SharpZipLib::Zip::ZipEntry::Crc, ICSharpCode::SharpZipLib::Zip::ZipEntry::DosTime, ICSharpCode::SharpZipLib::Zip::ZipEntry::ExtraData, ICSharpCode::SharpZipLib::Zip::ZipEntry::Flags, ICSharpCode::SharpZipLib::Zip::ZipEntry::IsCrypted, ICSharpCode::SharpZipLib::Zip::ZipEntry::Name, ICSharpCode::SharpZipLib::Zip::ZipEntry::Offset, ICSharpCode::SharpZipLib::Zip::ZipEntry::Size, and ICSharpCode::SharpZipLib::Zip::ZipEntry::Version.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::SetComment string  comment  )  [inline]
 

Set the zip file comment.

Parameters:
comment The comment string
Encoding of comment is longer than 0xffff bytes.

Definition at line 143 of file ZipOutputStream.cs.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::SetLevel int  level  )  [inline]
 

Sets default compression level. The new level will be activated immediately.

Exceptions:
ArgumentOutOfRangeException Level specified is not supported.
Deflater

Definition at line 160 of file ZipOutputStream.cs.

override void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::Write byte[]  b,
int  off,
int  len
[inline]
 

Writes the given buffer to the current entry.

Exceptions:
ZipException Archive size is invalid
System.InvalidOperationException No entry is active.

Reimplemented from ICSharpCode::SharpZipLib::Zip::Compression::Streams::DeflaterOutputStream.

Definition at line 463 of file ZipOutputStream.cs.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::WriteEncryptionHeader long  crcValue  )  [inline, private]
 

Definition at line 439 of file ZipOutputStream.cs.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::WriteLeInt int  value  )  [inline, private]
 

Write an int in little endian byte order.

Definition at line 187 of file ZipOutputStream.cs.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::WriteLeLong long  value  )  [inline, private]
 

Write an int in little endian byte order.

Definition at line 196 of file ZipOutputStream.cs.

void ICSharpCode::SharpZipLib::Zip::ZipOutputStream::WriteLeShort int  value  )  [inline, private]
 

Write an unsigned short in little endian byte order.

Definition at line 178 of file ZipOutputStream.cs.


Member Data Documentation

Crc32 ICSharpCode::SharpZipLib::Zip::ZipOutputStream::crc = new Crc32() [private]
 

Definition at line 102 of file ZipOutputStream.cs.

ZipEntry ICSharpCode::SharpZipLib::Zip::ZipOutputStream::curEntry = null [private]
 

Definition at line 103 of file ZipOutputStream.cs.

CompressionMethod ICSharpCode::SharpZipLib::Zip::ZipOutputStream::curMethod = CompressionMethod.Deflated [private]
 

Definition at line 106 of file ZipOutputStream.cs.

int ICSharpCode::SharpZipLib::Zip::ZipOutputStream::defaultCompressionLevel = Deflater.DEFAULT_COMPRESSION [private]
 

Definition at line 105 of file ZipOutputStream.cs.

ArrayList ICSharpCode::SharpZipLib::Zip::ZipOutputStream::entries = new ArrayList() [private]
 

Definition at line 101 of file ZipOutputStream.cs.

long ICSharpCode::SharpZipLib::Zip::ZipOutputStream::offset = 0 [private]
 

Definition at line 110 of file ZipOutputStream.cs.

long ICSharpCode::SharpZipLib::Zip::ZipOutputStream::size [private]
 

Definition at line 109 of file ZipOutputStream.cs.

byte [] ICSharpCode::SharpZipLib::Zip::ZipOutputStream::zipComment = new byte[0] [private]
 

Definition at line 112 of file ZipOutputStream.cs.


Property Documentation

long ICSharpCode::SharpZipLib::Zip::ZipOutputStream::headerPatchPos = -1 [private]
 

Definition at line 205 of file ZipOutputStream.cs.

bool ICSharpCode::SharpZipLib::Zip::ZipOutputStream::IsFinished [get]
 

Gets boolean indicating central header has been added for this archive... No further entries can be added once this has been done.

Definition at line 118 of file ZipOutputStream.cs.

bool ICSharpCode::SharpZipLib::Zip::ZipOutputStream::patchEntryHeader = false [private]
 

Definition at line 203 of file ZipOutputStream.cs.


The documentation for this class was generated from the following file:
Generated on Fri Jun 23 21:50:07 2006 for OblivionModTranslator by  doxygen 1.4.6-NO