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

> Chilkat 11.7.0 · language=csharp · 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/csharp/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**

```csharp
Chilkat.UnixCompress obj = new Chilkat.UnixCompress();
```

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

Minimal complete program:

```csharp
// Required once per process. Any string unlocks a 30-day trial; use your purchased code in production.
Chilkat.Global glob = new Chilkat.Global();
if (!glob.UnlockBundle("Anything for 30-day trial"))
{
    Console.WriteLine(glob.LastErrorText);
    return;
}

Chilkat.UnixCompress unixCompress = new Chilkat.UnixCompress();

bool success = unixCompress.CompressFile("<inFilename>", "<destPath>");
if (!success)
{
    Console.WriteLine(unixCompress.LastErrorText);   // full diagnostic of what went wrong
    return;
}
```

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` | `public string DebugLogFilePath {get; set; }` | 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` | `public string LastErrorHtml {get; }` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `public string LastErrorText {get; }` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `public string LastErrorXml {get; }` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `public bool LastMethodSuccess {get; set; }` | read/write | Indicates the success or failure of the most recent method call: `true` means success, `false` means failure. |
| `VerboseLogging` | `public bool VerboseLogging {get; set; }` | read/write | If set to `true`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `public string Version {get; }` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AbortCurrent` | property, read/write | `public bool AbortCurrent {get; set; }` |
| `HeartbeatMs` | property, read/write | `public int HeartbeatMs {get; set; }` |
| `CompressFile` | method | `public bool CompressFile(string inFilename, string destPath);` |
| `CompressFileToMem` | method | `public byte[] CompressFileToMem(string inFilename);` |
| `CompressMemory` | method | `public byte[] CompressMemory(byte[] inData);` |
| `CompressMemToFile` | method | `public bool CompressMemToFile(byte[] inData, string destPath);` |
| `CompressString` | method | `public byte[] CompressString(string inStr, string charset);` |
| `CompressStringToFile` | method | `public bool CompressStringToFile(string inStr, string charset, string destPath);` |
| `LoadTaskCaller` | method | `public bool LoadTaskCaller(Task task);` |
| `UncompressFile` | method | `public bool UncompressFile(string inFilename, string destPath);` |
| `UncompressFileToMem` | method | `public byte[] UncompressFileToMem(string inFilename);` |
| `UncompressFileToString` | method | `public string UncompressFileToString(string zFilename, string charset);` |
| `UncompressMemory` | method | `public byte[] UncompressMemory(byte[] inData);` |
| `UncompressMemToFile` | method | `public bool UncompressMemToFile(byte[] inData, string destPath);` |
| `UncompressString` | method | `public string UncompressString(byte[] inCompressedData, string charset);` |
| `UnTarZ` | method | `public bool UnTarZ(string zFilename, string destDir, bool bNoAbsolute);` |

## Properties

### UnixCompress.AbortCurrent

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

```csharp
public bool AbortCurrent {get; set; }
```

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 · csharp · UnixCompress · HeartbeatMs · property · read/write`

```csharp
public int HeartbeatMs {get; set; }
```

**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 · csharp · UnixCompress · CompressFile · method`

```csharp
public bool CompressFile(string inFilename, string 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.CompressFileToMem

`Chilkat 11.7.0 · csharp · UnixCompress · CompressFileToMem · method`

```csharp
public byte[] CompressFileToMem(string inFilename);
```

Unix compresses a file to an in-memory image of a .Z file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)

Returns an empty byte array on failure

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

### UnixCompress.CompressMemory

`Chilkat 11.7.0 · csharp · UnixCompress · CompressMemory · method`

```csharp
public byte[] CompressMemory(byte[] inData);
```

Compresses in-memory data to an in-memory image of a .Z file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)

Returns an empty byte array on failure

### UnixCompress.CompressMemToFile

`Chilkat 11.7.0 · csharp · UnixCompress · CompressMemToFile · method`

```csharp
public bool CompressMemToFile(byte[] inData, string destPath);
```

Unix compresses and creates a .Z file from in-memory data. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)

Returns true for success, false for failure.

### UnixCompress.CompressString

`Chilkat 11.7.0 · csharp · UnixCompress · CompressString · method`

```csharp
public byte[] CompressString(string inStr, string 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)

Compresses a string to an in-memory image of a .Z file. Prior to compression, the string is converted to the character encoding specified by `charset`. 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 an empty byte array on failure

### UnixCompress.CompressStringToFile

`Chilkat 11.7.0 · csharp · UnixCompress · CompressStringToFile · method`

```csharp
public bool CompressStringToFile(string inStr, string charset, string 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 · csharp · UnixCompress · LoadTaskCaller · method · since 9.5.0.80`

```csharp
public bool LoadTaskCaller(Task task);
```

Loads the caller of the task's async method.

Returns true for success, false for failure.

### UnixCompress.UncompressFile

`Chilkat 11.7.0 · csharp · UnixCompress · UncompressFile · method`

```csharp
public bool UncompressFile(string inFilename, string 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.UncompressFileToMem

`Chilkat 11.7.0 · csharp · UnixCompress · UncompressFileToMem · method`

```csharp
public byte[] UncompressFileToMem(string inFilename);
```

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

Returns an empty byte array on failure

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

### UnixCompress.UncompressFileToString

`Chilkat 11.7.0 · csharp · UnixCompress · UncompressFileToString · method`

```csharp
public string UncompressFileToString(string zFilename, string 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 `null` on failure

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

### UnixCompress.UncompressMemory

`Chilkat 11.7.0 · csharp · UnixCompress · UncompressMemory · method`

```csharp
public byte[] UncompressMemory(byte[] inData);
```

Uncompresses from an in-memory image of a .Z file directly into memory. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)

Returns an empty byte array on failure

### UnixCompress.UncompressMemToFile

`Chilkat 11.7.0 · csharp · UnixCompress · UncompressMemToFile · method`

```csharp
public bool UncompressMemToFile(byte[] inData, string destPath);
```

Uncompresses from an in-memory image of a .Z file to a file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)

Returns true for success, false for failure.

### UnixCompress.UncompressString

`Chilkat 11.7.0 · csharp · UnixCompress · UncompressString · method`

```csharp
public string UncompressString(byte[] inCompressedData, string 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 from an in-memory image of a .Z file directly to a string. The `charset` specifies the character encoding used to interpret the bytes resulting from the decompression. 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 `null` on failure

### UnixCompress.UnTarZ

`Chilkat 11.7.0 · csharp · UnixCompress · UnTarZ · method`

```csharp
public bool UnTarZ(string zFilename, string 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

### UnixCompress.AbortCheck (event)

`Chilkat 11.7.0 · csharp · UnixCompress · AbortCheck · event`

```csharp
public event AbortCheckEventHandler OnAbortCheck;
```

Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the `HeartbeatMs` property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.AbortCheckEventArgs

**Event callback implementation:**

```csharp
private void unixcompress_OnAbortCheck(object sender, Chilkat.AbortCheckEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
unixcompress.OnAbortCheck += unixcompress_OnAbortCheck;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handleAbortCheck(out bool abort)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
// ...
Chilkat.UnixCompress.AbortCheck abortCheck = new Chilkat.UnixCompress.AbortCheck(handleAbortCheck);
unixcompress.setAbortCheckCb(abortCheck);
```

### UnixCompress.PercentDone (event)

`Chilkat 11.7.0 · csharp · UnixCompress · PercentDone · event`

```csharp
public event PercentDoneEventHandler OnPercentDone;
```

This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The `pctDone` argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have `pctDone` equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).

The PercentDone callback also acts as an `AbortCheck` event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.

To abort the operation, set the `abort` output argument to `true`. This will cause the method to terminate and return a failure status or corresponding failure value.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.PercentDoneEventArgs

**Event callback implementation:**

```csharp
private void unixcompress_OnPercentDone(object sender, Chilkat.PercentDoneEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
unixcompress.OnPercentDone += unixcompress_OnPercentDone;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handlePercentDone(int pctDone, out bool abort)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
// ...
Chilkat.UnixCompress.PercentDone percentDone = new Chilkat.UnixCompress.PercentDone(handlePercentDone);
unixcompress.setPercentDoneCb(percentDone);
```

### UnixCompress.ProgressInfo (event)

`Chilkat 11.7.0 · csharp · UnixCompress · ProgressInfo · event`

```csharp
public event ProgressInfoEventHandler OnProgressInfo;
```

This event callback provides `tag name`/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.

Note: Some Chilkat methods don't fire any ProgressInfo events.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.ProgressInfoEventArgs

**Event callback implementation:**

```csharp
private void unixcompress_OnProgressInfo(object sender, Chilkat.ProgressInfoEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
unixcompress.OnProgressInfo += unixcompress_OnProgressInfo;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handleProgressInfo(string name, string value)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
// ...
Chilkat.UnixCompress.ProgressInfo progressInfo = new Chilkat.UnixCompress.ProgressInfo(handleProgressInfo);
unixcompress.setProgressInfoCb(progressInfo);
```

### UnixCompress.TaskCompleted (event)

`Chilkat 11.7.0 · csharp · UnixCompress · TaskCompleted · event`

```csharp
public event TaskCompletedEventHandler OnTaskCompleted;
```

Called from the background thread when an asynchronous task completes.

### Chilkat .NET Framework Event Implementation

Args are passed using Chilkat.TaskCompletedEventArgs

**Event callback implementation:**

```csharp
private void unixcompress_OnTaskCompleted(object sender, Chilkat.TaskCompletedEventArgs args)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
unixcompress.OnTaskCompleted += unixcompress_OnTaskCompleted;
```

### Chilkat .NET Core Event Implementation

**Event callback implementation:**

```csharp
public void handleTaskIdCompleted(int taskId)
	{
	    // application code goes here.
	}
```

**To add an event handler:**

```csharp
Chilkat.UnixCompress unixcompress = new Chilkat.UnixCompress();
// ...
Chilkat.UnixCompress.TaskIdCompleted taskIdCompleted = new Chilkat.UnixCompress.TaskIdCompleted(handleTaskIdCompleted);
unixcompress.setTaskIdCompletedCb(taskIdCompleted);
```

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

```csharp
public Task CompressFileAsync(string inFilename, string destPath);
public Task CompressFileToMemAsync(string inFilename);
public Task UncompressFileAsync(string inFilename, string destPath);
public Task UncompressFileToMemAsync(string inFilename);
public Task UncompressFileToStringAsync(string zFilename, string charset);
public Task UnTarZAsync(string zFilename, string destDir, bool bNoAbsolute);
```

## Related classes

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

