---
product: Chilkat
product_version: 11.7.0
language: pascal
language_label: Lazarus Pascal
class: Tar
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/pascal_TarRef.html
---
# Chilkat Tar — Lazarus Pascal — v11.7.0

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

## Purpose

**Create, list, verify, filter, and extract TAR archives and compressed TAR formats.**

`Chilkat.Tar` creates, verifies, lists, and extracts TAR archives, including compressed TAR formats such as `.tar.gz`, `.tgz`, `.tar.bz2`, and `.tar.Z`. It supports adding individual files and directory trees, controlling archive paths, preserving or overriding file permissions, filtering included or extracted files, extracting from memory, extracting selected entries to memory or `BinData`, producing XML listings, and creating Debian `.deb` package archives from control and data tarballs.

**Create TAR archives**

Add files or directory trees and write standard TAR output, with control over archive paths, directory handling, and write format.

**Compressed TAR formats**

Work with common compressed archive forms such as `.tar.gz`, `.tgz`, `.tar.bz2`, and `.tar.Z`.

**List and verify contents**

Inspect archive entries, verify archive structure, and produce XML listings for display, logging, or programmatic processing.

**Selective extraction**

Extract entire archives or selected entries, including workflows that extract matching files directly to memory or `BinData`.

**Filters and paths**

Include or exclude files using filters, control relative paths in the archive, and manage how entries are restored during extraction.

**Permissions and packages**

Preserve or override UNIX-style permissions and create Debian `.deb` package archives from control and data tarballs.

**Common pattern:** Use `Tar` when the data is a TAR archive or a compressed TAR archive. Configure the archive paths, filters, permissions, and compression format, then create, list, verify, or extract the archive as needed. Use `Chilkat.Zip` for ZIP archives, `Chilkat.Gzip` for a single GZIP stream, and `Chilkat.Compression` for raw compression operations.

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

## Object creation, unlocking and error handling

**Create / Free**

```pascal
uses
  Chilkat.Tar;

var
  obj: TTar;
begin
  obj := TTar.Create;
  try
    if not obj.IsValid then
      raise Exception.Create('Failed to create a TTar instance.');

    // ... use obj ...

  finally
    obj.Free;
  end;
end;
```

`constructor Create;`

Allocates the underlying CkTar object and returns a new TTar instance. Simply adding **Chilkat.Tar** to the unit's `uses` clause is enough to locate and bind to the Chilkat shared library (DLL / .so / .dylib) at runtime — no separate load step is required. Check `obj.IsValid` after calling `Create`; it is `False` if the underlying library could not be found/loaded or the object could not be allocated (for example, when unlicensed).

`destructor Destroy; override;`

Every TTar created by calling `Create` should eventually be released by calling `.Free` (inherited from `TObject`). The destructor automatically disposes the underlying CkTar handle. A native (unmanaged) memory leak occurs if the object is never freed.

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 Lazarus Pascal.

## 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` | `property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;` | 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` | `property LastErrorHtml: string read GetLastErrorHtml;` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `property LastErrorText: string read GetLastErrorText;` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `property LastErrorXml: string read GetLastErrorXml;` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;` | read/write | Indicates the success or failure of the most recent method call: `True` means success, `False` means failure. |
| `VerboseLogging` | `property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;` | read/write | If set to `True`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `property Version: string read GetVersion;` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `CaptureXmlListing` | property, read/write | `property CaptureXmlListing: Boolean read GetCaptureXmlListing write SetCaptureXmlListing;` |
| `Charset` | property, read/write | `property Charset: string read GetCharset write SetCharset;` |
| `DirMode` | property, read/write | `property DirMode: Integer read GetDirMode write SetDirMode;` |
| `DirPrefix` | property, read/write | `property DirPrefix: string read GetDirPrefix write SetDirPrefix;` |
| `FileMode` | property, read/write | `property FileMode: Integer read GetFileMode write SetFileMode;` |
| `GroupId` | property, read/write | `property GroupId: Integer read GetGroupId write SetGroupId;` |
| `GroupName` | property, read/write | `property GroupName: string read GetGroupName write SetGroupName;` |
| `HeartbeatMs` | property, read/write | `property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;` |
| `MatchCaseSensitive` | property, read/write | `property MatchCaseSensitive: Boolean read GetMatchCaseSensitive write SetMatchCaseSensitive;` |
| `MustMatch` | property, read/write | `property MustMatch: string read GetMustMatch write SetMustMatch;` |
| `MustNotMatch` | property, read/write | `property MustNotMatch: string read GetMustNotMatch write SetMustNotMatch;` |
| `NoAbsolutePaths` | property, read/write | `property NoAbsolutePaths: Boolean read GetNoAbsolutePaths write SetNoAbsolutePaths;` |
| `NumDirRoots` | property, read-only | `property NumDirRoots: Integer read GetNumDirRoots;` |
| `PercentDoneScale` | property, read/write | `property PercentDoneScale: Integer read GetPercentDoneScale write SetPercentDoneScale;` |
| `ScriptFileMode` | property, read/write | `property ScriptFileMode: Integer read GetScriptFileMode write SetScriptFileMode;` |
| `SuppressOutput` | property, read/write | `property SuppressOutput: Boolean read GetSuppressOutput write SetSuppressOutput;` |
| `UntarCaseSensitive` | property, read/write | `property UntarCaseSensitive: Boolean read GetUntarCaseSensitive write SetUntarCaseSensitive;` |
| `UntarDebugLog` | property, read/write | `property UntarDebugLog: Boolean read GetUntarDebugLog write SetUntarDebugLog;` |
| `UntarDiscardPaths` | property, read/write | `property UntarDiscardPaths: Boolean read GetUntarDiscardPaths write SetUntarDiscardPaths;` |
| `UntarFromDir` | property, read/write | `property UntarFromDir: string read GetUntarFromDir write SetUntarFromDir;` |
| `UntarMaxCount` | property, read/write | `property UntarMaxCount: Integer read GetUntarMaxCount write SetUntarMaxCount;` |
| `UserId` | property, read/write | `property UserId: Integer read GetUserId write SetUserId;` |
| `UserName` | property, read/write | `property UserName: string read GetUserName write SetUserName;` |
| `WriteFormat` | property, read/write | `property WriteFormat: string read GetWriteFormat write SetWriteFormat;` |
| `XmlListing` | property, read/write | `property XmlListing: string read GetXmlListing write SetXmlListing;` |
| `AddDirRoot` | method | `function AddDirRoot(const dirPath: string): Boolean;` |
| `AddDirRoot2` | method | `function AddDirRoot2(const rootPrefix: string;     const rootPath: string): Boolean;` |
| `AddFile` | method | `function AddFile(const path: string): Boolean;` |
| `AddFile2` | method | `function AddFile2(const filePath: string;     const pathWithinTar: string): Boolean;` |
| `ClearDirRootsAndFiles` | method | `function ClearDirRootsAndFiles: Boolean;` |
| `CreateDeb` | method | `function CreateDeb(const controlPath: string;     const dataPath: string;     const debPath: string): Boolean;` |
| `GetDirRoot` | method | `function GetDirRoot(index: Integer): string;` |
| `ListXml` | method | `function ListXml(const tarPath: string): string;` |
| `LoadTaskCaller` | method | `// task is a TTask object. function LoadTaskCaller(task: TChilkatBase): Boolean;` |
| `Untar` | method | `function Untar(const tarPath: string): Integer;` |
| `UntarBz2` | method | `function UntarBz2(const tarPath: string): Boolean;` |
| `UntarFirstMatchingToBd` | method | `// bd is a TBinData object. function UntarFirstMatchingToBd(const tarPath: string;     const matchPattern: string;     bd: TChilkatBase): Boolean;` |
| `UntarGz` | method | `function UntarGz(const tarPath: string): Boolean;` |
| `UntarZ` | method | `function UntarZ(const tarPath: string): Boolean;` |
| `VerifyTar` | method | `function VerifyTar(const tarPath: string): Boolean;` |
| `WriteTar` | method | `function WriteTar(const tarPath: string): Boolean;` |
| `WriteTarBz2` | method | `function WriteTarBz2(const bz2Path: string): Boolean;` |
| `WriteTarGz` | method | `function WriteTarGz(const gzPath: string): Boolean;` |

## Properties

### Tar.CaptureXmlListing

`Chilkat 11.7.0 · pascal · Tar · CaptureXmlListing · property · read/write · since 9.5.0.46`

```pascal
property CaptureXmlListing: Boolean read GetCaptureXmlListing write SetCaptureXmlListing;
```

Controls whether extraction methods also capture an XML inventory of the archive. When set to `True`, methods such as `Untar`, `UntarGz`, `UntarBz2`, and `UntarZ` store the listing in `XmlListing`. The XML has the same structure as the string returned by `ListXml`. The default is `False`.

**Inspect without extracting:** Set `CaptureXmlListing` and `SuppressOutput` to `True` before an untar operation to scan the archive and obtain its XML listing without writing archive entries to disk.

### Tar.Charset

`Chilkat 11.7.0 · pascal · Tar · Charset · property · read/write`

```pascal
property Charset: string read GetCharset write SetCharset;
```

Specifies the character encoding used to decode filenames stored in a TAR archive during extraction. The default is `utf-8`, which is normally appropriate for modern archives.

This property affects archive entry names only. It does not convert or otherwise alter the contents of extracted files. TAR archives written by the `WriteTar*` methods store filenames as UTF-8.

**Filename interoperability:** The original TAR header format does not always identify the character encoding of a filename. Change this property only when an older archive is known to use a different encoding.

### Tar.DirMode

`Chilkat 11.7.0 · pascal · Tar · DirMode · property · read/write`

```pascal
property DirMode: Integer read GetDirMode write SetDirMode;
```

Specifies the UNIX permission bits written to the TAR header for directory entries created by the `WriteTar*` methods. The default is octal `0755`, which represents `rwxr-xr-x`.

**Archive metadata:** This value records permissions in the archive. Whether the exact permissions are restored during extraction depends on the destination operating system, filesystem, process privileges, and local security policy.

### Tar.DirPrefix

`Chilkat 11.7.0 · pascal · Tar · DirPrefix · property · read/write`

```pascal
property DirPrefix: string read GetDirPrefix write SetDirPrefix;
```

Specifies a path prefix to prepend to entries when a TAR archive is created. For example, setting this property to `subdir1` causes an entry such as `report.txt` to be stored as `subdir1/report.txt`.

The prefix changes only the path stored in the archive; it does not rename or move the source file on disk.

**AddFile2 exception:** `AddFile2` explicitly supplies the complete path within the archive, so `DirPrefix` is not applied to files added by that method.

### Tar.FileMode

`Chilkat 11.7.0 · pascal · Tar · FileMode · property · read/write`

```pascal
property FileMode: Integer read GetFileMode write SetFileMode;
```

Specifies the UNIX permission bits written to the TAR header for ordinary file entries created by the `WriteTar*` methods. The default is octal `0644`, which represents `rw-r--r--`.

**Shell scripts:** Files recognized as shell scripts use `ScriptFileMode` instead, allowing executable permissions to be recorded separately.

### Tar.GroupId

`Chilkat 11.7.0 · pascal · Tar · GroupId · property · read/write`

```pascal
property GroupId: Integer read GetGroupId write SetGroupId;
```

Specifies the numeric group identifier (GID) written to TAR headers when an archive is created. The default value is `1000`.

**Ownership metadata:** A stored GID is archive metadata. Restoring ownership may require elevated privileges and may be ignored or mapped differently on non-UNIX systems.

### Tar.GroupName

`Chilkat 11.7.0 · pascal · Tar · GroupName · property · read/write`

```pascal
property GroupName: string read GetGroupName write SetGroupName;
```

Specifies the group name written to TAR headers when an archive is created. By default, Chilkat uses the username of the account running the application.

**Name versus numeric ID:** TAR headers can contain both a group name and the numeric `GroupId`. Extraction tools and operating systems may give different precedence to these fields.

### Tar.HeartbeatMs

`Chilkat 11.7.0 · pascal · Tar · HeartbeatMs · property · read/write`

```pascal
property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;
```

**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)

Specifies the approximate interval, in milliseconds, between `AbortCheck` event callbacks during supported long-running operations. The default is `0`, which disables periodic `AbortCheck` callbacks.

**Cancellation is cooperative:** A callback can request that an operation stop, but the request is observed only when the running method reaches a cancellation check. Short operations may finish before a callback occurs.

### Tar.MatchCaseSensitive

`Chilkat 11.7.0 · pascal · Tar · MatchCaseSensitive · property · read/write · since 9.5.0.46`

```pascal
property MatchCaseSensitive: Boolean read GetMatchCaseSensitive write SetMatchCaseSensitive;
```

Controls whether the patterns in `MustMatch` and `MustNotMatch` are matched case-sensitively. The default is `False`.

**Cross-platform behavior:** Case sensitivity in the archive filter is independent of whether the local filesystem itself treats filenames as case-sensitive.

### Tar.MustMatch

`Chilkat 11.7.0 · pascal · Tar · MustMatch · property · read/write · since 9.5.0.46`

```pascal
property MustMatch: string read GetMustMatch write SetMustMatch;
```

Specifies an inclusion pattern applied when creating or extracting TAR archives, including compressed TAR formats. A candidate path is included or extracted only when it matches this pattern. The default is an empty string, which permits all paths.

The pattern may contain zero or more asterisks (`*`), where each asterisk matches zero or more characters. For example, `*.txt` selects paths ending in `.txt`. Case handling is controlled by `MatchCaseSensitive`.

**Combined filters:** If both `MustMatch` and `MustNotMatch` are set, a path must satisfy the inclusion pattern and must not satisfy the exclusion pattern.

### Tar.MustNotMatch

`Chilkat 11.7.0 · pascal · Tar · MustNotMatch · property · read/write · since 9.5.0.46`

```pascal
property MustNotMatch: string read GetMustNotMatch write SetMustNotMatch;
```

Specifies an exclusion pattern applied when creating or extracting TAR archives, including compressed TAR formats. A candidate path that matches this pattern is skipped. The default is an empty string, which excludes nothing.

The pattern may contain zero or more asterisks (`*`), where each asterisk matches zero or more characters. For example, `*.obj` skips paths ending in `.obj`. Case handling is controlled by `MatchCaseSensitive`.

**Exclusion takes effect after inclusion:** When both filters are set, matching `MustMatch` does not override a match in `MustNotMatch`.

### Tar.NoAbsolutePaths

`Chilkat 11.7.0 · pascal · Tar · NoAbsolutePaths · property · read/write`

```pascal
property NoAbsolutePaths: Boolean read GetNoAbsolutePaths write SetNoAbsolutePaths;
```

Controls whether absolute archive paths are converted to relative paths during extraction. When `True`, a leading `/` or `\` is removed before the entry is written. The default is `True`.

**Recommended security setting:** Keep this property enabled when extracting archives you did not create. Also extract untrusted archives into a dedicated directory and inspect their entry names before relying on the extracted content.

### Tar.NumDirRoots

`Chilkat 11.7.0 · pascal · Tar · NumDirRoots · property · read-only`

```pascal
property NumDirRoots: Integer read GetNumDirRoots;
```

Returns the number of directory roots currently registered for archive creation by calls to `AddDirRoot` and `AddDirRoot2`. Individual files added with `AddFile` or `AddFile2` are not included in this count.

Use zero-based indexes from `0` through `NumDirRoots - 1` with `GetDirRoot`.

### Tar.PercentDoneScale

`Chilkat 11.7.0 · pascal · Tar · PercentDoneScale · property · read/write · since 9.5.0.49`

```pascal
property PercentDoneScale: Integer read GetPercentDoneScale write SetPercentDoneScale;
```

Specifies the value reported by `PercentDone` when an eligible operation is 100% complete. The default is `100`. Increasing the scale allows finer-grained integer progress values; for example, a scale of `1000` allows `453` to represent 45.3%.

The value is clamped to the range `10` through `100000`. This property is available only in environments that support event callbacks, and only methods for which measurable progress is available emit percentage updates.

**Scale, not frequency:** A larger scale increases the numeric resolution of progress values but does not guarantee a callback for every possible value.

### Tar.ScriptFileMode

`Chilkat 11.7.0 · pascal · Tar · ScriptFileMode · property · read/write`

```pascal
property ScriptFileMode: Integer read GetScriptFileMode write SetScriptFileMode;
```

Specifies the UNIX permission bits written to TAR headers for shell-script files recognized by extensions such as `.sh`, `.csh`, `.bash`, and `.bsh`. The default is octal `0755`, which records executable permissions.

**Other files:** Non-script files use `FileMode`; directories use `DirMode`.

### Tar.SuppressOutput

`Chilkat 11.7.0 · pascal · Tar · SuppressOutput · property · read/write · since 9.5.0.46`

```pascal
property SuppressOutput: Boolean read GetSuppressOutput write SetSuppressOutput;
```

Controls whether untar operations write extracted files and directories to the filesystem. When `True`, methods such as `Untar`, `UntarGz`, `UntarBz2`, and `UntarZ` scan the archive without producing extracted output. The default is `False`.

**Archive inventory workflow:** Combine this property with `CaptureXmlListing` to obtain an XML listing without extracting the archive.

### Tar.UntarCaseSensitive

`Chilkat 11.7.0 · pascal · Tar · UntarCaseSensitive · property · read/write`

```pascal
property UntarCaseSensitive: Boolean read GetUntarCaseSensitive write SetUntarCaseSensitive;
```

**Deprecated.** Use `MatchCaseSensitive` instead.

Until this property is removed, reading or setting it has the same effect as reading or setting `MatchCaseSensitive`.

### Tar.UntarDebugLog

`Chilkat 11.7.0 · pascal · Tar · UntarDebugLog · property · read/write`

```pascal
property UntarDebugLog: Boolean read GetUntarDebugLog write SetUntarDebugLog;
```

Controls whether untar methods add per-entry extraction details to `LastErrorText`, `LastErrorXml`, and `LastErrorHtml`. The default is `False`.

**Diagnostic output is not necessarily an error:** When this property is enabled, the LastError properties can contain useful extraction trace information even after a successful operation.

### Tar.UntarDiscardPaths

`Chilkat 11.7.0 · pascal · Tar · UntarDiscardPaths · property · read/write`

```pascal
property UntarDiscardPaths: Boolean read GetUntarDiscardPaths write SetUntarDiscardPaths;
```

Controls whether directory components from archive entry names are discarded during extraction. When `True`, each file is written directly into `UntarFromDir` rather than recreating the archived directory tree. The default is `False`.

**Filename collisions:** Different archive entries can have the same final filename after their directory paths are removed. Use this option only when flattening the archive is intentional and potential collisions are acceptable.

### Tar.UntarFromDir

`Chilkat 11.7.0 · pascal · Tar · UntarFromDir · property · read/write`

```pascal
property UntarFromDir: string read GetUntarFromDir write SetUntarFromDir;
```

Specifies the destination directory for extraction. The default is `.`, meaning the current working directory of the calling process.

When `UntarDiscardPaths` is `False`, archived subdirectories are recreated beneath this directory. When it is `True`, extracted files are placed directly in this directory.

**Safer extraction:** For untrusted archives, choose a new or otherwise isolated destination directory rather than extracting directly into an application or system directory.

### Tar.UntarMaxCount

`Chilkat 11.7.0 · pascal · Tar · UntarMaxCount · property · read/write`

```pascal
property UntarMaxCount: Integer read GetUntarMaxCount write SetUntarMaxCount;
```

Limits the number of matching entries extracted by an untar operation. The default is `0`, which means no maximum.

For example, set `MustMatch` to select a particular path and set `UntarMaxCount` to `1` to stop after the first matching entry is extracted.

**Archive order matters:** When a limit is used, extraction stops after the configured number of matches in archive order.

### Tar.UserId

`Chilkat 11.7.0 · pascal · Tar · UserId · property · read/write`

```pascal
property UserId: Integer read GetUserId write SetUserId;
```

Specifies the numeric user identifier (UID) written to TAR headers when an archive is created. The default value is `1000`.

**Ownership metadata:** A stored UID does not by itself change the owner of a local source file. Restoring ownership during extraction may require elevated privileges and may not apply on non-UNIX systems.

### Tar.UserName

`Chilkat 11.7.0 · pascal · Tar · UserName · property · read/write`

```pascal
property UserName: string read GetUserName write SetUserName;
```

Specifies the user name written to TAR headers when an archive is created. By default, Chilkat uses the username of the account running the application.

**Name versus numeric ID:** TAR headers can contain both a user name and the numeric `UserId`. Their interpretation depends on the extracting tool and destination system.

### Tar.WriteFormat

`Chilkat 11.7.0 · pascal · Tar · WriteFormat · property · read/write`

```pascal
property WriteFormat: string read GetWriteFormat write SetWriteFormat;
```

Specifies the TAR header format used by the `WriteTar*` methods. The default is `gnu`. Supported values are:

| Value | Use |
| :--- | :--- |
| `gnu` | GNU TAR format and extensions. This is the Chilkat default and supports archive metadata beyond classic ustar limits. |
| `pax` | POSIX pax extended format. It is designed to represent long names and additional metadata through extensible records. |
| `ustar` | POSIX ustar format. It is broadly interoperable but has stricter limits on path lengths and metadata fields. |

**Choosing a format:** Use `ustar` when compatibility with simple TAR readers is the priority and the archive fits its limits. Use `pax` for portable extended metadata, or retain `gnu` when GNU TAR compatibility is expected.

### Tar.XmlListing

`Chilkat 11.7.0 · pascal · Tar · XmlListing · property · read/write · since 9.5.0.46`

```pascal
property XmlListing: string read GetXmlListing write SetXmlListing;
```

Contains the XML listing captured by the most recent untar operation for which `CaptureXmlListing` was `True`. The XML structure is the same as the output from `ListXml`.

**Read after the operation:** Use the untar method's return value to confirm that the archive was processed successfully before consuming this property.

## Methods

### Tar.AddDirRoot

`Chilkat 11.7.0 · pascal · Tar · AddDirRoot · method`

```pascal
function  AddDirRoot(const dirPath: string): Boolean;
```

Adds the directory tree at `dirPath` to the set of sources used by the next `WriteTar*` operation. Call this method multiple times to include multiple directory trees in one archive.

Use `AddDirRoot2` when the tree should appear beneath an explicit prefix inside the archive.

**Queued archive sources:** Directory roots and files are retained by the object until `ClearDirRootsAndFiles` is called.

Returns True for success, False for failure.

### Tar.AddDirRoot2

`Chilkat 11.7.0 · pascal · Tar · AddDirRoot2 · method · since 9.5.0.56`

```pascal
function  AddDirRoot2(const rootPrefix: string;
    const rootPath: string): Boolean;
```

Adds the directory tree at `rootPath` to the archive-creation source list and stores its entries beneath the archive prefix supplied in `rootPrefix`. Call this method multiple times, or combine it with `AddDirRoot`, before calling a `WriteTar*` method.

`rootPrefix` should be a relative archive path such as `abc/123` and should not end with `/`. If `DirPrefix` is also set, `DirPrefix` is applied first.

**Path composition example:** With `DirPrefix = "package"` and `rootPrefix = "assets"`, files from this root are stored beneath `package/assets/`.

Returns True for success, False for failure.

### Tar.AddFile

`Chilkat 11.7.0 · pascal · Tar · AddFile · method · since 9.5.0.46`

```pascal
function  AddFile(const path: string): Boolean;
```

Adds the local file at `path` to the set of sources used by the next `WriteTar*` operation. Call `AddFile`, `AddFile2`, and the directory-root methods as needed before writing a single archive.

Use `AddFile2` when the path stored inside the TAR must be specified independently of the source file path.

**Queued archive sources:** Added files and directory roots remain associated with the object until `ClearDirRootsAndFiles` is called.

Returns True for success, False for failure.

### Tar.AddFile2

`Chilkat 11.7.0 · pascal · Tar · AddFile2 · method · since 9.5.0.69`

```pascal
function  AddFile2(const filePath: string;
    const pathWithinTar: string): Boolean;
```

Adds the local file at `filePath` to the archive-creation source list and stores it using the exact archive path supplied in `pathWithinTar`. This allows the source path and the path visible inside the TAR to differ.

Call this method as many times as needed, optionally together with the other file and directory-root methods, before calling a single `WriteTar*` method.

**DirPrefix is not applied:** Because `pathWithinTar` already specifies the path within the TAR, `DirPrefix` does not modify entries added by this method. Use forward slashes and a relative path for portable archive names.

Returns True for success, False for failure.

### Tar.ClearDirRootsAndFiles

`Chilkat 11.7.0 · pascal · Tar · ClearDirRootsAndFiles · method · since 9.5.0.84`

```pascal
function  ClearDirRootsAndFiles: Boolean;
```

Removes all files and directory roots previously registered by `AddDirRoot`, `AddDirRoot2`, `AddFile`, and `AddFile2`.

Call this method before building a different archive with the same `Tar` object when the earlier source list should not be reused.

Returns True for success, False for failure.

### Tar.CreateDeb

`Chilkat 11.7.0 · pascal · Tar · CreateDeb · method · since 9.5.0.66`

```pascal
function  CreateDeb(const controlPath: string;
    const dataPath: string;
    const debPath: string): Boolean;
```

Creates a Debian binary package at `debPath` from the prepared control archive at `controlPath` and data archive at `dataPath`. The inputs are typically named `control.tar.gz` and `data.tar.gz`, or use another compression form accepted by the target Debian tooling.

**Debian package structure:** A modern `.deb` file is an `ar` archive containing a `debian-binary` format marker, a `control.tar.*` member for package metadata and maintainer scripts, and a `data.tar.*` member for the installed filesystem payload.

**Prepared inputs required:** This method packages the supplied control and data tarballs. The caller is responsible for making their directory layout, control metadata, permissions, and package contents valid for Debian package-management tools.

Returns True for success, False for failure.

### Tar.GetDirRoot

`Chilkat 11.7.0 · pascal · Tar · GetDirRoot · method`

```pascal
function  GetDirRoot(index: Integer): string;
```

Returns a directory root previously added with `AddDirRoot` or `AddDirRoot2`. `index` is a zero-based index.

Valid indexes range from `0` through `NumDirRoots - 1`. For example, after two roots are added, `GetDirRoot(0)` returns the first and `GetDirRoot(1)` returns the second.

Returns True for success, False for failure.

### Tar.ListXml

`Chilkat 11.7.0 · pascal · Tar · ListXml · method`

```pascal
function  ListXml(const tarPath: string): string;
```

Scans the uncompressed TAR archive at `tarPath` and returns an XML description of its files, directories, and archive metadata. The archive is not extracted.

**Compressed tarballs:** For a compressed TAR archive, an untar method can capture the same listing format by setting `CaptureXmlListing`. Set `SuppressOutput` as well when no files should be written.

Returns True for success, False for failure.

### Tar.LoadTaskCaller

`Chilkat 11.7.0 · pascal · Tar · LoadTaskCaller · method · since 9.5.0.80`

```pascal
// task is a TTask object.

function  LoadTaskCaller(task: TChilkatBase): Boolean;
```

Loads the caller object associated with `task`, an asynchronous Chilkat `Task`, into this `Tar` object.

**Specialized async support:** This method supports Chilkat task-caller plumbing and is not normally needed in ordinary archive code. Use it only when a Chilkat example or support instruction specifically requires it.

Returns True for success, False for failure.

### Tar.Untar

`Chilkat 11.7.0 · pascal · Tar · Untar · method`

```pascal
function  Untar(const tarPath: string): Integer;
```

Extracts the uncompressed TAR archive at `tarPath` into the directory specified by `UntarFromDir`. Archived directory trees are recreated unless `UntarDiscardPaths` is `True`.

Returns the number of files and directories extracted, or `-1` if the operation fails. Extraction is also affected by the matching, path-safety, count-limit, listing, and output-suppression properties of this object.

**TAR is a container format:** An ordinary `.tar` archive is not compressed. Use `UntarGz`, `UntarBz2`, or `UntarZ` for the corresponding compressed tarball formats.

### Tar.UntarBz2

`Chilkat 11.7.0 · pascal · Tar · UntarBz2 · method`

```pascal
function  UntarBz2(const tarPath: string): Boolean;
```

Decompresses and extracts the `.tar.bz2` archive at `tarPath` into `UntarFromDir`. This format is also commonly named `.tbz`, `.tbz2`, or `.tb2`.

Returns `True` on success and `False` on failure. The same extraction filters, path controls, listing options, and output settings used by `Untar` also apply.

Returns True for success, False for failure.

### Tar.UntarFirstMatchingToBd

`Chilkat 11.7.0 · pascal · Tar · UntarFirstMatchingToBd · method · since 9.5.0.82`

```pascal
// bd is a TBinData object.

function  UntarFirstMatchingToBd(const tarPath: string;
    const matchPattern: string;
    bd: TChilkatBase): Boolean;
```

Scans the uncompressed TAR archive at `tarPath` and copies the contents of the first file whose archive path matches `matchPattern` into the `BinData` object supplied in `bd`. Matching is evaluated in archive order.

No archive entry is written to the local filesystem. Returns `True` when a matching file is successfully extracted to `bd` and `False` otherwise.

Returns True for success, False for failure.

### Tar.UntarGz

`Chilkat 11.7.0 · pascal · Tar · UntarGz · method`

```pascal
function  UntarGz(const tarPath: string): Boolean;
```

Decompresses and extracts the `.tar.gz` archive at `tarPath` into `UntarFromDir`. The `.tgz` extension is a common short form for the same gzip-compressed TAR structure.

Returns `True` on success and `False` on failure. The same extraction filters, path controls, listing options, and output settings used by `Untar` also apply.

Returns True for success, False for failure.

### Tar.UntarZ

`Chilkat 11.7.0 · pascal · Tar · UntarZ · method`

```pascal
function  UntarZ(const tarPath: string): Boolean;
```

Decompresses and extracts the `.tar.Z` archive at `tarPath` into `UntarFromDir`. The `.Z` suffix denotes the historical UNIX `compress` format; `.taz` is a common alternate extension.

Returns `True` on success and `False` on failure. The same extraction filters, path controls, listing options, and output settings used by `Untar` also apply.

Returns True for success, False for failure.

### Tar.VerifyTar

`Chilkat 11.7.0 · pascal · Tar · VerifyTar · method`

```pascal
function  VerifyTar(const tarPath: string): Boolean;
```

Opens the uncompressed TAR archive at `tarPath` and scans its headers through the end of the archive. Returns `True` when the archive structure is accepted and no TAR-format errors are found; otherwise returns `False`.

**What verification does not establish:** Structural verification does not prove that archived files are safe, trustworthy, or appropriate to extract. It is not malware scanning and does not authenticate the archive publisher.

### Tar.WriteTar

`Chilkat 11.7.0 · pascal · Tar · WriteTar · method`

```pascal
function  WriteTar(const tarPath: string): Boolean;
```

Creates an uncompressed TAR archive at `tarPath` from the files and directory trees previously added with `AddFile`, `AddFile2`, `AddDirRoot`, and `AddDirRoot2`. Archive paths, permissions, ownership metadata, filters, and header format are controlled by the corresponding properties.

Returns `True` on success and `False` on failure.

Returns True for success, False for failure.

### Tar.WriteTarBz2

`Chilkat 11.7.0 · pascal · Tar · WriteTarBz2 · method`

```pascal
function  WriteTarBz2(const bz2Path: string): Boolean;
```

Creates a bzip2-compressed TAR archive at `bz2Path` from the files and directory trees previously added to this object. Common filename extensions include `.tar.bz2`, `.tbz`, `.tbz2`, and `.tb2`.

Returns `True` on success and `False` on failure.

**Two-layer format:** The result is a TAR byte stream compressed with bzip2. TAR supplies the multi-file archive structure; bzip2 supplies compression.

Returns True for success, False for failure.

### Tar.WriteTarGz

`Chilkat 11.7.0 · pascal · Tar · WriteTarGz · method`

```pascal
function  WriteTarGz(const gzPath: string): Boolean;
```

Creates a gzip-compressed TAR archive at `gzPath` from the files and directory trees previously added to this object. The usual extensions are `.tar.gz` and `.tgz`.

Returns `True` on success and `False` on failure.

**Two-layer format:** The result is a TAR byte stream compressed with gzip. TAR supplies the multi-file archive structure; gzip supplies compression.

Returns True for success, False for failure.

## Events and callbacks

Chilkat for Pascal supports three synchronous event callbacks: `OnAbortCheck`, `OnPercentDone`, and `OnProgressInfo`. Each is a property of the class; assign a method of one of your own objects (an *of object* handler) to receive the callbacks, or assign `nil` to unhook. The handler types are declared in the `Chilkat.Base` unit:

```pascal
TChilkatAbortCheckEvent   = function(Sender: TChilkatBase): Boolean of object;
TChilkatPercentDoneEvent  = function(Sender: TChilkatBase; PctDone: Integer): Boolean of object;
TChilkatProgressInfoEvent = procedure(Sender: TChilkatBase; const Name, Value: string) of object;
```

All Chilkat methods are synchronous, so callbacks are invoked on the thread that called the method -- if the method was called from the main thread, it is safe to access UI elements from the handler. The `HeartbeatMs` property controls the frequency of `OnAbortCheck` callbacks (the default of 0 means no AbortCheck events fire). Returning `True` from an `OnAbortCheck` or `OnPercentDone` handler aborts the running method.

### Tar.AbortCheck (event)

`Chilkat 11.7.0 · pascal · Tar · AbortCheck · event`

```pascal
// TChilkatAbortCheckEvent = function(Sender: TChilkatBase): Boolean of object;

property OnAbortCheck: TChilkatAbortCheckEvent;
```

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.

**Event callback implementation:**

```pascal
// A handler is a method of one of your own classes, e.g. a form:
function TMyObject.TarAbortCheck(Sender: TChilkatBase): Boolean;
begin
  // Called every HeartbeatMs milliseconds while a method is running.
  // Return True to abort the method; return False to continue.
  Result := False;
end;
```

**To add an event handler:**

```pascal
tar := TTar.Create;
tar.HeartbeatMs := 250;   // fire OnAbortCheck 4 times per second
tar.OnAbortCheck := MyObject.TarAbortCheck;
```

### Tar.PercentDone (event)

`Chilkat 11.7.0 · pascal · Tar · PercentDone · event`

```pascal
// TChilkatPercentDoneEvent = function(Sender: TChilkatBase; PctDone: Integer): Boolean of object;

property OnPercentDone: TChilkatPercentDoneEvent;
```

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.

**Event callback implementation:**

```pascal
// A handler is a method of one of your own classes, e.g. a form:
function TMyObject.TarPercentDone(Sender: TChilkatBase; PctDone: Integer): Boolean;
begin
  // PctDone ranges from 1 to 100.
  WriteLn('Percent done: ', PctDone);
  // Return True to abort the method; return False to continue.
  Result := False;
end;
```

**To add an event handler:**

```pascal
tar := TTar.Create;
tar.OnPercentDone := MyObject.TarPercentDone;
```

### Tar.ProgressInfo (event)

`Chilkat 11.7.0 · pascal · Tar · ProgressInfo · event`

```pascal
// TChilkatProgressInfoEvent = procedure(Sender: TChilkatBase; const Name, Value: string) of object;

property OnProgressInfo: TChilkatProgressInfoEvent;
```

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.

**Event callback implementation:**

```pascal
// A handler is a method of one of your own classes, e.g. a form:
procedure TMyObject.TarProgressInfo(Sender: TChilkatBase; const Name, Value: string);
begin
  WriteLn(Name, ': ', Value);
end;
```

**To add an event handler:**

```pascal
tar := TTar.Create;
tar.OnProgressInfo := MyObject.TarProgressInfo;
```

## Related classes

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

