SocketTools .NET Edition

FileEncoder.CompressFile Method (String, String, CompressionType, CompressionLevel)

Compress the contents of the specified file.

[Visual Basic]
Overloads Public Function CompressFile( _
   ByVal inputFile As String, _
   ByVal outputFile As String, _
   ByVal compressionType As CompressionType, _
   ByVal compressionLevel As CompressionLevel _
) As Boolean
[C#]
public bool CompressFile(
   string inputFile,
   string outputFile,
   CompressionType compressionType,
   CompressionLevel compressionLevel
);

Parameters

inputFile
The name of the file that will be compressed. The file must exist, and it must be a regular file that can be opened for reading by the current process. An error will be returned if a character device, such as the console, is specified as the file name.
outputFile
The name of the file that is to contain the compressed file data. If the file exists, it must be a regular file that can be opened for writing by the current process and will be overwritten. If the file does not exist, it will be created. An error will be returned if a character device, such as the console, is specified as the file name.
compressionType
One of the CompressionType enumeration values which determines the algorithm that will be used to compress the data.
compressionLevel
One of the CompressionLevel enumeration values which specifies the compression level to use. A value of zero specifies that the default compression level appropriate for the selected algorithm should be used, balancing resource usage and the compression ratio of the data. A value of 1 specifies that the compression should be performed using minimal memory resources, at the expense of the compression ratio. The maximum value of 9 specifies that the algorithm should use more memory to achieve the maximum compression ratio. It is recommended that most applications use the default compression level.

Return Value

A boolean value which specifies if the method was successful or not. A return value of True indicates that the method call completed successfully. A return value of False indicates that the method failed and the application should check the value of the LastError property.

Remarks

It is permitted to specify an empty string as the output file name. In this case, the control will create a temporary file in the directory specified by the TEMP environment variable. After the file has been compressed, the OutputFile property will be set the name of the temporary file that has been created. It is the responsibility of the application to delete this temporary file after it is no longer needed.

Note that the compressed file is not stored in an archive format that is recognized by third-party applications such as PKZip or WinZip.

See Also

FileEncoder Class | SocketTools Namespace | FileEncoder.CompressFile Overload List