Fingerprint_Card

Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for ICSharpCode.SharpZipLib.Zip.ZipOutputStream:
[legend]

## Public Member Functions
| ZipOutputStream (Stream baseOutputStream)
| Creates a new Zip output stream, writing a zip archive.
| ZipOutputStream (Stream baseOutputStream, int bufferSize)
| Creates a new Zip output stream, writing a zip archive.
void | SetComment (string comment)
| Set the zip file comment.
void | SetLevel (int level)
| Sets the compression level. The new level will be activated immediately.
int | GetLevel ()
| Get the current deflater 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[] buffer, int offset, int count)
| 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.
Public Member Functions inherited from ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
| DeflaterOutputStream (Stream baseOutputStream)
| Creates a new DeflaterOutputStream with a default Deflater and default buffer size.
| DeflaterOutputStream (Stream baseOutputStream, Deflater deflater)
| Creates a new DeflaterOutputStream with the given Deflater and default buffer size.
| DeflaterOutputStream (Stream baseOutputStream, Deflater deflater, int bufferSize)
| Creates a new DeflaterOutputStream with the given Deflater and buffer size.
override long | Seek (long offset, SeekOrigin origin)
| Sets the current position of this stream to the given value. Not supported by this class!
override void | SetLength (long value)
| Sets the length of this stream to the given value. Not supported by this class!
override int | ReadByte ()
| Read a byte from stream advancing position by one.
override int | Read (byte[] buffer, int offset, int count)
| Read a block of bytes from stream.
override IAsyncResult | BeginRead (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
| Asynchronous reads are not supported a NotSupportedException is always thrown.
override IAsyncResult | BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
| Asynchronous writes arent supported, a NotSupportedException is always thrown.
override void | Flush ()
| Flushes the stream by calling Flush on the deflater and then on the underlying stream. This ensures that all bytes are flushed.
override void | Close ()
| Calls Finish and closes the underlying stream when IsStreamOwner is true.
override void | WriteByte (byte value)
| Writes a single byte to the compressed output stream.
override void | Write (byte[] buffer, int offset, int count)
| Writes bytes from an array to the compressed stream.

## Properties
bool | IsFinished`[get]`
| Gets a flag value of true if the central header has been added for this archive; false if it has not been added.
UseZip64 | UseZip64`[get, set]`
| Get / set a value indicating how Zip64 Extension usage is determined when adding entries.
Properties inherited from ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
bool | IsStreamOwner`[get, set]`
| Get/set flag indicating ownership of the underlying stream. When the flag is true Close will close the underlying stream also.
bool | CanPatchEntries`[get]`
| Allows client to determine if an entry can be patched after its added.
string | Password`[get, set]`
| Get/set the password used for encryption.
override bool | CanRead`[get]`
| Gets value indicating stream can be read from.
override bool | CanSeek`[get]`
| Gets a value indicating if seeking is supported for this stream This property always returns false.
override bool | CanWrite`[get]`
| Get value indicating if this stream supports writing.
override long | Length`[get]`
| Get current length of stream.
override long | Position`[get, set]`
| Gets the current position within the stream.

## 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)
void | WriteAESHeader (ZipEntry entry)
void | CopyAndEncrypt (byte[] buffer, int offset, int count)

## Static Private Member Functions
static void | AddExtraDataAES (ZipEntry entry, ZipExtraData extraData)

## Private Attributes
ArrayList | entries = new ArrayList()
| The entries for the archive.
Crc32 | crc = new Crc32()
| Used to track the crc of data added to entries.
ZipEntry | curEntry
| The current entry being added.
int | defaultCompressionLevel = Deflater.DEFAULT_COMPRESSION
CompressionMethod | curMethod = CompressionMethod.Deflated
long | size
| Used to track the size of data for an entry during writing.
long | offset
| Offset to be recorded for each entry in the central header.
byte[] | zipComment = new byte[0]
| Comment for the entire archive recorded in central header.
bool | patchEntryHeader
| Flag indicating that header patching is required for the current entry.
long | crcPatchPos = -1
| Position to patch crc.
long | sizePatchPos = -1
| Position to patch size.
UseZip64 | useZip64_ = UseZip64.Dynamic

## Additional Inherited Members
Protected Member Functions inherited from ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
void | EncryptBlock (byte[] buffer, int offset, int length)
| Encrypt a block of data.
void | InitializePassword (string password)
| Initializes encryption keys based on given password .
void | InitializeAESPassword (ZipEntry entry, string rawPassword, out byte[] salt, out byte[] pwdVerifier)
| Initializes encryption keys based on given password.
void | Deflate ()
| Deflates everything in the input buffers. This will call.
Protected Attributes inherited from ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream
byte[] | AESAuthCode
| Returns the 10 byte AUTH CODE to be appended immediately following the AES data stream.
Deflater | deflater_
| The deflater which is used to deflate the stream.
Stream | baseOutputStream_
| Base stream the deflater depends on.

## 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.Core;
using ICSharpCode.SharpZipLib.Zip;
class MainClass
{
public static void Main(string[] args)
{
string[] filenames = Directory.GetFiles(args[0]);
byte[] buffer = new byte[4096];
using ( ZipOutputStream s = new ZipOutputStream(File.Create(args[1])) ) {
@iverbatim
s.SetLevel(9); // 0 - store only to 9 - means best compression
foreach (string file in filenames) {
ZipEntry entry = new ZipEntry(file);
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file)) {
StreamUtils.Copy(fs, s, buffer);
}
}
@endiverbatim }
}
} <br>
File
Zwipe.Test.Tools.Entities.File File
Definition ExportsTest.cs:6
ICSharpCode.SharpZipLib.Core.StreamUtils
Provides simple Stream" utilities.
Definition StreamUtils.cs:45
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy
static void Copy(Stream source, Stream destination, byte[] buffer)
Copy the contents of one Stream to another.
Definition StreamUtils.cs:102
ICSharpCode.SharpZipLib.Zip.ZipEntry
This class represents an entry in a zip archive. This can be a file or a directory ZipFile and ZipInp...
Definition ZipEntry.cs:151
ICSharpCode.SharpZipLib.Zip.ZipOutputStream.ZipOutputStream
ZipOutputStream(Stream baseOutputStream)
Creates a new Zip output stream, writing a zip archive.
Definition ZipOutputStream.cs:106
ICSharpCode.SharpZipLib.Zip.ZipOutputStream.PutNextEntry
void PutNextEntry(ZipEntry entry)
Starts a new Zip entry. It automatically closes the previous entry if present. All entry elements bar...
Definition ZipOutputStream.cs:246
ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetLevel
void SetLevel(int level)
Sets the compression level. The new level will be activated immediately.
Definition ZipOutputStream.cs:161
ICSharpCode.SharpZipLib.Core
Definition FileSystemScanner.cs:40
ICSharpCode.SharpZipLib.Zip
Definition Deflater.cs:43

## Constructor & Destructor Documentation

## ◆ ZipOutputStream() [1/2]

ICSharpCode.SharpZipLib.Zip.ZipOutputStream.ZipOutputStream | ( | Stream | baseOutputStream | ) |

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

Parameters

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

## ◆ ZipOutputStream() [2/2]

ICSharpCode.SharpZipLib.Zip.ZipOutputStream.ZipOutputStream | ( | Stream | baseOutputStream,
|  | int | bufferSize )

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

Parameters

  baseOutputStream | The output stream to which the archive contents are written.
  bufferSize | Size of the buffer to use.

## Member Function Documentation

## ◆ AddExtraDataAES()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.AddExtraDataAES | ( | ZipEntry | entry,
|  | ZipExtraData | extraData )
| static private

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ CloseEntry()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.CloseEntry | ( |  | ) |

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.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ CopyAndEncrypt()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.CopyAndEncrypt | ( | byte[] | buffer,
|  | int | offset,
|  | int | count )
| private

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ Finish()

override void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.Finish | ( |  | ) |
| 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.

Here is the call graph for this function:

## ◆ GetLevel()

int ICSharpCode.SharpZipLib.Zip.ZipOutputStream.GetLevel | ( |  | ) |

Get the current deflater compression level.

Returns
  The current compression level

## ◆ PutNextEntry()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.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.

Parameters

  entry | the entry.

Exceptions

  System.ArgumentNullException | if entry passed is null.
  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

Here is the call graph for this function:

## ◆ SetComment()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetComment | ( | string | comment | ) |

Set the zip file comment.

Parameters

  comment | The comment text for the entire archive.

The converted comment is longer than 0xffff bytes.

Here is the call graph for this function:

## ◆ SetLevel()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetLevel | ( | int | level | ) |

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

Parameters

  level | The new compression level (1 to 9).

Exceptions

  ArgumentOutOfRangeException | Level specified is not supported.

ICSharpCode.SharpZipLib.Zip.Compression.Deflater

## ◆ Write()

override void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.Write | ( | byte[] | buffer,
|  | int | offset,
|  | int | count )

Writes the given buffer to the current entry.

Parameters

  buffer | The buffer containing data to write.
  offset | The offset of the first byte to write.
  count | The number of bytes to write.

Exceptions

  ZipException | Archive size is invalid
  System.InvalidOperationException | No entry is active.

Here is the call graph for this function:

## ◆ WriteAESHeader()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.WriteAESHeader | ( | ZipEntry | entry | ) |
| private

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ WriteEncryptionHeader()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.WriteEncryptionHeader | ( | long | crcValue | ) |
| private

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ WriteLeInt()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.WriteLeInt | ( | int | value | ) |
| private

Write an int in little endian byte order.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ WriteLeLong()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.WriteLeLong | ( | long | value | ) |
| private

Write an int in little endian byte order.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ WriteLeShort()

void ICSharpCode.SharpZipLib.Zip.ZipOutputStream.WriteLeShort | ( | int | value | ) |
| private

Write an unsigned short in little endian byte order.

Here is the caller graph for this function:

## Member Data Documentation

## ◆ crc

Crc32 ICSharpCode.SharpZipLib.Zip.ZipOutputStream.crc = new Crc32()
| private

Used to track the crc of data added to entries.

## ◆ crcPatchPos

long ICSharpCode.SharpZipLib.Zip.ZipOutputStream.crcPatchPos = -1
| private

Position to patch crc.

## ◆ curEntry

ZipEntry ICSharpCode.SharpZipLib.Zip.ZipOutputStream.curEntry
| private

The current entry being added.

## ◆ curMethod

CompressionMethod ICSharpCode.SharpZipLib.Zip.ZipOutputStream.curMethod = CompressionMethod.Deflated
| private

## ◆ defaultCompressionLevel

int ICSharpCode.SharpZipLib.Zip.ZipOutputStream.defaultCompressionLevel = Deflater.DEFAULT_COMPRESSION
| private

## ◆ entries

ArrayList ICSharpCode.SharpZipLib.Zip.ZipOutputStream.entries = new ArrayList()
| private

The entries for the archive.

## ◆ offset

long ICSharpCode.SharpZipLib.Zip.ZipOutputStream.offset
| private

Offset to be recorded for each entry in the central header.

## ◆ patchEntryHeader

bool ICSharpCode.SharpZipLib.Zip.ZipOutputStream.patchEntryHeader
| private

Flag indicating that header patching is required for the current entry.

## ◆ size

long ICSharpCode.SharpZipLib.Zip.ZipOutputStream.size
| private

Used to track the size of data for an entry during writing.

## ◆ sizePatchPos

long ICSharpCode.SharpZipLib.Zip.ZipOutputStream.sizePatchPos = -1
| private

Position to patch size.

## ◆ useZip64_

UseZip64 ICSharpCode.SharpZipLib.Zip.ZipOutputStream.useZip64_ = UseZip64.Dynamic
| private

## ◆ zipComment

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

Comment for the entire archive recorded in central header.

## Property Documentation

## ◆ IsFinished

bool ICSharpCode.SharpZipLib.Zip.ZipOutputStream.IsFinished
| get

Gets a flag value of true if the central header has been added for this archive; false if it has not been added.

No further entries can be added once this has been done.

## ◆ UseZip64

UseZip64 ICSharpCode.SharpZipLib.Zip.ZipOutputStream.UseZip64
| get set

Get / set a value indicating how Zip64 Extension usage is determined when adding entries.

Older archivers may not understand Zip64 extensions. If backwards compatability is an issue be careful when adding entries to an archive. Setting this property to off is workable but less desirable as in those circumstances adding a file larger then 4GB will fail.

The documentation for this class was generated from the following file:

- ICSharpCode.SharpZLib/Zip/ZipOutputStream.cs