---
product: Chilkat
product_version: 11.7.0
language: c
language_label: C
class: UnixCompress
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/c_CkUnixCompressRef.html
---
# Chilkat UnixCompress — C — v11.7.0

> Chilkat 11.7.0 · language=c · class=UnixCompress
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/UnixCompress.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/c/guide.md`.

## Purpose

**Compress, uncompress, and unpack legacy UNIX `.Z` files.**

`Chilkat.UnixCompress` provides UNIX `compress` and `uncompress` functionality for legacy `.Z` files. It supports file-based, memory-based, and string-based workflows, uses LZW compression, can unpack `.tar.Z` archives, and includes abort and progress-related support for longer-running operations.

**Compress to .Z**

Compress files, memory data, or strings into UNIX `.Z` format using LZW compression.

**Uncompress .Z data**

Expand UNIX-compressed data back to files, memory, byte arrays, or text depending on the application workflow.

**File workflows**

Compress and uncompress directly between input and output files when working with existing filesystem data.

**Memory workflows**

Work with compressed or uncompressed byte data in memory when temporary files are not desired.

**String workflows**

Compress and uncompress text using an explicit character set so string data round-trips correctly.

**Unpack tar.Z archives**

Use `UnTarZ` to decompress and extract legacy `.tar.Z` archives in a single workflow.

**Common pattern:** Use `UnixCompress` when the data is in classic UNIX `.Z` format or when a `.tar.Z` archive must be unpacked. Use `Chilkat.Gzip` for `.gz` and `.tar.gz` files, `Chilkat.Bz2` for `.bz2` files, and `Chilkat.Compression` for raw compression algorithms and general-purpose compression workflows.

For an extended overview, see [UnixCompress Class Overview](https://www.chilkatsoft.com/unixcompress_class_overview.asp).

## Object creation, unlocking and error handling

**Create/Dispose**

```c
HCkUnixCompress instance = CkUnixCompress_Create();
// ...
CkUnixCompress_Dispose(instance);
```

`HCkUnixCompress CkUnixCompress_Create(void);`

Creates an instance of the HCkUnixCompress object and returns a handle ("void \*" pointer). The handle is passed in the 1st argument for the functions listed on this page.

`void CkUnixCompress_Dispose(HCkUnixCompress handle);`

Objects created by calling CkUnixCompress_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkUnixCompress_Dispose.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in C.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `void CkUnixCompress_getDebugLogFilePath(HCkUnixCompress cHandle, HCkString retval); void CkUnixCompress_putDebugLogFilePath(HCkUnixCompress cHandle, const char *newVal); const char *CkUnixCompress_debugLogFilePath(HCkUnixCompress cHandle);` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `void CkUnixCompress_getLastErrorHtml(HCkUnixCompress cHandle, HCkString retval); const char *CkUnixCompress_lastErrorHtml(HCkUnixCompress cHandle);` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `void CkUnixCompress_getLastErrorText(HCkUnixCompress cHandle, HCkString retval); const char *CkUnixCompress_lastErrorText(HCkUnixCompress cHandle);` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `void CkUnixCompress_getLastErrorXml(HCkUnixCompress cHandle, HCkString retval); const char *CkUnixCompress_lastErrorXml(HCkUnixCompress cHandle);` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `BOOL CkUnixCompress_getLastMethodSuccess(HCkUnixCompress cHandle); void CkUnixCompress_putLastMethodSuccess(HCkUnixCompress cHandle, BOOL newVal);` | read/write | Indicates the success or failure of the most recent method call: `TRUE` means success, `FALSE` means failure. |
| `Utf8` | `BOOL CkUnixCompress_getUtf8(HCkUnixCompress cHandle); void CkUnixCompress_putUtf8(HCkUnixCompress cHandle, BOOL newVal);` | read/write | When set to `TRUE`, all `const char *` arguments and return values are interpreted as UTF-8 strings. |
| `VerboseLogging` | `BOOL CkUnixCompress_getVerboseLogging(HCkUnixCompress cHandle); void CkUnixCompress_putVerboseLogging(HCkUnixCompress cHandle, BOOL newVal);` | read/write | If set to `TRUE`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `void CkUnixCompress_getVersion(HCkUnixCompress cHandle, HCkString retval); const char *CkUnixCompress_version(HCkUnixCompress cHandle);` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AbortCurrent` | property, read/write | `BOOL CkUnixCompress_getAbortCurrent(HCkUnixCompress cHandle); void CkUnixCompress_putAbortCurrent(HCkUnixCompress cHandle, BOOL newVal);` |
| `HeartbeatMs` | property, read/write | `int CkUnixCompress_getHeartbeatMs(HCkUnixCompress cHandle); void CkUnixCompress_putHeartbeatMs(HCkUnixCompress cHandle, int newVal);` |
| `CompressFile` | method | `BOOL CkUnixCompress_CompressFile(HCkUnixCompress cHandle, const char *inFilename, const char *destPath);` |
| `CompressStringToFile` | method | `BOOL CkUnixCompress_CompressStringToFile(HCkUnixCompress cHandle, const char *inStr, const char *charset, const char *destPath);` |
| `LoadTaskCaller` | method | `BOOL CkUnixCompress_LoadTaskCaller(HCkUnixCompress cHandle, HCkTask task);` |
| `UncompressFile` | method | `BOOL CkUnixCompress_UncompressFile(HCkUnixCompress cHandle, const char *inFilename, const char *destPath);` |
| `UncompressFileToString` | method | `BOOL CkUnixCompress_UncompressFileToString(HCkUnixCompress cHandle, const char *zFilename, const char *charset, HCkString outStr); const char *CkUnixCompress_uncompressFileToString(HCkUnixCompress cHandle, const char *zFilename, const char *charset);` |
| `UnTarZ` | method | `BOOL CkUnixCompress_UnTarZ(HCkUnixCompress cHandle, const char *zFilename, const char *destDir, BOOL bNoAbsolute);` |

Deprecated members are listed at the end of this file with their replacements; do not use them in new code.

## Properties

### UnixCompress.AbortCurrent

`Chilkat 11.7.0 · c · UnixCompress · AbortCurrent · property · read/write · since 9.5.0.58`

```c
BOOL CkUnixCompress_getAbortCurrent(HCkUnixCompress cHandle);
void CkUnixCompress_putAbortCurrent(HCkUnixCompress cHandle, BOOL newVal);
```

When set to `TRUE`, causes the currently running method to abort. Methods that always finish quickly (i.e.have no length file operations or network communications) are not affected. If no method is running, then this property is automatically reset to `FALSE` when the next method is called. When the abort occurs, this property is reset to `FALSE`. Both synchronous and asynchronous method calls can be aborted. (A synchronous method call could be aborted by setting this property from a separate thread.)

### UnixCompress.HeartbeatMs

`Chilkat 11.7.0 · c · UnixCompress · HeartbeatMs · property · read/write`

```c
int CkUnixCompress_getHeartbeatMs(HCkUnixCompress cHandle);
void CkUnixCompress_putHeartbeatMs(HCkUnixCompress cHandle, int newVal);
```

**Full documentation for this property (same in every language):** [Event Callback Examples](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/event_callback_examples.md)

The interval in milliseconds between each `AbortCheck` event callback, which enables an application to abort certain method calls before they complete. **By default, HeartbeatMs is set to** `0`**, meaning no AbortCheck event callbacks will trigger.**

## Methods

### UnixCompress.CompressFile

`Chilkat 11.7.0 · c · UnixCompress · CompressFile · method`

```c
BOOL CkUnixCompress_CompressFile(HCkUnixCompress cHandle, const char *inFilename, const char *destPath);
```

Compresses a file to create a UNIX compressed file (.Z). This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.

Returns TRUE for success, FALSE for failure.

Async variant: `CompressFileAsync` — same arguments, returns a `Task` (see Async variants below).

### UnixCompress.CompressStringToFile

`Chilkat 11.7.0 · c · UnixCompress · CompressStringToFile · method`

```c
BOOL CkUnixCompress_CompressStringToFile(HCkUnixCompress cHandle, const char *inStr, const char *charset, const char *destPath);
```

**Full documentation for this method (same in every language):** [List of Valid Charsets](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Unix compresses and creates a .Z file from string data. The `charset` specifies the character encoding used for the byte representation of the characters when compressed. The `charset` can be any one of a large number of character encodings, such as `utf-8`, `iso-8859-1`, `Windows-1252`, `ucs-2`, etc.

Returns TRUE for success, FALSE for failure.

### UnixCompress.LoadTaskCaller

`Chilkat 11.7.0 · c · UnixCompress · LoadTaskCaller · method · since 9.5.0.80`

```c
BOOL CkUnixCompress_LoadTaskCaller(HCkUnixCompress cHandle, HCkTask task);
```

Loads the caller of the task's async method.

Returns TRUE for success, FALSE for failure.

### UnixCompress.UncompressFile

`Chilkat 11.7.0 · c · UnixCompress · UncompressFile · method`

```c
BOOL CkUnixCompress_UncompressFile(HCkUnixCompress cHandle, const char *inFilename, const char *destPath);
```

Uncompresses a .Z file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)

Returns TRUE for success, FALSE for failure.

Async variant: `UncompressFileAsync` — same arguments, returns a `Task` (see Async variants below).

### UnixCompress.UncompressFileToString

`Chilkat 11.7.0 · c · UnixCompress · UncompressFileToString · method`

```c
BOOL CkUnixCompress_UncompressFileToString(HCkUnixCompress cHandle, const char *zFilename, const char *charset, HCkString outStr);
const char *CkUnixCompress_uncompressFileToString(HCkUnixCompress cHandle, const char *zFilename, const char *charset);
```

**Full documentation for this method (same in every language):** [List of Valid Charsets](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Uncompresses a .Z 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 TRUE for success, FALSE for failure.

Async variant: `UncompressFileToStringAsync` — same arguments, returns a `Task` (see Async variants below).

### UnixCompress.UnTarZ

`Chilkat 11.7.0 · c · UnixCompress · UnTarZ · method`

```c
BOOL CkUnixCompress_UnTarZ(HCkUnixCompress cHandle, const char *zFilename, const char *destDir, BOOL bNoAbsolute);
```

Unpacks a .tar.Z file. The decompress and untar occur in streaming mode. There are no temporary files and the memory footprint is constant (and small) while untarring.

Returns TRUE for success, FALSE for failure.

Async variant: `UnTarZAsync` — same arguments, returns a `Task` (see Async variants below).

## Events and callbacks

This binding delivers progress information through callbacks (AbortCheck, PercentDone, ProgressInfo, TaskCompleted) rather than events. See `guide.md` for how to attach them in C.

## Async variants

Each returns a `Task` instead of the result and takes the same arguments as the synchronous method; run the task, wait for `Finished`, then read the result from the task. No new Async methods are added from 11.7.0 on.

```c
HCkTask CkUnixCompress_CompressFileAsync(HCkUnixCompress cHandle, const char *inFilename, const char *destPath);
HCkTask CkUnixCompress_UncompressFileAsync(HCkUnixCompress cHandle, const char *inFilename, const char *destPath);
HCkTask CkUnixCompress_UncompressFileToStringAsync(HCkUnixCompress cHandle, const char *zFilename, const char *charset);
HCkTask CkUnixCompress_UnTarZAsync(HCkUnixCompress cHandle, const char *zFilename, const char *destDir, BOOL bNoAbsolute);
```

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `CompressFileToMem` | method | before 11.6.1 | — |
| `CompressMemory` | method | before 11.6.1 | — |
| `CompressMemToFile` | method | before 11.6.1 | — |
| `CompressString` | method | before 11.6.1 | — |
| `UncompressFileToMem` | method | before 11.6.1 | — |
| `UncompressMemory` | method | before 11.6.1 | — |
| `UncompressMemToFile` | method | before 11.6.1 | — |
| `UncompressString` | method | before 11.6.1 | — |

## Related classes

[`Task`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/c/classes/Task.md)

