Gzip SQL Server Reference Documentation

Gzip

Current Version: 11.6.0

Chilkat.Gzip

Compress, decompress, inspect, and convert GZIP data in files or memory.

Chilkat.Gzip provides GZIP compression and decompression for file-based and in-memory workflows. It can compress and uncompress files, strings, byte arrays, BinData, and encoded data such as Base64 or hex. It also supports .tar.gz extraction, gzip metadata such as original filename, timestamp, and comments, and inspection of GZIP header information without fully expanding the compressed data.

File compression

Compress files to .gz, uncompress .gz files, and write decompressed output directly to disk.

Memory-based data

Work with byte arrays and Chilkat.BinData for applications that need compression or decompression without temporary files.

String workflows

Compress and uncompress strings with explicit charset handling for text data that must round-trip correctly.

Encoded GZIP data

Handle GZIP data represented as Base64, hex, or other supported encoded forms when binary data must be carried as text.

GZIP metadata

Set or inspect metadata such as original filename, modified time, comments, and extra data stored in the GZIP header.

Tar-gzip and XFDL

Extract .tar.gz archives and decode XFDL content that uses gzip-related encodings.

Common pattern: Use Gzip when the data is a single GZIP stream, a .gz file, or a .tar.gz archive. For ZIP archives, use Chilkat.Zip; for raw deflate or zlib-style compression, use Chilkat.Compression.

Object Creation

DECLARE @hr int
DECLARE @gzip int
EXEC @hr = sp_OACreate 'Chilkat.Gzip', @gzip OUT
IF @hr <> 0
BEGIN
    PRINT 'Failed to create ActiveX component'
    RETURN
END

-- ... use @gzip ...

EXEC @hr = sp_OADestroy @gzip

T-SQL uses the Chilkat ActiveX through the OLE Automation stored procedures. They must be enabled once on the server (EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;), and the Chilkat ActiveX registered must match the bitness of the SQL Server instance (64-bit for a 64-bit SQL Server). To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as sp_OACreate 'Chilkat.Gzip.11' for Chilkat v11.*.*.

sp_OACreate returns an object token (an int) that is passed as the first argument of every sp_OAMethod, sp_OAGetProperty and sp_OASetProperty call, and released with sp_OADestroy. Objects returned by methods (such as an HttpResponse or JsonObject) are also tokens received through an int OUT parameter; they must likewise be destroyed, and the OUT parameter is NULL when the method fails to return an object. Objects passed as arguments are passed by their token. When an OLE Automation procedure itself fails (non-zero @hr), sp_OAGetErrorInfo describes the error.

Data types: strings are nvarchar(4000); integers, booleans (1 or 0) and object tokens are int; dates are datetime. In the signatures on this page, @success, @iResult, @sResult and the like are the OUT variables receiving a method's return value, @iValue / @sValue receive or supply a property value, and the remaining @ variables are the method's arguments in order.

A string returned through an OUT parameter is limited to 4000 characters. For longer values, retrieve the result as a result set into a table variable instead of an OUT parameter, for example DECLARE @tmp TABLE (outputLine ntext) followed by INSERT INTO @tmp EXEC sp_OAGetProperty @gzip, 'LastErrorText'. See string length limitations for strings returned by sp_OAMethod calls.

Methods that pass or return raw byte arrays are not shown on this page, because varbinary(max) values cannot be exchanged through sp_OAMethod (see varbinary(max) limitation). Use the BinData-based alternatives (methods ending in Bd) or the base64 / hex string-encoded variants instead. Binary properties (such as LastBinaryResult) can be retrieved as a result set into a table variable, as shown in their signatures. Asynchronous (*Async) methods and event callbacks are not available from SQL Server.

Properties

AbortCurrent
EXEC sp_OAGetProperty @gzip, 'AbortCurrent', @iValue OUT
EXEC sp_OASetProperty @gzip, 'AbortCurrent', @iValue
Introduced in version 9.5.0.58

Set this property to 1 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 0 when the next method begins. After an abort occurs, it is also reset to 0. Both synchronous and asynchronous operations can be aborted. For synchronous calls, another thread must set this property.

top
Comment
EXEC sp_OAGetProperty @gzip, 'Comment', @sValue OUT
EXEC sp_OASetProperty @gzip, 'Comment', @sValue

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

More Information and Examples
top
CompressionLevel
EXEC sp_OAGetProperty @gzip, 'CompressionLevel', @iValue OUT
EXEC sp_OASetProperty @gzip, 'CompressionLevel', @iValue
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.

More Information and Examples
top
DebugLogFilePath
EXEC sp_OAGetProperty @gzip, 'DebugLogFilePath', @sValue OUT
EXEC sp_OASetProperty @gzip, 'DebugLogFilePath', @sValue

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
ExtraData
INSERT INTO @tmp EXEC sp_OAGetProperty @gzip, 'ExtraData'

Optional binary data to include in the Gzip header when a Compress* method is called.

top
Filename
EXEC sp_OAGetProperty @gzip, 'Filename', @sValue OUT
EXEC sp_OASetProperty @gzip, 'Filename', @sValue

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.

More Information and Examples
top
LastBinaryResult
INSERT INTO @tmp EXEC sp_OAGetProperty @gzip, 'LastBinaryResult'

This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. It is only accessible if Chilkat.Global.KeepBinaryResult is set to 1. This feature allows for the retrieval of large varbinary results in an SQL Server environment, which has restrictions on returning large data via method calls, though temp tables can handle binary properties.

top
LastErrorHtml
EXEC sp_OAGetProperty @gzip, 'LastErrorHtml', @sValue OUT

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
EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sValue OUT

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
EXEC sp_OAGetProperty @gzip, 'LastErrorXml', @sValue OUT

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
EXEC sp_OAGetProperty @gzip, 'LastMethodSuccess', @iValue OUT
EXEC sp_OASetProperty @gzip, 'LastMethodSuccess', @iValue

Indicates the success or failure of the most recent method call: 1 means success, 0 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
EXEC sp_OAGetProperty @gzip, 'LastModStr', @sValue OUT
EXEC sp_OASetProperty @gzip, 'LastModStr', @sValue

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:

Sun, 12 Apr 2026 12:45:26 GMT

If this property is not set, the current system date/time is used automatically.

More Information and Examples
top
LastStringResult
EXEC sp_OAGetProperty @gzip, 'LastStringResult', @sValue OUT

In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. It is accessible only when Chilkat.Global.KeepStringResult is set to TRUE. SQL Server has limitations on string lengths returned from methods and properties, but temp tables can be used to access large strings.

top
LastStringResultLen
EXEC sp_OAGetProperty @gzip, 'LastStringResultLen', @iValue OUT

The length, in characters, of the string contained in the LastStringResult property.

top
UseCurrentDate
EXEC sp_OAGetProperty @gzip, 'UseCurrentDate', @iValue OUT
EXEC sp_OASetProperty @gzip, 'UseCurrentDate', @iValue

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

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

top
VerboseLogging
EXEC sp_OAGetProperty @gzip, 'VerboseLogging', @iValue OUT
EXEC sp_OASetProperty @gzip, 'VerboseLogging', @iValue

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
EXEC sp_OAGetProperty @gzip, 'Version', @sValue OUT

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

More Information and Examples
top

Methods

CompressBd
EXEC sp_OAMethod @gzip, 'CompressBd', @success OUT, @binDat
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 1 for success, 0 for failure.

More Information and Examples
top
CompressFile
EXEC sp_OAMethod @gzip, 'CompressFile', @success OUT, @srcPath, @destPath

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

Returns 1 for success, 0 for failure.

More Information and Examples
top
CompressFile2
EXEC sp_OAMethod @gzip, 'CompressFile2', @success OUT, @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 1 for success, 0 for failure.

More Information and Examples
top
CompressFileBd
EXEC sp_OAMethod @gzip, 'CompressFileBd', @success OUT, @filePath, @bd
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 1 for success, 0 for failure.

top
CompressSb
EXEC sp_OAMethod @gzip, 'CompressSb', @success OUT, @sb, @charset, @bd
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 1 for success, 0 for failure.

top
CompressStringENC
EXEC sp_OAMethod @gzip, 'CompressStringENC', @sResult OUT, @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 NULL on failure

top
CompressStringToFile
EXEC sp_OAMethod @gzip, 'CompressStringToFile', @success OUT, @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 1 for success, 0 for failure.

top
GetGzipInfo
EXEC sp_OAMethod @gzip, 'GetGzipInfo', @success OUT, @filePath, @json
Introduced in version 11.5.0

Retrieves metadata stored in a Gzip file and returns the information in a JsonObject.

The metadata is returned using the following JSON structure:

{
  "extraData": "AAECAw==",
  "filename": "example.txt",
  "comment": "This is the comment"
}
  • filename – the original filename embedded in the Gzip file (if present)
  • comment – an optional descriptive comment (if present)
  • extraData – optional additional binary data, returned as a Base64-encoded string

Any of these fields may be omitted if they were not included when the Gzip file was created.

Returns 1 for success, 0 for failure.

More Information and Examples
top
GetGzipInfoBd
EXEC sp_OAMethod @gzip, 'GetGzipInfoBd', @success OUT, @bd, @json
Introduced in version 11.5.0

Retrieves metadata stored in Gzip data contained within a BinData object and returns the information in a JsonObject.

The metadata is returned using the same JSON structure:

{
  "extraData": "AAECAw==",
  "filename": "example.txt",
  "comment": "This is the comment"
}
  • filename – the original filename embedded in the Gzip data (if present)
  • comment – an optional descriptive comment (if present)
  • extraData – optional additional binary data, returned as a Base64-encoded string

Any of these fields may be omitted if they were not included when the Gzip data was created.

Returns 1 for success, 0 for failure.

top
IsGzip
EXEC sp_OAMethod @gzip, 'IsGzip', @success OUT, @bd
Introduced in version 11.0.0

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

Returns 1 if the data is Gzip-formatted, or 0 otherwise.

top
SetDt
EXEC sp_OAMethod @gzip, 'SetDt', @success OUT, @dt

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 1 for success, 0 for failure.

More Information and Examples
top
SetExtraData
EXEC sp_OAMethod @gzip, 'SetExtraData', @success OUT, @encodedData, @encoding
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 1 for success, 0 for failure.

top
UncompressBd
EXEC sp_OAMethod @gzip, 'UncompressBd', @success OUT, @binDat
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 1 for success, 0 for failure.

More Information and Examples
top
UncompressBdToFile
EXEC sp_OAMethod @gzip, 'UncompressBdToFile', @success OUT, @bd, @filePath
Introduced in version 11.0.0

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

Returns 1 for success, 0 for failure.

top
UncompressFile
EXEC sp_OAMethod @gzip, 'UncompressFile', @success OUT, @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 1 for success, 0 for failure.

top
UncompressFileToString
EXEC sp_OAMethod @gzip, 'UncompressFileToString', @sResult OUT, @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 NULL on failure

top
UncompressStringENC
EXEC sp_OAMethod @gzip, 'UncompressStringENC', @sResult OUT, @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 NULL on failure

top
UnTarGz
EXEC sp_OAMethod @gzip, 'UnTarGz', @success OUT, @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 1, absolute paths in the TAR archive are not allowed. This helps protect against extracting files to unsafe locations, such as system directories.

Returns 1 for success, 0 for failure.

More Information and Examples
top
XfdlToXml
EXEC sp_OAMethod @gzip, 'XfdlToXml', @sResult OUT, @xfldData

Converts encoded and compressed XFDL data to a decompressed XML string.

XFDL data is often stored in an ASCII-safe compressed form, such as asci-gzip or asc-gzip. Despite the name, this does not always mean the data is a standard .gz file. In some XFDL files, the compressed payload uses the raw deflate format rather than the full Gzip file format.

Chilkat automatically detects the actual encoding and compression format used by the XFDL data. It decodes the ASCII/Base64 representation, determines whether the compressed data is Gzip or deflate, decompresses it correctly, and returns the resulting XML string.

This allows applications to call XfdlToXml without needing to manually distinguish between XFDL variants such as Base64+Gzip and Base64+Deflate.

Returns the decoded and decompressed 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

More Information and Examples
top

Deprecated

DeflateStringENC
EXEC sp_OAMethod @gzip, 'DeflateStringENC', @sResult OUT, @inString, @charsetName, @outputEncoding
This method is deprecated.

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

More Information and Examples
top
ExamineFile
EXEC sp_OAMethod @gzip, 'ExamineFile', @success OUT, @filePath
This method is deprecated.

Checks whether the specified file contains Gzip-formatted data.

Returns 1 if the file is in Gzip format, or 0 otherwise.

More Information and Examples
top
GetDt
EXEC sp_OAMethod @gzip, 'GetDt', @ckDateTime OUT -- returns a CkDateTime object token
This method is deprecated.

Applications should instead access the LastModStr property.

Gets the last-modification date/time to be embedded within the .gz.

Returns NULL on failure

top
InflateStringENC
EXEC sp_OAMethod @gzip, 'InflateStringENC', @sResult OUT, @inString, @convertFromCharset, @inputEncoding
This method is deprecated.

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

top