---
product: Chilkat
product_version: 11.7.0
language: ckperl
language_label: Perl
class: UnixCompress
class_name: CkUnixCompress
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/perlCkUnixCompressRef.html
---
# Chilkat UnixCompress — Perl — v11.7.0

> Chilkat 11.7.0 · language=ckperl · class=UnixCompress (CkUnixCompress)
> 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/ckperl/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

**Object Creation**

```perl
$obj = chilkat::CkUnixCompress->new();
```

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 Perl.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## 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` | `# $strVal is a string # $ckStr is a CkString $unixCompress->get_DebugLogFilePath($ckStr); $strVal = $unixCompress->debugLogFilePath(); $unixCompress->put_DebugLogFilePath($strVal);` | 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` | `# $strVal is a string # $ckStr is a CkString $unixCompress->get_LastErrorHtml($ckStr); $strVal = $unixCompress->lastErrorHtml();` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `# $strVal is a string # $ckStr is a CkString $unixCompress->get_LastErrorText($ckStr); $strVal = $unixCompress->lastErrorText();` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `# $strVal is a string # $ckStr is a CkString $unixCompress->get_LastErrorXml($ckStr); $strVal = $unixCompress->lastErrorXml();` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `# $boolVal is a boolean $boolVal = $unixCompress->get_LastMethodSuccess(); $unixCompress->put_LastMethodSuccess($boolVal);` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `Utf8` | `# $boolVal is a boolean $boolVal = $unixCompress->get_Utf8(); $unixCompress->put_Utf8($boolVal);` | read/write | When set to `1`, all `string` arguments and return values are interpreted as UTF-8 strings. |
| `VerboseLogging` | `# $boolVal is a boolean $boolVal = $unixCompress->get_VerboseLogging(); $unixCompress->put_VerboseLogging($boolVal);` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `# $strVal is a string # $ckStr is a CkString $unixCompress->get_Version($ckStr); $strVal = $unixCompress->version();` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AbortCurrent` | property, read/write | `# $boolVal is a boolean $boolVal = $unixCompress->get_AbortCurrent(); $unixCompress->put_AbortCurrent($boolVal);` |
| `CompressFile` | method | `# $inFilename is a string # $destPath is a string $status = $unixCompress->CompressFile($inFilename, $destPath);` |
| `CompressStringToFile` | method | `# $inStr is a string # $charset is a string # $destPath is a string $status = $unixCompress->CompressStringToFile($inStr, $charset, $destPath);` |
| `LoadTaskCaller` | method | `# $task is a CkTask $status = $unixCompress->LoadTaskCaller($task);` |
| `UncompressFile` | method | `# $inFilename is a string # $destPath is a string $status = $unixCompress->UncompressFile($inFilename, $destPath);` |
| `UncompressFileToString` | method | `# $zFilename is a string # $charset is a string # $outStr is a CkString (output) $status = $unixCompress->UncompressFileToString($zFilename, $charset, $outStr); $retStr = $unixCompress->uncompressFileToString($zFilename, $charset);` |
| `UnTarZ` | method | `# $zFilename is a string # $destDir is a string # $bNoAbsolute is a boolean $status = $unixCompress->UnTarZ($zFilename, $destDir, $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 · ckperl · UnixCompress · AbortCurrent · property · read/write · since 9.5.0.58`

```perl
# $boolVal is a boolean

$boolVal = $unixCompress->get_AbortCurrent();

$unixCompress->put_AbortCurrent($boolVal);
```

When set to `1`, 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 `0` when the next method is called. When the abort occurs, this property is reset to `0`. Both synchronous and asynchronous method calls can be aborted. (A synchronous method call could be aborted by setting this property from a separate thread.)

## Methods

### UnixCompress.CompressFile

`Chilkat 11.7.0 · ckperl · UnixCompress · CompressFile · method`

```perl
# $inFilename is a string

# $destPath is a string

$status = $unixCompress->CompressFile($inFilename, $destPath);
```

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

Returns 1 for success, 0 for failure.

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

### UnixCompress.CompressStringToFile

`Chilkat 11.7.0 · ckperl · UnixCompress · CompressStringToFile · method`

```perl
# $inStr is a string

# $charset is a string

# $destPath is a string

$status = $unixCompress->CompressStringToFile($inStr, $charset, $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 1 for success, 0 for failure.

### UnixCompress.LoadTaskCaller

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

```perl
# $task is a CkTask

$status = $unixCompress->LoadTaskCaller($task);
```

Loads the caller of the task's async method.

Returns 1 for success, 0 for failure.

### UnixCompress.UncompressFile

`Chilkat 11.7.0 · ckperl · UnixCompress · UncompressFile · method`

```perl
# $inFilename is a string

# $destPath is a string

$status = $unixCompress->UncompressFile($inFilename, $destPath);
```

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

Returns 1 for success, 0 for failure.

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

### UnixCompress.UncompressFileToString

`Chilkat 11.7.0 · ckperl · UnixCompress · UncompressFileToString · method`

```perl
# $zFilename is a string

# $charset is a string

# $outStr is a CkString (output)

$status = $unixCompress->UncompressFileToString($zFilename, $charset, $outStr);

$retStr = $unixCompress->uncompressFileToString($zFilename, $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 1 for success, 0 for failure.

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

### UnixCompress.UnTarZ

`Chilkat 11.7.0 · ckperl · UnixCompress · UnTarZ · method`

```perl
# $zFilename is a string

# $destDir is a string

# $bNoAbsolute is a boolean

$status = $unixCompress->UnTarZ($zFilename, $destDir, $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 1 for success, 0 for failure.

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

## Events and callbacks

This binding has no event callbacks. For progress, percent-done or cancellation use the `*Async` variant of a method and poll the returned `Task` (`PercentDone`, `Finished`, `Cancel`).

## 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.

```perl
# returns a CkTask

# $inFilename is a string

# $destPath is a string

$ret_task = $unixCompress->CompressFileAsync($inFilename, $destPath);
# returns a CkTask

# $inFilename is a string

# $destPath is a string

$ret_task = $unixCompress->UncompressFileAsync($inFilename, $destPath);
# returns a CkTask

# $zFilename is a string

# $charset is a string

$ret_task = $unixCompress->UncompressFileToStringAsync($zFilename, $charset);
# returns a CkTask

# $zFilename is a string

# $destDir is a string

# $bNoAbsolute is a boolean

$ret_task = $unixCompress->UnTarZAsync($zFilename, $destDir, $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/ckperl/classes/Task.md)

