TGzip Delphi Reference

TGzip

GZip compression component.

Object Creation

var
obj: TGzip;
...
begin
obj := TGzip.Create(Self);
...
// When finished, free the object instance.
obj.Free();

Properties

property Comment: WideString

Specifies an optional comment string that can be embedded within the .gz when any Compress* method is called.

property ExtraData: OleVariant

Optional extra-data that can be included within a .gz when a Compress* method is called.

property Filename: WideString

The filename that is embedded within the .gz during any Compress* method call. When extracting from a .gz using applications such as WinZip, this will be the filename that is created.

property LastErrorHtml: WideString readonly

Error information in HTML format for the last method called.

property LastErrorText: WideString readonly

Error information in plain-text format for the last method called.

property LastErrorXml: WideString readonly

Error information in XML format for the last method called.

property LastMod: TDateTime

The last-modification date/time to be embedded within the .gz when a Compress* method is called. By default, the current system date/time is used.

property UseCurrentDate: Integer

If set to 1, the file produced by an Uncompress* method will use the current date/time for the last-modification date instead of the date/time found within the Gzip format.

property VerboseLogging: Integer

To be documented soon...

property Version: WideString readonly

Version of the component, such as "1.0.0"

Methods

function CompressFile(inFilename: WideString, outGzipFilename: WideString): Integer;

Compresses a file to create a GZip compressed file (.gz).

Returns 1 for success, 0 for failure.

function CompressFile2(inFilename: WideString, embeddedFilename: WideString, outGzipFilename: WideString): Integer;

Compresses a file to create a GZip compressed file (.gz). inFilename is the actual filename on disk. embeddedFilename is the filename to be embedded in the .gz such that when it is un-gzipped, this is the name of the file that will be created.

Returns 1 for success, 0 for failure.

function CompressFileToMem(inFilename: WideString): OleVariant;

Gzip compresses a file to an in-memory image of a .gz file.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

function CompressMemToFile(inData: OleVariant, outFilename: WideString): Integer;

Gzip compresses and creates a .gz file from in-memory data.

Returns 1 for success, 0 for failure.

function CompressMemory(inData: OleVariant): OleVariant;

Compresses in-memory data to an in-memory image of a .gz file.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

function CompressString(inString: WideString, outCharset: WideString): OleVariant;

Gzip compresses a string and writes the output to a byte array. The string is first converted to the charset specified by outCharset. Typical charsets are "utf-8", "iso-8859-1", "shift_JIS", etc.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

Full List of Charset Names

function CompressStringToFile(inStr: WideString, outCharset: WideString, outFilename: WideString): Integer;

Gzip compresses a string and writes the output to a .gz compressed file. The string is first converted to the charset specified by ARG2. Typical charsets are "utf-8", "iso-8859-1", "shift_JIS", etc.

Returns 1 for success, 0 for failure.

Full List of Charset Names

function Decode(encodedStr: WideString, encoding: WideString): OleVariant;

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 a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

function DeflateStringENC(inString: WideString, charsetName: WideString, outputEncoding: WideString): WideString;

Provides the ability to use the zip/gzip's deflate algorithm directly to compress a string. Internal to this method, inString is first converted to the charset specified by charsetName. The data is then compressed using the deflate compression algorithm. The binary output is then encoded according to outputEncoding. Possible values for outputEncoding are "hex", "base64", "url", and "quoted-printable".

Note: The output of this method is compressed data with no Gzip file format. Use the Compress* methods to produce Gzip file format output.

Returns a zero-length WideString on failure

Full List of Charset Names

function Encode(byteData: OleVariant, encoding: WideString): WideString;

Encodes binary data to a printable string. The encoding mode is determined by encoding. It may be "base64", "hex", "quoted-printable", or "url".

Returns a zero-length WideString on failure

function ExamineFile(inGzFilename: WideString): Integer;

Determines if the inGzFilename is a Gzip formatted file. Returns 1 if it is a Gzip formatted file, otherwise returns 0.

function ExamineMemory(inGzData: OleVariant): Integer;

Determines if the in-memory bytes (inGzData) contain a Gzip formatted file. Returns 1 if it is Gzip format, otherwise returns 0.

function InflateStringENC(inString: WideString, convertFromCharset: WideString, inputEncoding: WideString): WideString;

This the reverse of DeflateStringENC.

The input string is first decoded according to inputEncoding. (Possible values for inputEncoding are "hex", "base64", "url", and "quoted-printable".) The compressed data is then inflated, and the result is then converted from convertFromCharset (if necessary) to return a string.

Returns a zero-length WideString on failure

function IsUnlocked(): Integer;

Returns 1 if the component has been unlocked.

function ReadFile(filename: WideString): OleVariant;

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 a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

procedure SaveLastError(filename: WideString);

Saves the last error information to an XML formatted file.

function UnTarGz(tgzFilename: WideString, destDir: WideString, bNoAbsolute: Integer): Integer;

Unpacks a .tar.gz file. The ungzip and untar occur in streaming mode. There are no temporary files and the memory footprint is constant (and small) while untarring. bNoAbsolute may be 1 or 0. A value of 1 protects from untarring to absolute paths. (For example, imagine the trouble if the tar contains files with absolute paths beginning with /Windows/system32)

Returns 1 for success, 0 for failure.

function UncompressFile(inFilename: WideString, outFilename: WideString): Integer;

Un-Gzips a .gz file. The output filename is specified by the 2nd argument and not by the filename embedded within the .gz.

Returns 1 for success, 0 for failure.

function UncompressFileToMem(inFilename: WideString): OleVariant;

Un-Gzips a .gz file directly to memory.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

function UncompressFileToString(gzFilename: WideString, charset: WideString): WideString;

Uncompresses a .gz file that contains a text file. The contents of the text file are returned as a string. The character encoding of the text file is specified by charset. Typical charsets are "iso-8859-1", "utf-8", "windows-1252", "shift_JIS", "big5", etc.

Returns a zero-length WideString on failure

List of Valid Charsets

function UncompressMemToFile(inData: OleVariant, outFilename: WideString): Integer;

Un-Gzips from an in-memory image of a .gz file to a file.

Returns 1 for success, 0 for failure.

function UncompressMemory(inData: OleVariant): OleVariant;

Un-Gzips from an in-memory image of a .gz file directly into memory.

Returns a zero-length byte array (as an OleVariant) on failure.
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

function UncompressString(inData: OleVariant, inCharset: WideString): WideString;

The reverse of CompressString.

The bytes in inData are uncompressed, then converted from inCharset (if necessary) to return a string.

Returns a zero-length WideString on failure

Full List of Charset Names

function UnlockComponent(b1: WideString): Integer;

Unlocks the component allowing for the full functionality to be used.

Returns 1 for success, 0 for failure.

function WriteFile(filename: WideString, binaryData: OleVariant): Integer;

A convenience method for writing a binary byte array to a file.

Returns 1 for success, 0 for failure.

function XfdlToXml(xfldData: WideString): WideString;

Converts base64-gzip .xfdl data to a decompressed XML string. The xfldData contains the base64 data. This method returns the decoded/decompressed XML string.

Returns a zero-length WideString on failure