Zstd Class
Properties Methods Events Config Settings Errors
The Zstd class implements a Zstandard (zstd) compressor and decompressor.
Syntax
ipworkszip.Zstd
Remarks
The Zstd class is compliant with RFC 8878, the Zstandard Compression Format specification. Data compressed by the class can be decompressed by any standard zstd-compatible tool or library, and the class can in turn decompress data produced by any standard zstd encoder.
The CompressionLevel property selects the compression level to use, from 1 (fastest) to 22 (most compact). The class favors speed and simplicity over maximum compression, so at very high levels it may not reach the same compression ratio as the reference zstd encoder; however, the resulting data is still fully standard and can be decompressed by any zstd decoder.
Data may be operated on in multiple ways as discussed below.
Compression and Decompression Streams
The GetDecompressionStream and GetCompressionStream methods are used to retrieve streams that read or write compressed data, as appropriate. The underlying stream should be passed to either method as a parameter.
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 they become available.
Note that when using blocks of data, the OutputData property is not applicable. Instead, data are made available via the CompressedData and DecompressedData events.
If all data is available ahead of time, the CompressData and DecompressData methods may be called instead.
Compress Data
The InputData property should be set to the current block to be compressed. Next, the CompressBlock method should be called to compress the current block. Note that this method takes a LastBlock parameter; if the block of data is the final block to be compressed, it must be set to true. For all other blocks, it must remain 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.
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressBlock();
Data are accumulated inside the CompressedData event:
private static void Zipstream_OnCompressedData(object sender, ZipstreamCompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that the OutputData property is not applicable when compressing block data.
Decompress Data
The InputData property should be set to the current block to be decompressed. Next, the DecompressBlock method should be called 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.
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 the OutputData property 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 the InputData property before calling either method.
To compress and decompress data in blocks (chunks), refer to the CompressBlock and DecompressBlock methods.
Compress Data
The InputData property should be set to the decompressed data. This should be the entire data to be compressed. Next, the CompressData method should be called, after which the OutputData property will hold the compressed data.
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
The InputData property should be set to the compressed data. This should be the entire data to be decompressed. Next, the DecompressData method should be called, after which the OutputData property will hold the decompressed data.
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressData();
MyDecompressedData = zipstream.OutputDataB;
In addition to OutputData, the decompressed 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.
| CloseBaseStream | Whether or not to close the underlying stream. |
| CompressionLevel | The compression level to use. |
| InputData | The data to compress or decompress. |
| OutputData | The output data after compression or decompression. |
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. |
| GetCompressionStream | Creates an output stream used to write compressed data. |
| GetDecompressionStream | Creates an input stream used to read data from a compressed stream. |
| 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 | Fires with compressed data. |
| DecompressedData | Fires with decompressed data. |
| Error | Fires with information about errors during data delivery. |
Config Settings
The following is a list of config settings for the class with short descriptions. Click on the links for further details.
| BuildInfo | Information about the product's build. |
| GUIAvailable | Whether or not a message loop is available for processing events. |
| LicenseInfo | Information about the current license. |
| MaskSensitiveData | Whether sensitive data is masked in log messages. |
| UseDaemonThreads | Whether threads created by the class are daemon threads. |
| UseInternalSecurityAPI | Whether or not to use the system security libraries or an internal implementation. |
| UseVirtualThreads | Whether threads created by the class use virtual threads instead of platform threads. |
CloseBaseStream Property (Zstd Class)
Whether or not to close the underlying stream.
Syntax
public boolean isCloseBaseStream(); public void setCloseBaseStream(boolean closeBaseStream);
Default Value
True
Remarks
This property controls whether streams created via the GetCompressionStream and GetDecompressionStream methods will close their underlying streams when their Close method is invoked.
When enabled, the underlying streams are closed; otherwise, they will remain open.
CompressionLevel Property (Zstd Class)
The compression level to use.
Syntax
public int getCompressionLevel(); public void setCompressionLevel(int compressionLevel);
Default Value
4
Remarks
This property dictates the compression level to use, from 1 to 22. Higher values will cause the class to compress better; lower values will cause the class to compress faster.
Note that some levels may produce functionally identical results to a neighboring level. A higher level will never compress worse than a lower one, but it is not guaranteed to compress better at every step.
When the GetCompressionStream method is invoked, the stream will be created with the specified compression level. After a stream has been created, it is independent of the class, and changing this property will have no effect on existing streams.
InputData Property (Zstd Class)
The data to compress or decompress.
Syntax
public byte[] getInputData(); public void setInputData(byte[] inputData);
Default Value
""
Remarks
This property specifies the data to compress or decompress.
When decompressing, this should be set to the compressed data before the DecompressData or DecompressBlock methods are called.
When compressing, this should be set to the decompressed data before the CompressData or CompressBlock methods are called.
Note that this property is not automatically cleared after each operation when performing operations on multiple chunks of data.
OutputData Property (Zstd Class)
The output data after compression or decompression.
Syntax
public byte[] getOutputData();
Default Value
""
Remarks
This property holds the compressed or decompressed data after the CompressData or DecompressData methods are called.
This property is not applicable when calling the CompressBlock or DecompressBlock methods.
This property is read-only and not available at design time.
CompressBlock Method (Zstd Class)
Compresses a block of data.
Syntax
public void compressBlock(boolean lastBlock);
Remarks
This method compresses the block of data specified by the InputData property.
The CompressBlock and DecompressBlock methods operate on blocks (chunks) of data. The methods may be used to compress and decompress data as they become available.
Note that when using blocks of data, the OutputData property is not applicable. Instead, data are made available via the CompressedData and DecompressedData events.
If all data is available ahead of time, the CompressData and DecompressData methods may be called instead.
Compress Data
The InputData property should be set to the current block to be compressed. Next, the CompressBlock method should be called to compress the current block. Note that this method takes a LastBlock parameter; if the block of data is the final block to be compressed, it must be set to true. For all other blocks, it must remain 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.
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressBlock();
Data are accumulated inside the CompressedData event:
private static void Zipstream_OnCompressedData(object sender, ZipstreamCompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that the OutputData property is not applicable when compressing block data.
Decompress Data
The InputData property should be set to the current block to be decompressed. Next, the DecompressBlock method should be called 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.
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 the OutputData property is not applicable when decompressing block data.
CompressData Method (Zstd Class)
Compresses the specified data.
Syntax
public void compressData();
Remarks
This method compresses the data specified by the InputData property. After calling this method, the OutputData property 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 the InputData property before calling either method.
To compress and decompress data in blocks (chunks), refer to the CompressBlock and DecompressBlock methods.
Compress Data
The InputData property should be set to the decompressed data. This should be the entire data to be compressed. Next, the CompressData method should be called, after which the OutputData property will hold the compressed data.
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
The InputData property should be set to the compressed data. This should be the entire data to be decompressed. Next, the DecompressData method should be called, after which the OutputData property will hold the decompressed data.
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressData();
MyDecompressedData = zipstream.OutputDataB;
In addition to OutputData, the decompressed data may also be accumulated within the DecompressedData event.
Config Method (Zstd Class)
Sets or retrieves a configuration setting.
Syntax
public String config(String configurationString);
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.
DecompressBlock Method (Zstd Class)
Decompresses a block of data.
Syntax
public void decompressBlock();
Remarks
This method decompresses the block of data specified by the InputData property.
The CompressBlock and DecompressBlock methods operate on blocks (chunks) of data. The methods may be used to compress and decompress data as they become available.
Note that when using blocks of data, the OutputData property is not applicable. Instead, data are made available via the CompressedData and DecompressedData events.
If all data is available ahead of time, the CompressData and DecompressData methods may be called instead.
Compress Data
The InputData property should be set to the current block to be compressed. Next, the CompressBlock method should be called to compress the current block. Note that this method takes a LastBlock parameter; if the block of data is the final block to be compressed, it must be set to true. For all other blocks, it must remain 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.
zipstream.InputDataB = MyDecompressedData;
zipstream.CompressBlock();
Data are accumulated inside the CompressedData event:
private static void Zipstream_OnCompressedData(object sender, ZipstreamCompressedDataEventArgs e)
{
DoSomethingWith(e.DataB);
}
Note that the OutputData property is not applicable when compressing block data.
Decompress Data
The InputData property should be set to the current block to be decompressed. Next, the DecompressBlock method should be called 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.
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 the OutputData property is not applicable when decompressing block data.
DecompressData Method (Zstd Class)
Decompresses the specified data.
Syntax
public void decompressData();
Remarks
This method decompresses the data specified by the InputData property. After calling this method, the OutputData property 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 the InputData property before calling either method.
To compress and decompress data in blocks (chunks), refer to the CompressBlock and DecompressBlock methods.
Compress Data
The InputData property should be set to the decompressed data. This should be the entire data to be compressed. Next, the CompressData method should be called, after which the OutputData property will hold the compressed data.
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
The InputData property should be set to the compressed data. This should be the entire data to be decompressed. Next, the DecompressData method should be called, after which the OutputData property will hold the decompressed data.
zipstream.InputDataB = MyCompressedData;
zipstream.DecompressData();
MyDecompressedData = zipstream.OutputDataB;
In addition to OutputData, the decompressed data may also be accumulated within the DecompressedData event.
GetCompressionStream Method (Zstd Class)
Creates an output stream used to write compressed data.
Syntax
public java.io.OutputStream getCompressionStream(java.io.OutputStream baseStream);
Remarks
This method returns a stream used to compress data as they are written to an underlying stream. The BaseStream parameter should be set to the stream to which the compressed data will be written.
The returned stream is independent of the class once created; thus, subsequently changing the CompressionLevel property has no effect on it. Closing the returned stream also closes BaseStream if the CloseBaseStream property is enabled before the stream is created.
GetDecompressionStream Method (Zstd Class)
Creates an input stream used to read data from a compressed stream.
Syntax
public java.io.InputStream getDecompressionStream(java.io.InputStream baseStream);
Remarks
This method returns a stream used to read decompressed data as they are read from an underlying compressed stream. The BaseStream parameter should be set to the stream providing the compressed data.
The returned stream is independent of the class once created. Closing the returned stream also closes BaseStream if the CloseBaseStream property is enabled before the stream is created.
Reset Method (Zstd Class)
Resets the class.
Syntax
public void reset();
Remarks
This method is used to reset the state of the class. All properties are set to their default values, and any open files are closed.
CompressedData Event (Zstd Class)
Fires with compressed data.
Syntax
public class DefaultZstdEventListener implements ZstdEventListener { ... public void compressedData(ZstdCompressedDataEvent e) {} ... } public class ZstdCompressedDataEvent { public byte[] data; }
Remarks
This event is fired one or more times as compressed data become available when the CompressData or CompressBlock methods are called.
Data holds the current block of compressed data.
DecompressedData Event (Zstd Class)
Fires with decompressed data.
Syntax
public class DefaultZstdEventListener implements ZstdEventListener { ... public void decompressedData(ZstdDecompressedDataEvent e) {} ... } public class ZstdDecompressedDataEvent { public byte[] data; }
Remarks
This event is fired one or more times as decompressed data become available when the DecompressData or DecompressBlock methods are called.
Data holds the current block of decompressed data.
Error Event (Zstd Class)
Fires with information about errors during data delivery.
Syntax
public class DefaultZstdEventListener implements ZstdEventListener { ... public void error(ZstdErrorEvent e) {} ... } public class ZstdErrorEvent { public int errorCode; public String description; }
Remarks
This event is fired in case of exceptional conditions during message processing. Normally, the class throws an exception.
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.
Config Settings (Zstd 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 Config Settings
In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the class does not attempt to process external events.
- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.
Setting this configuration setting to true tells the class to use the internal implementation instead of using the system security libraries.
This setting is set to false by default on all platforms.
Trappable Errors (Zstd 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). |