C# Class Ionic.Zlib.ParallelDeflateOutputStream

A class for compressing streams using the Deflate algorithm with multiple threads.

This class performs DEFLATE compression through writing. For more information on the Deflate algorithm, see IETF RFC 1951, "DEFLATE Compressed Data Format Specification version 1.3."

This class is similar to Ionic.Zlib.DeflateStream, except that this class is for compression only, and this implementation uses an approach that employs multiple worker threads to perform the DEFLATE. On a multi-cpu or multi-core computer, the performance of this class can be significantly higher than the single-threaded DeflateStream, particularly for larger streams. How large? Anything over 10mb is a good candidate for parallel compression.

The tradeoff is that this class uses more memory and more CPU than the vanilla DeflateStream, and also is less efficient as a compressor. For large files the size of the compressed data stream can be less than 1% larger than the size of a compressed data stream from the vanialla DeflateStream. For smaller files the difference can be larger. The difference will also be larger if you set the BufferSize to be lower than the default value. Your mileage may vary. Finally, for small files, the ParallelDeflateOutputStream can be much slower than the vanilla DeflateStream, because of the overhead associated to using the thread pool.

Inheritance: System.IO.Stream
Mostrar archivo Open project: haf/DotNetZip.Semverd Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Close the stream.

You must call Close on the stream to guarantee that all of the data written in has been compressed, and the compressed data has been written out.

Dispose ( ) : void

Dispose the object

Because ParallelDeflateOutputStream is IDisposable, the application must call this method when finished using the instance.

This method is generally called implicitly upon exit from a using scope in C# (Using in VB).

Flush ( ) : void

Flush the stream.

ParallelDeflateOutputStream ( System stream ) : System

Create a ParallelDeflateOutputStream.

This stream compresses data written into it via the DEFLATE algorithm (see RFC 1951), and writes out the compressed byte stream.

The instance will use the default compression level, the default buffer sizes and the default number of threads and buffers per thread.

This class is similar to Ionic.Zlib.DeflateStream, except that this implementation uses an approach that employs multiple worker threads to perform the DEFLATE. On a multi-cpu or multi-core computer, the performance of this class can be significantly higher than the single-threaded DeflateStream, particularly for larger streams. How large? Anything over 10mb is a good candidate for parallel compression.

ParallelDeflateOutputStream ( System stream, CompressionLevel level ) : System

Create a ParallelDeflateOutputStream using the specified CompressionLevel.

See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.

ParallelDeflateOutputStream ( System stream, CompressionLevel level, CompressionStrategy strategy, bool leaveOpen ) : System

Create a ParallelDeflateOutputStream using the specified CompressionLevel and CompressionStrategy, and specifying whether to leave the captive stream open when the ParallelDeflateOutputStream is closed.

See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.

ParallelDeflateOutputStream ( System stream, CompressionLevel level, bool leaveOpen ) : System

Create a ParallelDeflateOutputStream and specify whether to leave the captive stream open when the ParallelDeflateOutputStream is closed.

See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.

ParallelDeflateOutputStream ( System stream, bool leaveOpen ) : System

Create a ParallelDeflateOutputStream and specify whether to leave the captive stream open when the ParallelDeflateOutputStream is closed.

See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.

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

This method always throws a NotSupportedException.

Reset ( Stream stream ) : void

Resets the stream for use with another stream.

Because the ParallelDeflateOutputStream is expensive to create, it has been designed so that it can be recycled and re-used. You have to call Close() on the stream first, then you can call Reset() on it, to use it again on another stream.

Seek ( long offset, System origin ) : long

This method always throws a NotSupportedException.

SetLength ( long value ) : void

This method always throws a NotSupportedException.

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

Write data to the stream.

To use the ParallelDeflateOutputStream to compress data, create a ParallelDeflateOutputStream with CompressionMode.Compress, passing a writable output stream. Then call Write() on that ParallelDeflateOutputStream, providing uncompressed data as input. The data sent to the output stream will be the compressed form of the data written.

To decompress data, use the Ionic.Zlib.DeflateStream class.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

The Dispose method

Private Methods

Method Description
DeflateOneSegment ( WorkItem workitem ) : bool
EmitPendingBuffers ( bool doAll, bool mustWait ) : void
InnerClose ( ) : void
TraceOutput ( TraceBits bits, string format ) : void
_DeflateOne ( Object wi ) : void
_Flush ( bool lastInput ) : void
_FlushFinish ( ) : void
_InitializePoolOfWorkItems ( ) : void
_PerpetualWriterMethod ( object state ) : void

Method Details

Close() public method

Close the stream.
You must call Close on the stream to guarantee that all of the data written in has been compressed, and the compressed data has been written out.
public Close ( ) : void
return void

Dispose() public method

Dispose the object

Because ParallelDeflateOutputStream is IDisposable, the application must call this method when finished using the instance.

This method is generally called implicitly upon exit from a using scope in C# (Using in VB).

public Dispose ( ) : void
return void

Dispose() protected method

The Dispose method
protected Dispose ( bool disposing ) : void
disposing bool /// indicates whether the Dispose method was invoked by user code. ///
return void

Flush() public method

Flush the stream.
public Flush ( ) : void
return void

ParallelDeflateOutputStream() public method

Create a ParallelDeflateOutputStream.

This stream compresses data written into it via the DEFLATE algorithm (see RFC 1951), and writes out the compressed byte stream.

The instance will use the default compression level, the default buffer sizes and the default number of threads and buffers per thread.

This class is similar to Ionic.Zlib.DeflateStream, except that this implementation uses an approach that employs multiple worker threads to perform the DEFLATE. On a multi-cpu or multi-core computer, the performance of this class can be significantly higher than the single-threaded DeflateStream, particularly for larger streams. How large? Anything over 10mb is a good candidate for parallel compression.

public ParallelDeflateOutputStream ( System stream ) : System
stream System The stream to which compressed data will be written.
return System

ParallelDeflateOutputStream() public method

Create a ParallelDeflateOutputStream using the specified CompressionLevel.
See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.
public ParallelDeflateOutputStream ( System stream, CompressionLevel level ) : System
stream System The stream to which compressed data will be written.
level CompressionLevel A tuning knob to trade speed for effectiveness.
return System

ParallelDeflateOutputStream() public method

Create a ParallelDeflateOutputStream using the specified CompressionLevel and CompressionStrategy, and specifying whether to leave the captive stream open when the ParallelDeflateOutputStream is closed.
See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.
public ParallelDeflateOutputStream ( System stream, CompressionLevel level, CompressionStrategy strategy, bool leaveOpen ) : System
stream System The stream to which compressed data will be written.
level CompressionLevel A tuning knob to trade speed for effectiveness.
strategy CompressionStrategy /// By tweaking this parameter, you may be able to optimize the compression for /// data with particular characteristics. ///
leaveOpen bool /// true if the application would like the stream to remain open after inflation/deflation. ///
return System

ParallelDeflateOutputStream() public method

Create a ParallelDeflateOutputStream and specify whether to leave the captive stream open when the ParallelDeflateOutputStream is closed.
See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.
public ParallelDeflateOutputStream ( System stream, CompressionLevel level, bool leaveOpen ) : System
stream System The stream to which compressed data will be written.
level CompressionLevel A tuning knob to trade speed for effectiveness.
leaveOpen bool /// true if the application would like the stream to remain open after inflation/deflation. ///
return System

ParallelDeflateOutputStream() public method

Create a ParallelDeflateOutputStream and specify whether to leave the captive stream open when the ParallelDeflateOutputStream is closed.
See the ParallelDeflateOutputStream(System.IO.Stream) constructor for example code.
public ParallelDeflateOutputStream ( System stream, bool leaveOpen ) : System
stream System The stream to which compressed data will be written.
leaveOpen bool /// true if the application would like the stream to remain open after inflation/deflation. ///
return System

Read() public method

This method always throws a NotSupportedException.
public Read ( byte buffer, int offset, int count ) : int
buffer byte /// The buffer into which data would be read, IF THIS METHOD /// ACTUALLY DID ANYTHING. ///
offset int /// The offset within that data array at which to insert the /// data that is read, IF THIS METHOD ACTUALLY DID /// ANYTHING. ///
count int /// The number of bytes to write, IF THIS METHOD ACTUALLY DID /// ANYTHING. ///
return int

Reset() public method

Resets the stream for use with another stream.
Because the ParallelDeflateOutputStream is expensive to create, it has been designed so that it can be recycled and re-used. You have to call Close() on the stream first, then you can call Reset() on it, to use it again on another stream.
public Reset ( Stream stream ) : void
stream Stream /// The new output stream for this era. ///
return void

Seek() public method

This method always throws a NotSupportedException.
public Seek ( long offset, System origin ) : long
offset long /// The offset to seek to.... /// IF THIS METHOD ACTUALLY DID ANYTHING. ///
origin System /// The reference specifying how to apply the offset.... IF /// THIS METHOD ACTUALLY DID ANYTHING. ///
return long

SetLength() public method

This method always throws a NotSupportedException.
public SetLength ( long value ) : void
value long /// The new value for the stream length.... IF /// THIS METHOD ACTUALLY DID ANYTHING. ///
return void

Write() public method

Write data to the stream.

To use the ParallelDeflateOutputStream to compress data, create a ParallelDeflateOutputStream with CompressionMode.Compress, passing a writable output stream. Then call Write() on that ParallelDeflateOutputStream, providing uncompressed data as input. The data sent to the output stream will be the compressed form of the data written.

To decompress data, use the Ionic.Zlib.DeflateStream class.

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.
return void