C# 클래스 Ionic.Zip.ZipOutputStream

Provides a stream metaphor for generating zip files.

This class provides an alternative programming model to the one enabled by the ZipFile class. Use this when creating zip files, as an alternative to the ZipFile class, when you would like to use a Stream class to write the zip file.

Some designs require a writable stream for output. This stream can be used to produce a zip file, as it is written.

Both the ZipOutputStream class and the ZipFile class can be used to create zip files. Both of them support many of the common zip features, including Unicode, different compression levels, and ZIP64. For example, when creating a zip file via calls to the PutNextEntry() and Write() methods on the ZipOutputStream class, the caller is responsible for opening the file, reading the bytes from the file, writing those bytes into the ZipOutputStream, setting the attributes on the ZipEntry, and setting the created, last modified, and last accessed timestamps on the zip entry. All of these things are done automatically by a call to ZipFile.AddFile(). For this reason, the ZipOutputStream is generally recommended for when your application wants to emit the arbitrary data, not necessarily data from a filesystem file, directly into a zip file.

Aside from the differences in programming model, there are other differences in capability between the two classes.

ZipFile can be used to read and extract zip files, in addition to creating zip files. ZipOutputStream cannot read zip files. If you want to use a stream to read zip files, check out the ZipInputStream class. ZipOutputStream does not support the creation of segmented or spanned zip files. ZipOutputStream cannot produce a self-extracting archive.
상속: Stream
파일 보기 프로젝트 열기: puckipedia/MagisterAPI 1 사용 예제들

Private Properties

프로퍼티 타입 설명
InsureUniqueEntry void
_FinishCurrentEntry void
_Init void
_InitiateCurrentEntry void

공개 메소드들

메소드 설명
ContainsEntry ( string name ) : bool

Returns true if an entry by the given name has already been written to the ZipOutputStream.

Flush ( ) : void

This is a no-op.

PutNextEntry ( String entryName ) : ZipEntry

Specify the name of the next entry that will be written to the zip file.

Call this method just before calling Write(byte[], int, int), to specify the name of the entry that the next set of bytes written to the ZipOutputStream belongs to. All subsequent calls to Write, until the next call to PutNextEntry, will be inserted into the named entry in the zip file.

If the entryName used in PutNextEntry() ends in a slash, then the entry added is marked as a directory. Because directory entries do not contain data, a call to Write(), before an intervening additional call to PutNextEntry(), will throw an exception.

If you don't call Write() between two calls to PutNextEntry(), the first entry is inserted into the zip file as a file of zero size. This may be what you want.

Because PutNextEntry() closes out the prior entry, if any, this method may throw if there is a problem with the prior entry.

This method returns the ZipEntry. You can modify public properties on the ZipEntry, such as ZipEntry.Encryption, , and so on, until the first call to ZipOutputStream.Write(), or until the next call to PutNextEntry(). If you modify the ZipEntry after having called Write(), you may get a runtime exception, or you may silently get an invalid zip archive.

Read ( byte buffer, int offset, int count ) : int

This method always throws a NotSupportedException.

Seek ( long offset, SeekOrigin origin ) : long

This method always throws a NotSupportedException.

SetLength ( long value ) : void

This method always throws a NotSupportedException.

ToString ( ) : String

Provides a string representation of the instance.

This can be useful for debugging purposes.

Write ( byte buffer, int offset, int count ) : void

Write the data from the buffer to the stream.

As the application writes data into this stream, the data may be compressed and encrypted before being written out to the underlying stream, depending on the settings of the CompressionLevel and the Encryption properties.

ZipOutputStream ( Stream stream ) : System

Create a ZipOutputStream, wrapping an existing stream.

The ZipFile class is generally easier to use when creating zip files. The ZipOutputStream offers a different metaphor for creating a zip file, based on the System.IO.Stream class.

ZipOutputStream ( Stream stream, bool leaveOpen ) : System

Create a ZipOutputStream.

See the documentation for the ZipOutputStream(Stream) constructor for an example.

ZipOutputStream ( String fileName ) : System

Create a ZipOutputStream that writes to a filesystem file.

The ZipFile class is generally easier to use when creating zip files. The ZipOutputStream offers a different metaphor for creating a zip file, based on the System.IO.Stream class.

보호된 메소드들

메소드 설명
Dispose ( bool disposing ) : void

Dispose the stream

This method writes the Zip Central directory, then closes the stream. The application must call Dispose() (or Close) in order to produce a valid zip file.

Typically the application will call Dispose() implicitly, via a using statement in C#, or a Using statement in VB.

비공개 메소드들

메소드 설명
InsureUniqueEntry ( ZipEntry ze1 ) : void
_FinishCurrentEntry ( ) : void
_Init ( Stream stream, bool leaveOpen, string name ) : void
_InitiateCurrentEntry ( bool finishing ) : void

메소드 상세

ContainsEntry() 공개 메소드

Returns true if an entry by the given name has already been written to the ZipOutputStream.
public ContainsEntry ( string name ) : bool
name string /// The name of the entry to scan for. ///
리턴 bool

Dispose() 보호된 메소드

Dispose the stream

This method writes the Zip Central directory, then closes the stream. The application must call Dispose() (or Close) in order to produce a valid zip file.

Typically the application will call Dispose() implicitly, via a using statement in C#, or a Using statement in VB.

protected Dispose ( bool disposing ) : void
disposing bool set this to true, always.
리턴 void

Flush() 공개 메소드

This is a no-op.
public Flush ( ) : void
리턴 void

PutNextEntry() 공개 메소드

Specify the name of the next entry that will be written to the zip file.

Call this method just before calling Write(byte[], int, int), to specify the name of the entry that the next set of bytes written to the ZipOutputStream belongs to. All subsequent calls to Write, until the next call to PutNextEntry, will be inserted into the named entry in the zip file.

If the entryName used in PutNextEntry() ends in a slash, then the entry added is marked as a directory. Because directory entries do not contain data, a call to Write(), before an intervening additional call to PutNextEntry(), will throw an exception.

If you don't call Write() between two calls to PutNextEntry(), the first entry is inserted into the zip file as a file of zero size. This may be what you want.

Because PutNextEntry() closes out the prior entry, if any, this method may throw if there is a problem with the prior entry.

This method returns the ZipEntry. You can modify public properties on the ZipEntry, such as ZipEntry.Encryption, , and so on, until the first call to ZipOutputStream.Write(), or until the next call to PutNextEntry(). If you modify the ZipEntry after having called Write(), you may get a runtime exception, or you may silently get an invalid zip archive.

public PutNextEntry ( String entryName ) : ZipEntry
entryName String /// The name of the entry to be added, including any path to be used /// within the zip file. ///
리턴 ZipEntry

Read() 공개 메소드

This method always throws a NotSupportedException.
public Read ( byte buffer, int offset, int count ) : int
buffer byte ignored
offset int ignored
count int ignored
리턴 int

Seek() 공개 메소드

This method always throws a NotSupportedException.
public Seek ( long offset, SeekOrigin origin ) : long
offset long ignored
origin SeekOrigin ignored
리턴 long

SetLength() 공개 메소드

This method always throws a NotSupportedException.
public SetLength ( long value ) : void
value long ignored
리턴 void

ToString() 공개 메소드

Provides a string representation of the instance.

This can be useful for debugging purposes.

public ToString ( ) : String
리턴 String

Write() 공개 메소드

Write the data from the buffer to the stream.
As the application writes data into this stream, the data may be compressed and encrypted before being written out to the underlying stream, depending on the settings of the CompressionLevel and the Encryption properties.
public Write ( byte buffer, int offset, int count ) : void
buffer byte The buffer holding data to write to the stream.
offset int the offset within that data array to find the first byte to write.
count int the number of bytes to write.
리턴 void

ZipOutputStream() 공개 메소드

Create a ZipOutputStream, wrapping an existing stream.

The ZipFile class is generally easier to use when creating zip files. The ZipOutputStream offers a different metaphor for creating a zip file, based on the System.IO.Stream class.

public ZipOutputStream ( Stream stream ) : System
stream Stream /// The stream to wrap. It must be writable. This stream will be closed at /// the time the ZipOutputStream is closed. ///
리턴 System

ZipOutputStream() 공개 메소드

Create a ZipOutputStream.
See the documentation for the ZipOutputStream(Stream) constructor for an example.
public ZipOutputStream ( Stream stream, bool leaveOpen ) : System
stream Stream /// The stream to wrap. It must be writable. ///
leaveOpen bool /// true if the application would like the stream /// to remain open after the ZipOutputStream has been closed. ///
리턴 System

ZipOutputStream() 공개 메소드

Create a ZipOutputStream that writes to a filesystem file.
The ZipFile class is generally easier to use when creating zip files. The ZipOutputStream offers a different metaphor for creating a zip file, based on the System.IO.Stream class.
public ZipOutputStream ( String fileName ) : System
fileName String /// The name of the zip file to create. ///
리턴 System