---
product: Chilkat
product_version: 11.7.0
language: purebasic
language_label: PureBasic
class: Compression
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/pbCompressionRef.html
---
# Chilkat Compression — PureBasic — v11.7.0

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

## Purpose

**Compress and decompress bytes, text, files, and streams with a flexible API.**

`Chilkat.Compression` provides a general-purpose API for compressing and decompressing data in memory, files, and streams. It supports multiple algorithms, text charset conversion, encoded output, chunked processing, and streaming operations for large data.

**Multiple algorithms**

Supports `deflate`, `zlib`, `bzip2`, and `lzw`.

**Flexible data types**

Work with byte arrays, strings, `BinData`, `StringBuilder`, files, and streams.

**Chunked processing**

Process data incrementally with `FirstChunk` and `LastChunk` for chunk-aware methods.

**Encoded output**

Return compressed bytes as text using encodings such as `base64`, `hex`, and others.

**Streaming support**

Compress or decompress large files and streams with stable memory usage.

**Compression + encryption**

Combine compression and encryption in file workflows with integrated methods.

**Tip:** For text compression, explicitly set `Charset = "utf-8"` unless another encoding is required. For encoded compressed data, set `EncodingMode` to the desired output format.

For an extended overview, see [Compression Class Overview](https://www.chilkatsoft.com/compression_class_overview.asp). See also [Binary Encodings](https://www.chilkatsoft.com/binary_encodings.asp) for supported encoded output formats.

## Object creation, unlocking and error handling

**Object Creation**

```purebasic
obj.i = CkCompression::ckCreate()

; Make sure to dispose of the object when finished like this:
CkCompression::ckDispose(obj);
```

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

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` | `Declare.s ckDebugLogFilePath(obj.i) Declare setCkDebugLogFilePath(obj.i, value.s)` | 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` | `Declare.s ckLastErrorHtml(obj.i) ; (read-only)` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `Declare.s ckLastErrorText(obj.i) ; (read-only)` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `Declare.s ckLastErrorXml(obj.i) ; (read-only)` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `Declare.i ckLastMethodSuccess(obj.i) Declare setCkLastMethodSuccess(obj.i, value.i)` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `VerboseLogging` | `Declare.i ckVerboseLogging(obj.i) Declare setCkVerboseLogging(obj.i, value.i)` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `Declare.s ckVersion(obj.i) ; (read-only)` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `Algorithm` | property, read/write | `Declare.s ckAlgorithm(obj.i) Declare setCkAlgorithm(obj.i, value.s)` |
| `Charset` | property, read/write | `Declare.s ckCharset(obj.i) Declare setCkCharset(obj.i, value.s)` |
| `DeflateLevel` | property, read/write | `Declare.i ckDeflateLevel(obj.i) Declare setCkDeflateLevel(obj.i, value.i)` |
| `EncodingMode` | property, read/write | `Declare.s ckEncodingMode(obj.i) Declare setCkEncodingMode(obj.i, value.s)` |
| `FirstChunk` | property, read/write | `Declare.i ckFirstChunk(obj.i) Declare setCkFirstChunk(obj.i, value.i)` |
| `LastChunk` | property, read/write | `Declare.i ckLastChunk(obj.i) Declare setCkLastChunk(obj.i, value.i)` |
| `UncommonOptions` | property, read/write | `Declare.s ckUncommonOptions(obj.i) Declare setCkUncommonOptions(obj.i, value.s)` |
| `CompressBd` | method | `Declare.i ckCompressBd(obj.i, bd.i)` |
| `CompressBd2` | method | `Declare.i ckCompressBd2(obj.i, bdIn.i, bdOut.i)` |
| `CompressEncryptFile` | method | `Declare.i ckCompressEncryptFile(obj.i, cryptParams.i, srcPath.s, destPath.s)` |
| `CompressFile` | method | `Declare.i ckCompressFile(obj.i, srcPath.s, destPath.s)` |
| `CompressSb` | method | `Declare.i ckCompressSb(obj.i, sb.i, binData.i)` |
| `CompressStr` | method | `Declare.i ckCompressStr(obj.i, str.s, bd.i)` |
| `CompressStream` | method | `Declare.i ckCompressStream(obj.i, strm.i)` |
| `CompressStringENC` | method | `Declare.s ckCompressStringENC(obj.i, str.s)` |
| `DecompressBd` | method | `Declare.i ckDecompressBd(obj.i, bd.i)` |
| `DecompressBd2` | method | `Declare.i ckDecompressBd2(obj.i, bdIn.i, bdOut.i)` |
| `DecompressFile` | method | `Declare.i ckDecompressFile(obj.i, srcPath.s, destPath.s)` |
| `DecompressSb` | method | `Declare.i ckDecompressSb(obj.i, binData.i, sb.i)` |
| `DecompressStream` | method | `Declare.i ckDecompressStream(obj.i, strm.i)` |
| `DecompressStringENC` | method | `Declare.s ckDecompressStringENC(obj.i, encodedCompressedData.s)` |
| `DecryptDecompressFile` | method | `Declare.i ckDecryptDecompressFile(obj.i, cryptParams.i, srcPath.s, destPath.s)` |
| `LoadTaskCaller` | method | `Declare.i ckLoadTaskCaller(obj.i, task.i)` |

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

## Properties

### Compression.Algorithm

`Chilkat 11.7.0 · purebasic · Compression · Algorithm · property · read/write`

```purebasic
Declare.s ckAlgorithm(obj.i)
Declare setCkAlgorithm(obj.i, value.s)
```

Specifies the compression algorithm to use. Supported values are `deflate`, `zlib`, `gzip`, `bzip2`, and `lzw`.

The `zlib` option is the deflate algorithm with a zlib header.

The `gzip` option (starting in v11.7.0) is the deflate algorithm in the gzip format (RFC 1952): a gzip header, the deflate data, and a trailer with the CRC-32 and size of the uncompressed data. When decompressing in one call, the CRC-32 and size are checked. Before v11.7.0, `gzip` was not recognized and was treated as `deflate`.

**Note:** `ppmd` is deprecated and should not be used. It was only available on 32-bit systems and specifically used the J variant. New applications should use one of the supported algorithms listed above.

### Compression.Charset

`Chilkat 11.7.0 · purebasic · Compression · Charset · property · read/write`

```purebasic
Declare.s ckCharset(obj.i)
Declare setCkCharset(obj.i, value.s)
```

**Full documentation for this property (same in every language):** [How Character Encoding (Charset) Affects Compression and Decompression](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/how_charset_affects_compression.md) · [Full List of Character Encodings Supported by Chilkat](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Specifies the character encoding used when converting text to bytes before compression, and bytes back to text after decompression.

The current default is the computer’s ANSI charset, such as Windows-1252 on many Western Windows systems. However, most modern applications should explicitly set this property to `utf-8`.

**Recommendation:** Set `Charset = "utf-8"` unless you specifically need compatibility with another encoding.

### Compression.DeflateLevel

`Chilkat 11.7.0 · purebasic · Compression · DeflateLevel · property · read/write · since 9.5.0.73`

```purebasic
Declare.i ckDeflateLevel(obj.i)
Declare setCkDeflateLevel(obj.i, value.i)
```

Sets the compression level used by the `deflate` and `zlib` algorithms.

- `0` means no compression.
- `9` means maximum compression.
- The default value is `6`.

Higher values may produce smaller output but can require more processing time.

### Compression.EncodingMode

`Chilkat 11.7.0 · purebasic · Compression · EncodingMode · property · read/write`

```purebasic
Declare.s ckEncodingMode(obj.i)
Declare setCkEncodingMode(obj.i, value.s)
```

**Full documentation for this property (same in every language):** [Binary Encodings Supported by Chilkat](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/binary_encodings.md)

Specifies the text encoding used by methods whose names end in `ENC`, such as `CompressBytesENC` and `DecompressStringENC`.

Compression methods ending in `ENC` return compressed binary data as an encoded string. Decompression methods ending in `ENC` expect the input string to use this same encoding.

Valid values include:

- `base64`
- `hex`
- `url`
- `quoted-printable`

### Compression.FirstChunk

`Chilkat 11.7.0 · purebasic · Compression · FirstChunk · property · read/write · since 11.0.0`

```purebasic
Declare.i ckFirstChunk(obj.i)
Declare setCkFirstChunk(obj.i, value.i)
```

Indicates that the next chunk-aware compression or decompression call is the first chunk in a sequence.

The default value is `1`.

When both `FirstChunk` and `LastChunk` are `1`, the method call is treated as a complete, single-call compression or decompression operation.

### Compression.LastChunk

`Chilkat 11.7.0 · purebasic · Compression · LastChunk · property · read/write · since 11.0.0`

```purebasic
Declare.i ckLastChunk(obj.i)
Declare setCkLastChunk(obj.i, value.i)
```

Indicates that the next chunk-aware compression or decompression call is the final chunk in a sequence.

The default value is `1`.

When both `FirstChunk` and `LastChunk` are `1`, the input is treated as the complete data set and processed in a single call.

### Compression.UncommonOptions

`Chilkat 11.7.0 · purebasic · Compression · UncommonOptions · property · read/write · since 11.0.0`

```purebasic
Declare.s ckUncommonOptions(obj.i)
Declare setCkUncommonOptions(obj.i, value.s)
```

Provides a way to enable specialized or uncommon behavior. This property normally remains empty.

It may be set to a comma-separated list of keywords.

Supported option:

- `Crypt2CompressHdr` — Duplicates the compression/decompression header behavior used by the deprecated and removed Crypt2 compression functions.

## Methods

### Compression.CompressBd

`Chilkat 11.7.0 · purebasic · Compression · CompressBd · method · since 9.5.0.66`

```purebasic
Declare.i ckCompressBd(obj.i, bd.i)
```

Compresses the data contained in a `BinData` object.

The `BinData` object is modified to contain the compressed result.

This method is not `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.CompressBd2

`Chilkat 11.7.0 · purebasic · Compression · CompressBd2 · method · since 11.0.0`

```purebasic
Declare.i ckCompressBd2(obj.i, bdIn.i, bdOut.i)
```

Compresses the data in one `BinData` object and appends the compressed output to another `BinData` object.

The input `BinData` is not modified.

This method is `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.CompressEncryptFile

`Chilkat 11.7.0 · purebasic · Compression · CompressEncryptFile · method · since 9.5.0.99`

```purebasic
Declare.i ckCompressEncryptFile(obj.i, cryptParams.i, srcPath.s, destPath.s)
```

Compresses and encrypts a file, writing the result to a destination file.

The compression and encryption are performed internally in streaming mode, so files of any size can be processed without loading the entire file into memory.

Returns 1 for success, 0 for failure.

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

### Compression.CompressFile

`Chilkat 11.7.0 · purebasic · Compression · CompressFile · method`

```purebasic
Declare.i ckCompressFile(obj.i, srcPath.s, destPath.s)
```

Compresses a source file and writes the compressed data to a destination file.

The file is processed internally in streaming mode, allowing files of any size to be compressed with stable memory usage.

Returns 1 for success, 0 for failure.

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

### Compression.CompressSb

`Chilkat 11.7.0 · purebasic · Compression · CompressSb · method · since 9.5.0.73`

```purebasic
Declare.i ckCompressSb(obj.i, sb.i, binData.i)
```

Compresses the text contained in a `StringBuilder` and appends the compressed bytes to a `BinData` object.

Text is converted to bytes according to the `Charset` property.

This method is `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.CompressStr

`Chilkat 11.7.0 · purebasic · Compression · CompressStr · method · since 11.0.0`

```purebasic
Declare.i ckCompressStr(obj.i, str.s, bd.i)
```

Compresses a string and appends the compressed bytes to a `BinData` object.

The string is converted to bytes using the charset specified by the `Charset` property.

This method is `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.CompressStream

`Chilkat 11.7.0 · purebasic · Compression · CompressStream · method · since 9.5.0.56`

```purebasic
Declare.i ckCompressStream(obj.i, strm.i)
```

Compresses data from a stream source and writes the compressed data to the stream sink.

The operation is performed in streaming mode, making it suitable for very large or even continuous streams while maintaining stable memory usage.

Returns 1 for success, 0 for failure.

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

### Compression.CompressStringENC

`Chilkat 11.7.0 · purebasic · Compression · CompressStringENC · method`

```purebasic
Declare.s ckCompressStringENC(obj.i, str.s)
```

Compresses a string and returns the compressed result as an encoded string.

The string is first converted to bytes using `Charset`, then compressed, and finally encoded according to `EncodingMode`.

This method is not `FirstChunk` / `LastChunk` aware.

Returns an empty string on failure. Use the LastMethodSuccess property to check for success.

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

### Compression.DecompressBd

`Chilkat 11.7.0 · purebasic · Compression · DecompressBd · method · since 9.5.0.66`

```purebasic
Declare.i ckDecompressBd(obj.i, bd.i)
```

Decompresses the compressed data contained in a `BinData` object.

The `BinData` object is modified to contain the decompressed result.

This method is not `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.DecompressBd2

`Chilkat 11.7.0 · purebasic · Compression · DecompressBd2 · method · since 11.0.0`

```purebasic
Declare.i ckDecompressBd2(obj.i, bdIn.i, bdOut.i)
```

Decompresses the data in one `BinData` object and appends the decompressed output to another `BinData` object.

The input `BinData` is not modified.

This method is `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.DecompressFile

`Chilkat 11.7.0 · purebasic · Compression · DecompressFile · method`

```purebasic
Declare.i ckDecompressFile(obj.i, srcPath.s, destPath.s)
```

Decompresses a source file and writes the decompressed data to a destination file.

The file is processed internally in streaming mode, allowing files of any size to be decompressed without loading the entire file into memory.

Returns 1 for success, 0 for failure.

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

### Compression.DecompressSb

`Chilkat 11.7.0 · purebasic · Compression · DecompressSb · method · since 9.5.0.73`

```purebasic
Declare.i ckDecompressSb(obj.i, binData.i, sb.i)
```

Decompresses compressed data from a `BinData` object and appends the resulting text to a `StringBuilder`.

The decompressed bytes are converted to text using the `Charset` property.

This method is `FirstChunk` / `LastChunk` aware.

Returns 1 for success, 0 for failure.

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

### Compression.DecompressStream

`Chilkat 11.7.0 · purebasic · Compression · DecompressStream · method · since 9.5.0.56`

```purebasic
Declare.i ckDecompressStream(obj.i, strm.i)
```

Decompresses data from a stream source and writes the decompressed data to the stream sink.

The operation is performed in streaming mode, making it suitable for very large or continuous streams while maintaining stable memory usage.

Returns 1 for success, 0 for failure.

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

### Compression.DecompressStringENC

`Chilkat 11.7.0 · purebasic · Compression · DecompressStringENC · method`

```purebasic
Declare.s ckDecompressStringENC(obj.i, encodedCompressedData.s)
```

Decompresses compressed data supplied as an encoded string and returns the resulting text.

The input string is decoded according to `EncodingMode`, then decompressed. The resulting bytes are converted to text using `Charset`.

This method is not `FirstChunk` / `LastChunk` aware.

Returns an empty string on failure. Use the LastMethodSuccess property to check for success.

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

### Compression.DecryptDecompressFile

`Chilkat 11.7.0 · purebasic · Compression · DecryptDecompressFile · method · since 9.5.0.99`

```purebasic
Declare.i ckDecryptDecompressFile(obj.i, cryptParams.i, srcPath.s, destPath.s)
```

Decrypts and decompresses a file, writing the restored data to a destination file.

This is the reverse operation of `CompressEncryptFile`.

Returns 1 for success, 0 for failure.

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

### Compression.LoadTaskCaller

`Chilkat 11.7.0 · purebasic · Compression · LoadTaskCaller · method · since 9.5.0.80`

```purebasic
Declare.i ckLoadTaskCaller(obj.i, task.i)
```

Loads the caller of the task's async method.

Returns 1 for success, 0 for failure.

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

```purebasic
Declare.i ckCompressBdAsync(obj.i, bd.i)
Declare.i ckCompressBd2Async(obj.i, bdIn.i, bdOut.i)
Declare.i ckCompressEncryptFileAsync(obj.i, cryptParams.i, srcPath.s, destPath.s)
Declare.i ckCompressFileAsync(obj.i, srcPath.s, destPath.s)
Declare.i ckCompressSbAsync(obj.i, sb.i, binData.i)
Declare.i ckCompressStrAsync(obj.i, str.s, bd.i)
Declare.i ckCompressStreamAsync(obj.i, strm.i)
Declare.i ckCompressStringENCAsync(obj.i, str.s)
Declare.i ckDecompressBdAsync(obj.i, bd.i)
Declare.i ckDecompressBd2Async(obj.i, bdIn.i, bdOut.i)
Declare.i ckDecompressFileAsync(obj.i, srcPath.s, destPath.s)
Declare.i ckDecompressSbAsync(obj.i, binData.i, sb.i)
Declare.i ckDecompressStreamAsync(obj.i, strm.i)
Declare.i ckDecompressStringENCAsync(obj.i, encodedCompressedData.s)
Declare.i ckDecryptDecompressFileAsync(obj.i, cryptParams.i, srcPath.s, destPath.s)
```

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `BeginCompressStringENC` | method | before 11.6.1 | `FirstChunk` |
| `BeginDecompressStringENC` | method | before 11.6.1 | `FirstChunk` |
| `EndCompressBytesENC` | method | before 11.6.1 | — |
| `EndCompressStringENC` | method | before 11.6.1 | — |
| `EndDecompressString` | method | before 11.6.1 | — |
| `EndDecompressStringENC` | method | before 11.6.1 | — |
| `MoreCompressStringENC` | method | before 11.6.1 | — |
| `MoreDecompressStringENC` | method | before 11.6.1 | — |

## Related classes

[`BinData`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/purebasic/classes/BinData.md), [`JsonObject`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/purebasic/classes/JsonObject.md), [`Stream`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/purebasic/classes/Stream.md), [`StringBuilder`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/purebasic/classes/StringBuilder.md), [`Task`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/purebasic/classes/Task.md)

