ZipStream Class
Properties Methods Events Configuration Settings Errors
The ZipStream class is used to perform compression or decompression.
Syntax
ZipStream
Remarks
The ZipStream class provides a way to compress and decompress streamed data.
Data may be operated on in multiple ways as discussed below. The StreamFormat property specifies the algorithm to us. Possible values are:
- Deflate
- Zlib
- Gzip
CompressBlock and DecompressBlock
The CompressBlock and DecompressBlock methods operate on blocks (chunks) of data. The methods may be used to compress and decompress data as it becomes available.
Note that when using blocks of data the OutputData property is not applicable. Instead data is made available through the CompressedData and DecompressedData events.
If all data is available ahead of time CompressData and DecompressData may be called instead.
Compress Data
Set InputData to the current block to be compressed. Next call CompressBlock to compress the current block. Note that CompressBlock takes a LastBlock parameter. If the block of data is the final block to be compressed set this to True. For all other blocks set this to False.
During compression the CompressedData event will fire with the compressed data. Note that this event may not fire for every call to CompressBlock due to the way the compression algorithm operates. For example:
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressBlock();
Data is accumulated inside the CompressedData event:
private static void Zipstream_OnCompressedData(object sender, ZipstreamCompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that OutputData is not applicable when compressing block data.
Decompress Data
Set InputData to the current block to be decompressed. Next call DecompressBlock to decompress the current block.
During decompression the DecompressedData event will fire with the decompressed data. Note that this event may not fire for every call to DecompressBlock due to the way the decompression algorithm operates. For example:
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressBlock();
Data is accumulated inside the DecompressedData event:
private static void Zipstream_OnDecompressedData(object sender, ZipstreamDecompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that OutputData is not applicable when decompressing block data.
CompressData and DecompressData
The CompressData and DecompressData methods operate on the complete blob of data. The entire compressed or decompressed data must be set to InputData before calling either method.
To compress and decompress data in blocks (chunks) see CompressBlock and DecompressBlock.
Compress Data
Set InputData to the decompressed data. This should be the entire data to be compressed. Next call CompressData. After compression OutputData will hold the compressed data. For example:
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressData();
MyCompressedData = zipstream.OutputDataB;
In addition to OutputData, the compressed data may also be accumulated within the CompressedData event.
Decompress Data
Set InputData to the compressed data. This should be the entire data to be decompressed. Next call DecompressData. After decompression OutputData will hold the decompressed data. For example:
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressData();
MyDecompressedData = zipstream.OutputDataB;
In addition to OutputData, the compressed data may also be accumulated within the DecompressedData event.
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
CompressionLevel | The compression level to use. |
InputData | Specifies the data to compress or decompress. |
OutputData | The output data after compression or decompression. |
StreamFormat | The stream format to use. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
CompressBlock | Compresses a block of data. |
CompressData | Compresses the specified data. |
Config | Sets or retrieves a configuration setting. |
DecompressBlock | Decompresses a block of data. |
DecompressData | Decompresses the specified data. |
Reset | Resets the class. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
CompressedData | This event fires with compressed data. |
DecompressedData | This event fires with decompressed data. |
Error | Information about errors during data delivery. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
UseInternalSecurityAPI | Tells the class whether or not to use the system security libraries or an internal implementation. |
CompressionLevel Property (ZipStream Class)
The compression level to use.
Syntax
int GetCompressionLevel();
int SetCompressionLevel(int iCompressionLevel);
Default Value
4
Remarks
The compression level to use, from 1 to 6. Higher values will cause the component to compress better; lower values will cause the component to compress faster.
When GetCompressionStream is invoked the stream will be created with the specified compression level. After a stream has been created it is independent of the control, and changing CompressionLevel will have no effect on existing streams.
Data Type
Integer
InputData Property (ZipStream Class)
Specifies the data to compress or decompress.
Syntax
QByteArray GetInputData();
int SetInputData(QByteArray qbaInputData);
Default Value
""
Remarks
This property specifies the data to compress or decompress.
When decompressing this should be set to the compressed data before calling DecompressData or DecompressBlock.
When compressing this should be set to the decompressed data before calling CompressData or CompressBlock.
Data Type
Byte Array
OutputData Property (ZipStream Class)
The output data after compression or decompression.
Syntax
QByteArray GetOutputData();
Default Value
""
Remarks
This property holds the compressed or decompressed data after CompressData or DecompressData is called.
This property is not applicable when calling CompressBlock or DecompressBlock.
This property is read-only and not available at design time.
Data Type
Byte Array
StreamFormat Property (ZipStream Class)
The stream format to use.
Syntax
int GetStreamFormat();
int SetStreamFormat(int iStreamFormat);
Possible Values
SF_DEFLATE(0),
SF_ZLIB(1),
SF_GZIP(2)
Default Value
0
Remarks
The stream format to use, by default Deflate.
All three stream formats use the Deflate algorithm specified in RFC 1951, which is the same algorithm used by Zip. The Zlib stream format adds a two-byte header and an Adler-32 checksum; the Gzip format adds a longer header and a CRC checksum, and is identical to the Gzip file format.
Caution: The terms zlib and deflate are sometimes used interchangeably (which is technically incorrect).
Data Type
Integer
CompressBlock Method (ZipStream Class)
Compresses a block of data.
Syntax
int CompressBlock(bool bLastBlock);
Remarks
This method compresses the block of data specified by InputData.
The CompressBlock and DecompressBlock methods operate on blocks (chunks) of data. The methods may be used to compress and decompress data as it becomes available.
Note that when using blocks of data the OutputData property is not applicable. Instead data is made available through the CompressedData and DecompressedData events.
If all data is available ahead of time CompressData and DecompressData may be called instead.
Compress Data
Set InputData to the current block to be compressed. Next call CompressBlock to compress the current block. Note that CompressBlock takes a LastBlock parameter. If the block of data is the final block to be compressed set this to True. For all other blocks set this to False.
During compression the CompressedData event will fire with the compressed data. Note that this event may not fire for every call to CompressBlock due to the way the compression algorithm operates. For example:
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressBlock();
Data is accumulated inside the CompressedData event:
private static void Zipstream_OnCompressedData(object sender, ZipstreamCompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that OutputData is not applicable when compressing block data.
Decompress Data
Set InputData to the current block to be decompressed. Next call DecompressBlock to decompress the current block.
During decompression the DecompressedData event will fire with the decompressed data. Note that this event may not fire for every call to DecompressBlock due to the way the decompression algorithm operates. For example:
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressBlock();
Data is accumulated inside the DecompressedData event:
private static void Zipstream_OnDecompressedData(object sender, ZipstreamDecompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that OutputData is not applicable when decompressing block data.
Error Handling
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
CompressData Method (ZipStream Class)
Compresses the specified data.
Syntax
int CompressData();
Remarks
This method compresses the data specified by InputData. After calling this method OutputData holds the compressed data.
The CompressData and DecompressData methods operate on the complete blob of data. The entire compressed or decompressed data must be set to InputData before calling either method.
To compress and decompress data in blocks (chunks) see CompressBlock and DecompressBlock.
Compress Data
Set InputData to the decompressed data. This should be the entire data to be compressed. Next call CompressData. After compression OutputData will hold the compressed data. For example:
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressData();
MyCompressedData = zipstream.OutputDataB;
In addition to OutputData, the compressed data may also be accumulated within the CompressedData event.
Decompress Data
Set InputData to the compressed data. This should be the entire data to be decompressed. Next call DecompressData. After decompression OutputData will hold the decompressed data. For example:
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressData();
MyDecompressedData = zipstream.OutputDataB;
In addition to OutputData, the compressed data may also be accumulated within the DecompressedData event.
Error Handling
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Config Method (ZipStream Class)
Sets or retrieves a configuration setting.
Syntax
QString Config(const QString& qsConfigurationString);
Remarks
Config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
Error Handling
This method returns a String value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
DecompressBlock Method (ZipStream Class)
Decompresses a block of data.
Syntax
int DecompressBlock();
Remarks
This method decompresses the block of data specified by InputData.
The CompressBlock and DecompressBlock methods operate on blocks (chunks) of data. The methods may be used to compress and decompress data as it becomes available.
Note that when using blocks of data the OutputData property is not applicable. Instead data is made available through the CompressedData and DecompressedData events.
If all data is available ahead of time CompressData and DecompressData may be called instead.
Compress Data
Set InputData to the current block to be compressed. Next call CompressBlock to compress the current block. Note that CompressBlock takes a LastBlock parameter. If the block of data is the final block to be compressed set this to True. For all other blocks set this to False.
During compression the CompressedData event will fire with the compressed data. Note that this event may not fire for every call to CompressBlock due to the way the compression algorithm operates. For example:
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressBlock();
Data is accumulated inside the CompressedData event:
private static void Zipstream_OnCompressedData(object sender, ZipstreamCompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that OutputData is not applicable when compressing block data.
Decompress Data
Set InputData to the current block to be decompressed. Next call DecompressBlock to decompress the current block.
During decompression the DecompressedData event will fire with the decompressed data. Note that this event may not fire for every call to DecompressBlock due to the way the decompression algorithm operates. For example:
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressBlock();
Data is accumulated inside the DecompressedData event:
private static void Zipstream_OnDecompressedData(object sender, ZipstreamDecompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that OutputData is not applicable when decompressing block data.
Error Handling
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
DecompressData Method (ZipStream Class)
Decompresses the specified data.
Syntax
int DecompressData();
Remarks
This method decompresses the data specified by InputData. After calling this method OutputData holds the decompressed data.
The CompressData and DecompressData methods operate on the complete blob of data. The entire compressed or decompressed data must be set to InputData before calling either method.
To compress and decompress data in blocks (chunks) see CompressBlock and DecompressBlock.
Compress Data
Set InputData to the decompressed data. This should be the entire data to be compressed. Next call CompressData. After compression OutputData will hold the compressed data. For example:
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressData();
MyCompressedData = zipstream.OutputDataB;
In addition to OutputData, the compressed data may also be accumulated within the CompressedData event.
Decompress Data
Set InputData to the compressed data. This should be the entire data to be decompressed. Next call DecompressData. After decompression OutputData will hold the decompressed data. For example:
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressData();
MyDecompressedData = zipstream.OutputDataB;
In addition to OutputData, the compressed data may also be accumulated within the DecompressedData event.
Error Handling
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Reset Method (ZipStream Class)
Resets the class.
Syntax
int Reset();
Remarks
Reset resets the state of the class. All properties will be set to their default values, and any files open will be closed.
Error Handling
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
CompressedData Event (ZipStream Class)
This event fires with compressed data.
Syntax
class ZipStreamCompressedDataEventParams { public: const QByteArray &Data(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void CompressedData(ZipStreamCompressedDataEventParams *e);
// Or, subclass ZipStream and override this emitter function. virtual int FireCompressedData(ZipStreamCompressedDataEventParams *e) {...}
Remarks
The CompressedData event fires as compressed data is available when CompressData or CompressBlock is called. This may fire one or more times when data is compressed.
Data holds the current block of compressed data.
DecompressedData Event (ZipStream Class)
This event fires with decompressed data.
Syntax
class ZipStreamDecompressedDataEventParams { public: const QByteArray &Data(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void DecompressedData(ZipStreamDecompressedDataEventParams *e);
// Or, subclass ZipStream and override this emitter function. virtual int FireDecompressedData(ZipStreamDecompressedDataEventParams *e) {...}
Remarks
The DecompressedData event fires as compressed data is available when DecompressData or DecompressBlock is called. This may fire one or more times as data is decompressed.
Data holds the current block of decompressed data.
Error Event (ZipStream Class)
Information about errors during data delivery.
Syntax
class ZipStreamErrorEventParams { public: int ErrorCode(); const QString &Description(); int EventRetVal(); void SetEventRetVal(int iRetVal); };
// To handle, connect one or more slots to this signal. void Error(ZipStreamErrorEventParams *e);
// Or, subclass ZipStream and override this emitter function. virtual int FireError(ZipStreamErrorEventParams *e) {...}
Remarks
The Error event is fired in case of exceptional conditions during message processing. Normally the class fails with an error.
ErrorCode contains an error code and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.
Configuration Settings (ZipStream Class)
The class accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these internal properties is provided through the Config method.No configuration settings defined.
Base Configuration Settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BuildInfo: Information about the product's build.When queried, this setting will return a string containing information about the product's build. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CodePage:
The system code page used for Unicode to Multibyte translations.The default code page is Unicode UTF-8 (65001).
The following is a list of valid code page identifiers:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LicenseInfo:
Information about the current license.When queried, this setting will return a string containing information about the license this instance of a class is using. It will return the following information:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
UseInternalSecurityAPI: Tells the class whether or not to use the system security libraries or an internal implementation. By default the class will use the system security libraries to perform cryptographic functions where applicable. Setting this to true tells the class to use the internal implementation instead of using the system's security API. |
Trappable Errors (ZipStream Class)
Note that the streams returned by GetCompressionStream and GetDecompressionStream will throw standard IOExceptions in case of error.ZipStream Errors
101 The data is of an invalid or unsupported format. | |
111 Can't open file for read. | |
150 An I/O error has occurred (details follow). |