Tar PureBasic Reference Documentation

Tar

Current Version: 11.5.0

Chilkat.Tar

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.

Object Creation

obj.i = CkTar::ckCreate()

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

Properties

CaptureXmlListing
Declare.i ckCaptureXmlListing(obj.i)
Declare setCkCaptureXmlListing(obj.i, value.i)
Introduced in version 9.5.0.46

If 1, then untar methods, such as Untar, UntarGz, UntarBz2, and UntarZ, will also capture an XML listing of the contents in the XmlListing property. The format of the XML contained in XmlListing is identical to what is returned by the ListXml method. The default value is 0.

top
Charset
Declare.s ckCharset(obj.i)
Declare setCkCharset(obj.i, value.s)

Character encoding to be used when interpreting filenames within .tar archives for untar operations. The default is utf-8, and this is typically not changed. (The WriteTar methods always uses utf-8 to store filenames within the TAR archive.)

top
DebugLogFilePath
Declare.s ckDebugLogFilePath(obj.i)
Declare setCkDebugLogFilePath(obj.i, value.s)

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
DirMode
Declare.i ckDirMode(obj.i)
Declare setCkDirMode(obj.i, value.i)

The directory permissions to used in WriteTar* methods. The default is octal 0755. This is the value to be stored in the mode field of each TAR header for a directory entries.

top
DirPrefix
Declare.s ckDirPrefix(obj.i)
Declare setCkDirPrefix(obj.i, value.s)

A prefix to be added to each file's path within the TAR archive as it is being created. For example, if this property is set to the string subdir1, then subdir1/ will be prepended to each file's path within the TAR.

Note: This property does not apply to files added using the AddFile2 method, which directly specifies the path-in-tar.

top
FileMode
Declare.i ckFileMode(obj.i)
Declare setCkFileMode(obj.i, value.i)

The file permissions to used in WriteTar* methods. The default is octal 0644. This is the value to be stored in the mode field of each TAR header for a file entries.

top
GroupId
Declare.i ckGroupId(obj.i)
Declare setCkGroupId(obj.i, value.i)

The default numerical GID to be stored in each TAR header when writing TAR archives. The default value is 1000.

top
GroupName
Declare.s ckGroupName(obj.i)
Declare setCkGroupName(obj.i, value.s)

The default group name to be stored in each TAR header when writing TAR archives. The default value is the logged-on username of the application's process.

top
LastErrorHtml
Declare.s ckLastErrorHtml(obj.i) ; (read-only)

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
Declare.s ckLastErrorText(obj.i) ; (read-only)

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
Declare.s ckLastErrorXml(obj.i) ; (read-only)

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
Declare.i ckLastMethodSuccess(obj.i)
Declare setCkLastMethodSuccess(obj.i, value.i)

Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
MatchCaseSensitive
Declare.i ckMatchCaseSensitive(obj.i)
Declare setCkMatchCaseSensitive(obj.i, value.i)
Introduced in version 9.5.0.46

Determines whether pattern matching for the MustMatch and MustNotMatch properties is case-sensitive or not. The default value is 0.

top
MustMatch
Declare.s ckMustMatch(obj.i)
Declare setCkMustMatch(obj.i, value.s)
Introduced in version 9.5.0.46

If set, then file paths must match this pattern when creating TAR archives, or when extracting from TAR archives. If a file does not match, it will not be included when creating a TAR, or it will not be extracted when extracting from a TAR. This property also applies to methods that create or extract from compressed TAR archives.

The must-match pattern may include 0 or more asterisk characters, each of which represents 0 or more of any character. For example, the pattern *.txt causes only .txt files to be included or extracted. The default value is an empty string, indicating that all files are implicitly matched.

top
MustNotMatch
Declare.s ckMustNotMatch(obj.i)
Declare setCkMustNotMatch(obj.i, value.s)
Introduced in version 9.5.0.46

If set, then file paths must NOT match this pattern when creating TAR archives, or when extracting from TAR archives. If a file path matches, it will not be included when creating a TAR, or it will not be extracted when extracting from a TAR. This property also applies to methods that create or extract from compressed TAR archives.

The must-not-match pattern may include 0 or more asterisk characters, each of which represents 0 or more of any character. For example, the pattern *.obj causes all .obj files to be skipped. The default value is an empty string, indicating that no files are skipped.

top
NoAbsolutePaths
Declare.i ckNoAbsolutePaths(obj.i)
Declare setCkNoAbsolutePaths(obj.i, value.i)

If 1, then absolute paths are converted to relative paths by removing the leading / or \ character when untarring. This protects your system from unknowingly untarring files into important system directories, such as C:\Windows\system32. The default value is 1.

top
NumDirRoots
Declare.i ckNumDirRoots(obj.i) ; (read-only)

The total number of directory roots set by calling AddDirRoot (i.e. the number of times AddDirRoot was called by the application). A TAR archive is created by calling AddDirRoot for one or more directory tree roots, followed by a single call to WriteTar (or WriteTarBz2, WriteTarGz, WriteTarZ). This allows for TAR archives containing multiple directory trees to be created.

top
ScriptFileMode
Declare.i ckScriptFileMode(obj.i)
Declare setCkScriptFileMode(obj.i, value.i)

The file permissions to used in WriteTar* methods for shell script files (.sh, .csh, .bash, .bsh). The default is octal 0755. This is the value to be stored in the mode field of each TAR header for a file entries.

top
SuppressOutput
Declare.i ckSuppressOutput(obj.i)
Declare setCkSuppressOutput(obj.i, value.i)
Introduced in version 9.5.0.46

If 1, then untar methods, such as Untar, UntarGz, UntarBz2, and UntarZ, do not produce any output. Setting this value equal to 1 is useful when the CaptureXmlListing is also set to 1, which enables an application to get the contents of a TAR archive without extracting. The default value is 0.

top
UntarCaseSensitive
Declare.i ckUntarCaseSensitive(obj.i)
Declare setCkUntarCaseSensitive(obj.i, value.i)

This property is deprecated. Applications should instead use the MatchCaseSensitive property. Until this property is officially removed, it will behave the same as the MatchCaseSensitive property.

top
UntarDebugLog
Declare.i ckUntarDebugLog(obj.i)
Declare setCkUntarDebugLog(obj.i, value.i)

Similar to the VerboseLogging property. If set to 1, then information about each file/directory extracted in an untar method call is logged to LastErrorText (or LastErrorXml / LastErrorHtml). The default value is 0.

top
UntarDiscardPaths
Declare.i ckUntarDiscardPaths(obj.i)
Declare setCkUntarDiscardPaths(obj.i, value.i)

If 1, then discard all path information when untarring. This causes all files to be untarred into a single directory. The default value is 0.

top
UntarFromDir
Declare.s ckUntarFromDir(obj.i)
Declare setCkUntarFromDir(obj.i, value.s)

The directory path where files are extracted when untarring. The default value is ., meaning that the current working directory of the calling process is used. If UntarDiscardPaths is set, then all files are untarred into this directory. Otherwise, the untar operation will re-create a directory tree rooted in this directory.

top
UntarMaxCount
Declare.i ckUntarMaxCount(obj.i)
Declare setCkUntarMaxCount(obj.i, value.i)

Limits the number of files extracted during an untar to this count. The default value is 0 to indicate no maximum. To untar a single file, one might set the UntarMatchPattern such that it will match only the file to be extracted, and also set UntarMaxCount equal to 1. This causes an untar to scan the TAR archive until it finds the matching file, extract it, and then return.

top
UserId
Declare.i ckUserId(obj.i)
Declare setCkUserId(obj.i, value.i)

The default numerical UID to be stored in each TAR header when writing TAR archives. The default value is 1000.

top
UserName
Declare.s ckUserName(obj.i)
Declare setCkUserName(obj.i, value.s)

The default user name to be stored in each TAR header when writing TAR archives. The default value is the logged-on username of the application's process.

top
VerboseLogging
Declare.i ckVerboseLogging(obj.i)
Declare setCkVerboseLogging(obj.i, value.i)

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
Declare.s ckVersion(obj.i) ; (read-only)

Version of the component/library, such as "10.1.0"

More Information and Examples
top
WriteFormat
Declare.s ckWriteFormat(obj.i)
Declare setCkWriteFormat(obj.i, value.s)

The TAR format to use when writing a TAR archive. Valid values are gnu, pax, and ustar. The default value is gnu.

top
XmlListing
Declare.s ckXmlListing(obj.i)
Declare setCkXmlListing(obj.i, value.s)
Introduced in version 9.5.0.46

Contains the XML listing of the contents of the TAR archive for the last untar method call (such as Untar, UntarGz, etc.) where the CaptureXmlListing property was set to 1.

top

Methods

AddDirRoot
Declare.i ckAddDirRoot(obj.i, dirPath.s)

Adds a directory tree to be included in the next call to one of the WriteTar* methods. To include multiple directory trees in a .tar, call AddDirRoot multiple times followed by a single call to WriteTar.

Returns 1 for success, 0 for failure.

top
AddDirRoot2
Declare.i ckAddDirRoot2(obj.i, rootPrefix.s, rootPath.s)
Introduced in version 9.5.0.56

Adds a directory tree to be included in the next call to one of the WriteTar* methods. To include multiple directory trees in a .tar, call AddDirRoot2 (and/or AddDirRoot) multiple times followed by a single call to WriteTar.

The rootPrefix adds a prefix to the path in the TAR for all files added under this root. The rootPrefix should not end with a forward-slash char. For example: This is good: abc/123, but this is not good: abc/123/. If the DirPrefix property is also set, its prefix will added first.

Returns 1 for success, 0 for failure.

top
AddFile
Declare.i ckAddFile(obj.i, path.s)
Introduced in version 9.5.0.46

Adds a local file to be included in the next call to one of the WriteTar* methods. To include multiple files or directory trees in a .tar, call AddFile/AddDirRoot multiple times followed by a single call to WriteTar (or WriteTarGz, or WriteTarBz2).

Returns 1 for success, 0 for failure.

top
AddFile2
Declare.i ckAddFile2(obj.i, filePath.s, pathWithinTar.s)
Introduced in version 9.5.0.69

Adds a local file to be included in the next call to one of the WriteTar* methods. Allows for the path within the TAR to be specified. To include multiple files or directory trees in a .tar, call AddFile/AddFile2/AddDirRoot multiple times followed by a single call to WriteTar (or WriteTarGz, or WriteTarBz2).

Note: The DirPrefix property does not apply to files added via this method because this method explicilty specifies the path-in-tar.

Returns 1 for success, 0 for failure.

top
ClearDirRootsAndFiles
Declare.i ckClearDirRootsAndFiles(obj.i)
Introduced in version 9.5.0.84

Clears all directory roots and files previously added by calls to AddDirRoot, AddDirRoot2, AddFile, and AddFile2.

Returns 1 for success, 0 for failure.

top
CreateDeb
Declare.i ckCreateDeb(obj.i, controlPath.s, dataPath.s, debPath.s)
Introduced in version 9.5.0.66

Creates a .deb Debian binary package archive from a control.tar.gz and data.tar.gz. The controlPath is the path to the control.tar.gz file (or equivalent), and the dataPath is the path to the data.tar.gz file. The output file path (.deb) is specified in debPath.

Returns 1 for success, 0 for failure.

top
GetDirRoot
Declare.s ckGetDirRoot(obj.i, index.l)

Returns the value of the Nth directory root. For example, if an application calls AddDirRoot twice, then the NumDirRoots property would have a value of 2, and GetDirRoot(0) would return the path passed to AddDirRoot in the 1st call, and GetDirRoot(1) would return the directory path in the 2nd call to AddDirRoot.

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

top
ListXml
Declare.s ckListXml(obj.i, tarPath.s)

Scans a TAR archive and returns XML detailing the files and directories found within the TAR.

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

top
ListXmlAsync (1)
Declare.i ckListXmlAsync(obj.i, tarPath.s)

Creates an asynchronous task to call the ListXml method with the arguments provided.

Returns 0 on failure

top
LoadTaskCaller
Declare.i ckLoadTaskCaller(obj.i, task.i)
Introduced in version 9.5.0.80

Loads the caller of the task's async method.

Returns 1 for success, 0 for failure.

top
Untar
Declare.i ckUntar(obj.i, tarPath.s)

Extracts the files and directories from a TAR archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property. Returns the number of files and directories extracted, or -1 for failure.

More Information and Examples
top
UntarAsync (1)
Declare.i ckUntarAsync(obj.i, tarPath.s)

Creates an asynchronous task to call the Untar method with the arguments provided.

Returns 0 on failure

top
UntarBz2
Declare.i ckUntarBz2(obj.i, tarPath.s)

Extracts the files and directories from a tar.bz2 (or tar.bzip2) archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property.

Returns 1 for success, 0 for failure.

More Information and Examples
top
UntarBz2Async (1)
Declare.i ckUntarBz2Async(obj.i, tarPath.s)

Creates an asynchronous task to call the UntarBz2 method with the arguments provided.

Returns 0 on failure

top
UntarFirstMatchingToBd
Declare.i ckUntarFirstMatchingToBd(obj.i, tarPath.s, matchPattern.s, bd.i)
Introduced in version 9.5.0.82

Untars the first file matching the matchPattern into bd.

Returns 1 for success, 0 for failure.

top
UntarGz
Declare.i ckUntarGz(obj.i, tarPath.s)

Extracts the files and directories from a tar.gz (or tar.gzip) archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property.

Returns 1 for success, 0 for failure.

More Information and Examples
top
UntarGzAsync (1)
Declare.i ckUntarGzAsync(obj.i, tarPath.s)

Creates an asynchronous task to call the UntarGz method with the arguments provided.

Returns 0 on failure

top
UntarZ
Declare.i ckUntarZ(obj.i, tarPath.s)

Extracts the files and directories from a tar.Z archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property.

Returns 1 for success, 0 for failure.

More Information and Examples
top
UntarZAsync (1)
Declare.i ckUntarZAsync(obj.i, tarPath.s)

Creates an asynchronous task to call the UntarZ method with the arguments provided.

Returns 0 on failure

top
VerifyTar
Declare.i ckVerifyTar(obj.i, tarPath.s)

Verifies that a TAR archive is valid. This method opens the TAR archive and scans the entire file by walking the TAR headers. Returns 1 if no errors were found. Otherwise returns 0.

top
VerifyTarAsync (1)
Declare.i ckVerifyTarAsync(obj.i, tarPath.s)

Creates an asynchronous task to call the VerifyTar method with the arguments provided.

Returns 0 on failure

top
WriteTar
Declare.i ckWriteTar(obj.i, tarPath.s)

Writes a TAR archive. The directory trees previously added by calling AddDirRoot one or more times are included in the output TAR archive.

Returns 1 for success, 0 for failure.

More Information and Examples
top
WriteTarAsync (1)
Declare.i ckWriteTarAsync(obj.i, tarPath.s)

Creates an asynchronous task to call the WriteTar method with the arguments provided.

Returns 0 on failure

top
WriteTarBz2
Declare.i ckWriteTarBz2(obj.i, bz2Path.s)

Writes a .tar.bz2 compressed TAR archive. The directory trees previously added by calling AddDirRoot one or more times are included in the output file.

Returns 1 for success, 0 for failure.

top
WriteTarBz2Async (1)
Declare.i ckWriteTarBz2Async(obj.i, bz2Path.s)

Creates an asynchronous task to call the WriteTarBz2 method with the arguments provided.

Returns 0 on failure

top
WriteTarGz
Declare.i ckWriteTarGz(obj.i, gzPath.s)

Writes a .tar.gz (also known as .tgz) compressed TAR archive. The directory trees previously added by calling AddDirRoot one or more times are included in the output file.

Returns 1 for success, 0 for failure.

More Information and Examples
top
WriteTarGzAsync (1)
Declare.i ckWriteTarGzAsync(obj.i, gzPath.s)

Creates an asynchronous task to call the WriteTarGz method with the arguments provided.

Returns 0 on failure

top