Gzip JavaScript Reference Documentation

Gzip

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

Note: This is intended for running within a Chilkat.Js embedded JavaScript engine.

var obj = new CkGzip();

Properties

AbortCurrent
AbortCurrent
· boolean
Introduced in version 9.5.0.58

Set this property to true 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.

If no method is currently running, the property is automatically reset to false 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.

top
Comment
Comment
· string

An optional comment to embed in the Gzip file when a Compress* method is called.

top
CompressionLevel
CompressionLevel
· int
Introduced in version 9.5.0.50

Controls the compression level used when creating Gzip data. The value can range from 0 to 9.

  • 0 = no compression
  • 9 = 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.

top
DebugLogFilePath
DebugLogFilePath
· string

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.

More Information and Examples
top
Filename
Filename
· string

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.

top
LastErrorHtml
LastErrorHtml
· string, read-only

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.

top
LastErrorText
LastErrorText
· string, read-only

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.

top
LastErrorXml
LastErrorXml
· string, read-only

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.

top
LastMethodSuccess
LastMethodSuccess
· boolean

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.

top
LastModStr
LastModStr
· string

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.

top
UseCurrentDate
UseCurrentDate
· boolean

Controls the last-modified date/time assigned to files created by Uncompress* methods.

When set to true, the extracted file uses the current date/time instead of the date/time stored in the Gzip data.

top
VerboseLogging
VerboseLogging
· boolean

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.

top
Version
Version
· string, read-only

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

CompressBd
var success = CompressBd(binDat);
· return: boolean; true for success, false for failure
· binDat: CkBinData
Introduced in version 9.5.0.67

Compresses the contents of a BinData object in place, replacing the original data with Gzip-compressed data.

Returns true for success, false for failure.

More Information and Examples
top
CompressFile
var success = CompressFile(srcPath, destPath);
· return: boolean; true for success, false for failure
· srcPath: string
· destPath: string

Compresses a file and writes the result as a Gzip file, typically with a .gz extension.

Returns true for success, false for failure.

More Information and Examples
top
CompressFile2
var success = CompressFile2(srcPath, embeddedFilename, destPath);
· return: boolean; true for success, false for failure
· srcPath: string
· embeddedFilename: string
· destPath: string

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.

More Information and Examples
top
CompressFileBd
var success = CompressFileBd(filePath, bd);
· return: boolean; true for success, false for failure
· filePath: string
· bd: CkBinData
Introduced in version 11.0.0

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.

top
CompressSb
var success = CompressSb(sb, charset, bd);
· return: boolean; true for success, false for failure
· sb: CkStringBuilder
· charset: string
· bd: CkBinData
Introduced in version 11.0.0

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.

top
CompressStringENC
var strVal = CompressStringENC(inStr, charset, encoding);
· return: string
· inStr: string
· charset: string
· encoding: string

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 null on failure

top
CompressStringToFile
var success = CompressStringToFile(inStr, destCharset, destPath);
· return: boolean; true for success, false for failure
· inStr: string
· destCharset: string
· destPath: string

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.

top
ExamineFile
var boolVal = ExamineFile(filePath);
· return: boolean
· filePath: string

Checks whether the specified file contains Gzip-formatted data.

Returns true if the file is in Gzip format, or false otherwise.

More Information and Examples
top
IsGzip
var boolVal = IsGzip(bd);
· return: boolean
· bd: CkBinData
Introduced in version 11.0.0

Checks whether the data contained in a BinData object is in Gzip format.

Returns true if the data is Gzip-formatted, or false otherwise.

top
SetDt
var success = SetDt(dt);
· return: boolean; true for success, false for failure
· dt: CkDateTime

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.

More Information and Examples
top
SetExtraData
var success = SetExtraData(encodedData, encoding);
· return: boolean; true for success, false for failure
· encodedData: string
· encoding: string
Introduced in version 11.0.0

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.

More Information and Examples
top
UncompressBd
var success = UncompressBd(binDat);
· return: boolean; true for success, false for failure
· binDat: CkBinData
Introduced in version 9.5.0.67

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.

top
UncompressBdToFile
var success = UncompressBdToFile(bd, filePath);
· return: boolean; true for success, false for failure
· bd: CkBinData
· filePath: string
Introduced in version 11.0.0

Decompresses Gzip data stored in a BinData object and writes the result to a file.

Returns true for success, false for failure.

top
UncompressFile
var success = UncompressFile(srcPath, destPath);
· return: boolean; true for success, false for failure
· srcPath: string
· destPath: string

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.

More Information and Examples
top
UncompressFileToString
var strVal = UncompressFileToString(srcPath, charset);
· return: string
· srcPath: string
· charset: string

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 null on failure

More Information and Examples
top
UncompressStringENC
var strVal = UncompressStringENC(inStr, charset, encoding);
· return: string
· inStr: string
· charset: string
· encoding: string

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 null on failure

More Information and Examples
top
UnTarGz
var success = UnTarGz(gzPath, destDir, bNoAbsolute);
· return: boolean; true for success, false for failure
· gzPath: string
· destDir: string
· bNoAbsolute: boolean

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 true, absolute paths in the TAR archive are not allowed. This helps protect against extracting files to unsafe locations, such as system directories.

Returns true for success, false for failure.

top
XfdlToXml
var strVal = XfdlToXml(xfldData);
· return: string
· xfldData: string

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 null on failure

top