Gzip Ruby Reference Documentation
CkGzip
Current Version: 11.4.0
This class provides functionality for working with GZIP compression in both file-based and in-memory scenarios. It supports compressing and decompressing:
- Files (
.gz,.tar.gz) - Strings (with charset conversion)
- Binary data (
byte[],BinData) - Encoded data (Base64, Hex, etc.)
It also allows embedding metadata such as filenames, timestamps, and comments within the GZIP format.
For an extended overview, see Gzip Class Overview.
Object Creation
obj = Chilkat::CkGzip.new()
Properties
AbortCurrent
boolVal = gzip.get_AbortCurrent();
gzip.put_AbortCurrent(boolVal);
Set this property to to request that the currently running operation be aborted.
This is useful for long-running operations such as large file compression or decompression.
Methods that complete quickly are generally not affected.
true
If no method is currently running, the property is automatically reset to
when the next method begins. After an abort occurs, it is also reset to false.
Both synchronous and asynchronous operations can be aborted. For synchronous calls, another
thread must set this property.
false
Comment
# ckStr is a CkString
gzip.get_Comment(ckStr);
strVal = gzip.comment();
gzip.put_Comment(strVal);
An optional comment to embed in the Gzip file when a Compress* method is called.
CompressionLevel
intVal = gzip.get_CompressionLevel();
gzip.put_CompressionLevel(intVal);
Controls the compression level used when creating Gzip data. The value can range from
0 to 9.
0= no compression9= maximum compression
The default value is 6, which is a typical balance between compression size and speed.
Higher levels may take significantly more CPU time while producing only slightly smaller output,
depending on the data.
DebugLogFilePath
# ckStr is a CkString
gzip.get_DebugLogFilePath(ckStr);
strVal = gzip.debugLogFilePath();
gzip.put_DebugLogFilePath(strVal);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
Filename
# ckStr is a CkString
gzip.get_Filename(ckStr);
strVal = gzip.filename();
gzip.put_Filename(strVal);
The filename to embed in the Gzip file when a Compress* method is called.
Some Gzip extraction tools use this embedded filename as the default output filename.
LastErrorHtml
# ckStr is a CkString
gzip.get_LastErrorHtml(ckStr);
strVal = gzip.lastErrorHtml();
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
# ckStr is a CkString
gzip.get_LastErrorText(ckStr);
strVal = gzip.lastErrorText();
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
# ckStr is a CkString
gzip.get_LastErrorXml(ckStr);
strVal = gzip.lastErrorXml();
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
boolVal = gzip.get_LastMethodSuccess();
gzip.put_LastMethodSuccess(boolVal);
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
LastModStr
# ckStr is a CkString
gzip.get_LastModStr(ckStr);
strVal = gzip.lastModStr();
gzip.put_LastModStr(strVal);
Specifies the last-modified date/time to embed in the Gzip file when a
Compress* method is called.
The value must be provided as an RFC 822 formatted date/time string.
Example:
Tue, 15 Nov 1994 12:45:26 GMT
If this property is not set, the current system date/time is used automatically.
topUseCurrentDate
boolVal = gzip.get_UseCurrentDate();
gzip.put_UseCurrentDate(boolVal);
Controls the last-modified date/time assigned to files created by Uncompress* methods.
When set to , the extracted file uses the current date/time instead of the
date/time stored in the Gzip data.
true
Utf8
boolVal = gzip.get_Utf8();
gzip.put_Utf8(boolVal);
When set to true, all string arguments and return values are interpreted as UTF-8 strings. When set to false, they are interpreted as ANSI strings.
In Chilkat v11.0.0 and later, the default value is true. Before v11.0.0, it was false.
VerboseLogging
boolVal = gzip.get_VerboseLogging();
gzip.put_VerboseLogging(boolVal);
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
Methods
CompressBd
Compresses the contents of a BinData object in place, replacing the original data
with Gzip-compressed data.
Returns true for success, false for failure.
CompressBdAsync (1)
Creates an asynchronous task to call the CompressBd method with the arguments provided.
Returns nil on failure
CompressFile
# destPath is a string
status = gzip.CompressFile(srcPath, destPath);
Compresses a file and writes the result as a Gzip file, typically with a .gz extension.
Returns true for success, false for failure.
CompressFileAsync (1)
# srcPath is a string
# destPath is a string
ret_task = gzip.CompressFileAsync(srcPath, destPath);
Creates an asynchronous task to call the CompressFile method with the arguments provided.
Returns nil on failure
CompressFile2
# embeddedFilename is a string
# destPath is a string
status = gzip.CompressFile2(srcPath, embeddedFilename, destPath);
Compresses a file and writes the result as a Gzip file, while allowing a different filename to be embedded inside the Gzip data.
The inFilename parameter is the actual file on disk. The
srcPath parameter is the filename stored in the Gzip header and may be used
by extraction tools as the output filename.
Returns true for success, false for failure.
CompressFile2Async (1)
# srcPath is a string
# embeddedFilename is a string
# destPath is a string
ret_task = gzip.CompressFile2Async(srcPath, embeddedFilename, destPath);
Creates an asynchronous task to call the CompressFile2 method with the arguments provided.
Returns nil on failure
CompressFileBd
Compresses a file and stores the resulting Gzip data in a BinData object.
The compressed output is held in memory. The maximum compressed size is 4 GB.
Returns true for success, false for failure.
CompressFileBdAsync (1)
# filePath is a string
# bd is a CkBinData
ret_task = gzip.CompressFileBdAsync(filePath, bd);
Creates an asynchronous task to call the CompressFileBd method with the arguments provided.
Returns nil on failure
CompressSb
# charset is a string
# bd is a CkBinData
status = gzip.CompressSb(sb, charset, bd);
Compresses the text contained in a StringBuilder and writes the Gzip-compressed
result to a BinData object.
Before compression, the string is converted to bytes using the specified character set, such as
utf-8, iso-8859-1, or shift_JIS.
Returns true for success, false for failure.
CompressSbAsync (1)
# sb is a CkStringBuilder
# charset is a string
# bd is a CkBinData
ret_task = gzip.CompressSbAsync(sb, charset, bd);
Creates an asynchronous task to call the CompressSb method with the arguments provided.
Returns nil on failure
CompressStringENC
# charset is a string
# encoding is a string
# outStr is a CkString (output)
status = gzip.CompressStringENC(inStr, charset, encoding, outStr);
retStr = gzip.compressStringENC(inStr, charset, encoding);
Compresses a string and returns the Gzip-compressed data as an encoded string.
The input string is first converted to bytes using the specified character set. The compressed
binary data is then encoded using the requested encoding, such as base64,
hex, url, base32, or quoted-printable.
Returns true for success, false for failure.
CompressStringToFile
# destCharset is a string
# destPath is a string
status = gzip.CompressStringToFile(inStr, destCharset, destPath);
Compresses a string and writes the resulting Gzip data to a file.
The string is first converted to bytes using the character set specified by
destCharset.
Returns true for success, false for failure.
CompressStringToFileAsync (1)
# inStr is a string
# destCharset is a string
# destPath is a string
ret_task = gzip.CompressStringToFileAsync(inStr, destCharset, destPath);
Creates an asynchronous task to call the CompressStringToFile method with the arguments provided.
Returns nil on failure
ExamineFile
retBool = gzip.ExamineFile(filePath);
Checks whether the specified file contains Gzip-formatted data.
Returns if the file is in Gzip format, or true otherwise.
false
IsGzip
Checks whether the data contained in a BinData object is in Gzip format.
Returns if the data is Gzip-formatted, or true otherwise.
false
LoadTaskCaller
SetDt
Sets the last-modified date/time to embed in the Gzip file when a Compress*
method is called.
If no date/time is explicitly set, the current system date/time is used.
Returns true for success, false for failure.
SetExtraData
# encoding is a string
status = gzip.SetExtraData(encodedData, encoding);
Sets optional extra binary data to include in the Gzip header when a Compress*
method is called.
The data is passed as an encoded string. Supported encodings include base64,
hex, ascii, and many others.
Returns true for success, false for failure.
UncompressBd
Decompresses Gzip data contained in a BinData object in place, replacing the
compressed data with the uncompressed data.
Returns true for success, false for failure.
topUncompressBdAsync (1)
Creates an asynchronous task to call the UncompressBd method with the arguments provided.
Returns nil on failure
UncompressBdToFile
Decompresses Gzip data stored in a BinData object and writes the result to a file.
Returns true for success, false for failure.
topUncompressBdToFileAsync (1)
# bd is a CkBinData
# filePath is a string
ret_task = gzip.UncompressBdToFileAsync(bd, filePath);
Creates an asynchronous task to call the UncompressBdToFile method with the arguments provided.
Returns nil on failure
UncompressFile
# destPath is a string
status = gzip.UncompressFile(srcPath, destPath);
Decompresses a Gzip file and writes the result to the specified output path.
The output filename is provided by the caller. The filename embedded in the Gzip data is not used.
Returns true for success, false for failure.
UncompressFileAsync (1)
# srcPath is a string
# destPath is a string
ret_task = gzip.UncompressFileAsync(srcPath, destPath);
Creates an asynchronous task to call the UncompressFile method with the arguments provided.
Returns nil on failure
UncompressFileToString
# charset is a string
# outStr is a CkString (output)
status = gzip.UncompressFileToString(srcPath, charset, outStr);
retStr = gzip.uncompressFileToString(srcPath, charset);
Decompresses a Gzip file that contains text and returns the uncompressed text as a string.
The charset parameter specifies the character encoding of the uncompressed text,
such as utf-8, iso-8859-1, windows-1252,
shift_JIS, big5, etc.
Returns true for success, false for failure.
UncompressFileToStringAsync (1)
# srcPath is a string
# charset is a string
ret_task = gzip.UncompressFileToStringAsync(srcPath, charset);
Creates an asynchronous task to call the UncompressFileToString method with the arguments provided.
Returns nil on failure
UncompressStringENC
# charset is a string
# encoding is a string
# outStr is a CkString (output)
status = gzip.UncompressStringENC(inStr, charset, encoding, outStr);
retStr = gzip.uncompressStringENC(inStr, charset, encoding);
Decompresses Gzip data provided as an encoded string and returns the uncompressed result as text.
The input string is first decoded using the specified encoding, such as base64,
hex, url, base32, quoted-printable, etc. The decoded
Gzip data is then decompressed and converted to text using the specified character set.
Returns true for success, false for failure.
UnTarGz
# destDir is a string
# bNoAbsolute is a boolean
status = gzip.UnTarGz(gzPath, destDir, bNoAbsolute);
Extracts a .tar.gz archive to a directory.
The Gzip decompression and TAR extraction are performed in streaming mode. No temporary files are created, and memory usage remains small and constant.
If bNoAbsolute is , absolute paths in the TAR archive are not
allowed. This helps protect against extracting files to unsafe locations, such as system
directories.
true
Returns true for success, false for failure.
topUnTarGzAsync (1)
# gzPath is a string
# destDir is a string
# bNoAbsolute is a boolean
ret_task = gzip.UnTarGzAsync(gzPath, destDir, bNoAbsolute);
Creates an asynchronous task to call the UnTarGz method with the arguments provided.
Returns nil on failure
XfdlToXml
# outStr is a CkString (output)
status = gzip.XfdlToXml(xfldData, outStr);
retStr = gzip.xfdlToXml(xfldData);
Converts base64-encoded, Gzip-compressed XFDL data to XML text.
The input contains base64 data. The method decodes it, decompresses the Gzip data, and returns the resulting XML string.
XFDL (Extensible Forms Description Language) is an XML-based format used to define secure, interactive electronic forms—often including digital signatures and integrity protections—commonly used in government and enterprise applications.
Returns true for success, false for failure.
topDeprecated
CompressFileToMem Deprecated
# outData is a CkByteData (output)
status = gzip.CompressFileToMem(inFilename, outData);
Compresses a file and returns the resulting Gzip data as a byte array.
The compressed output is held in memory and has a maximum size limit of 4 GB.
Returns true for success, false for failure.
topCompressFileToMemAsync Deprecated (1)
Creates an asynchronous task to call the CompressFileToMem method with the arguments provided.
Returns nil on failure
CompressMemory Deprecated
# outData is a CkByteData (output)
status = gzip.CompressMemory(inData, outData);
Compresses a byte array and returns the result as an in-memory Gzip image.
The uncompressed input data must not exceed 4 GB.
Returns true for success, false for failure.
topCompressMemoryAsync Deprecated (1)
Creates an asynchronous task to call the CompressMemory method with the arguments provided.
Returns nil on failure
CompressMemToFile Deprecated
Compresses a byte array and writes the resulting Gzip data to a file.
Returns true for success, false for failure.
topCompressMemToFileAsync Deprecated (1)
# inData is a CkByteData
# destPath is a string
ret_task = gzip.CompressMemToFileAsync(inData, destPath);
Creates an asynchronous task to call the CompressMemToFile method with the arguments provided.
Returns nil on failure
CompressString Deprecated
# destCharset is a string
# outBytes is a CkByteData (output)
status = gzip.CompressString(inStr, destCharset, outData);
Compresses a string and returns the Gzip-compressed data as a byte array.
The string is first converted to bytes using the character set specified by
destCharset. Common values include utf-8,
iso-8859-1, and shift_JIS.
Returns true for success, false for failure.
CompressStringAsync Deprecated (1)
# inStr is a string
# destCharset is a string
ret_task = gzip.CompressStringAsync(inStr, destCharset);
Creates an asynchronous task to call the CompressString method with the arguments provided.
Returns nil on failure
Decode Deprecated
# encoding is a string
# outBytes is a CkByteData (output)
status = gzip.Decode(encodedStr, encoding, outData);
Decodes an encoded string and returns the original data. The encoding mode is determined by encoding. It may be base64, hex, quoted-printable, or url.
Returns true for success, false for failure.
topDeflateStringENC
# charsetName is a string
# outputEncoding is a string
# outStr is a CkString (output)
status = gzip.DeflateStringENC(inString, charsetName, outputEncoding, outStr);
retStr = gzip.deflateStringENC(inString, charsetName, outputEncoding);
Compresses a string using the raw deflate algorithm and returns the compressed data as an encoded string.
The input string is first converted to bytes using the specified character set. The compressed
binary data is then encoded using the requested output encoding, such as hex,
base64, url, or quoted-printable.
Important: This method produces raw deflate-compressed data, not Gzip-format data.
Use the Compress* methods when Gzip format output is required.
Returns true for success, false for failure.
Encode Deprecated
# encoding is a string
# outStr is a CkString (output)
status = gzip.Encode(byteData, encoding, outStr);
retStr = gzip.encode(byteData, encoding);
Encodes binary data to a printable string. The encoding mode is determined by encoding. It may be base64, hex, quoted-printable, or url.
Returns true for success, false for failure.
topExamineMemory Deprecated
Checks whether the provided byte array contains Gzip-formatted data.
Returns if the data is in Gzip format, or true otherwise.
false
GetDt
Applications should instead access the LastModStr property.
Gets the last-modification date/time to be embedded within the .gz.
Returns nil on failure
InflateStringENC
# convertFromCharset is a string
# inputEncoding is a string
# outStr is a CkString (output)
status = gzip.InflateStringENC(inString, convertFromCharset, inputEncoding, outStr);
retStr = gzip.inflateStringENC(inString, convertFromCharset, inputEncoding);
Decompresses data previously compressed with DeflateStringENC.
The input string is first decoded using the specified input encoding, such as
hex, base64, url, or
quoted-printable. The resulting compressed bytes are then inflated, and the
final bytes are converted to a string using the specified character set.
Returns true for success, false for failure.
topReadFile Deprecated
Reads a binary file into memory and returns the byte array. Note: This method does not parse a Gzip, it is only a convenience method for reading a binary file into memory.
Returns true for success, false for failure.
topUncompressFileToMem Deprecated
# outData is a CkByteData (output)
status = gzip.UncompressFileToMem(srcPath, outData);
Decompresses a Gzip file and returns the uncompressed data as a byte array.
The uncompressed output is held in memory and must not exceed 4 GB.
Returns true for success, false for failure.
topUncompressFileToMemAsync Deprecated (1)
Creates an asynchronous task to call the UncompressFileToMem method with the arguments provided.
Returns nil on failure
UncompressMemory Deprecated
# outData is a CkByteData (output)
status = gzip.UncompressMemory(inData, outData);
Decompresses an in-memory Gzip image and returns the uncompressed data as a byte array.
The uncompressed output is held in memory and must not exceed 4 GB.
Returns true for success, false for failure.
topUncompressMemoryAsync Deprecated (1)
Creates an asynchronous task to call the UncompressMemory method with the arguments provided.
Returns nil on failure
UncompressMemToFile Deprecated
# destPath is a string
status = gzip.UncompressMemToFile(inData, destPath);
Decompresses an in-memory Gzip image and writes the uncompressed data to a file.
Returns true for success, false for failure.
topUncompressMemToFileAsync Deprecated (1)
# inData is a CkByteData
# destPath is a string
ret_task = gzip.UncompressMemToFileAsync(inData, destPath);
Creates an asynchronous task to call the UncompressMemToFile method with the arguments provided.
Returns nil on failure
UncompressString Deprecated
# inCharset is a string
# outStr is a CkString (output)
status = gzip.UncompressString(inData, inCharset, outStr);
retStr = gzip.uncompressString(inData, inCharset);
Decompresses Gzip-compressed data and returns the result as a string.
After decompression, the result is raw binary data (a sequence of bytes). These bytes are then
interpreted as text using the specified character set (such as utf-8,
iso-8859-1, etc.) to produce the final string.
Internally, Chilkat converts the byte sequence to a string by interpreting the bytes according
to the specified character set. For example, if utf-8 is specified, the bytes are
treated as the UTF-8 byte representation of text and decoded into the internal string format
used by the programming language.
It is important that the character set matches the one originally used when the data was compressed. If the wrong character set is used, the byte-to-text conversion may produce incorrect or unreadable characters.
Returns true for success, false for failure.
UncompressStringAsync Deprecated (1)
# inData is a CkByteData
# inCharset is a string
ret_task = gzip.UncompressStringAsync(inData, inCharset);
Creates an asynchronous task to call the UncompressString method with the arguments provided.
Returns nil on failure
WriteFile Deprecated
A convenience method for writing a binary byte array to a file.
Returns true for success, false for failure.
top