Tar Lua Reference Documentation

chilkat.Tar

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

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

local chilkat = require("chilkat")

local tar = chilkat.Tar.new()
local tar = chilkat.Tar.new()

Creates the object (chilkat.Tar() does the same). Lua's garbage collector frees it when it is no longer referenced; tar:dispose() frees it at once, and in Lua 5.4 and later local tar <close> = chilkat.Tar.new() frees it when the block ends. Calling a method of a disposed object raises an error.

Errors

A method that fails returns nil followed by the error text, as io.open does: local body, err = tar:method(...), where err is the object's last_error_text. Wrap the call in assert() to raise an error with that text instead. Methods that answer a question return true or false, numbers are returned as they are (check last_method_success where the description says a value means failure), and property reads and writes never fail for Chilkat reasons.

Misuse raises a Lua error: a wrong argument type or a missing argument (bad argument #1 to ...), an unknown property name, a write to a read-only property, an out-of-range integer, or an object of the wrong class.

Names are Chilkat's in snake_case: QuickGetStr is quick_get_str, LastErrorText is last_error_text. Properties are fields (tar.verbose_logging = true) and methods use the colon (tar:method(...)). Strings are UTF-8; binary data is a Lua string of bytes. Indexes are 0-based, as in every Chilkat API. Unlocking: call chilkat.unlock_bundle("...") once at startup.

Properties

CaptureXmlListing
-- boolVal is a boolean
local boolVal = tar.capture_xml_listing
tar.capture_xml_listing = boolVal
Introduced in version 9.5.0.46

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.

top
Charset
-- strVal is a string
local strVal = tar.charset
tar.charset = strVal

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.

top
DebugLogFilePath
-- strVal is a string
local strVal = tar.debug_log_file_path
tar.debug_log_file_path = strVal

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
-- intVal is an integer
local intVal = tar.dir_mode
tar.dir_mode = intVal

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.

top
DirPrefix
-- strVal is a string
local strVal = tar.dir_prefix
tar.dir_prefix = strVal

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.

top
FileMode
-- intVal is an integer
local intVal = tar.file_mode
tar.file_mode = intVal

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.

top
GroupId
-- intVal is an integer
local intVal = tar.group_id
tar.group_id = intVal

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.

top
GroupName
-- strVal is a string
local strVal = tar.group_name
tar.group_name = strVal

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.

top
HeartbeatMs
-- intVal is an integer
local intVal = tar.heartbeat_ms
tar.heartbeat_ms = intVal

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.

More Information and Examples
top
LastErrorHtml
-- strVal is a string (read-only)
local strVal = tar.last_error_html

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
-- strVal is a string (read-only)
local strVal = tar.last_error_text

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
-- strVal is a string (read-only)
local strVal = tar.last_error_xml

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
-- boolVal is a boolean
local boolVal = tar.last_method_success
tar.last_method_success = boolVal

Indicates the success or failure of the most recent method call: true means success, false 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
-- boolVal is a boolean
local boolVal = tar.match_case_sensitive
tar.match_case_sensitive = boolVal
Introduced in version 9.5.0.46

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.

top
MustMatch
-- strVal is a string
local strVal = tar.must_match
tar.must_match = strVal
Introduced in version 9.5.0.46

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.

top
MustNotMatch
-- strVal is a string
local strVal = tar.must_not_match
tar.must_not_match = strVal
Introduced in version 9.5.0.46

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.

top
NoAbsolutePaths
-- boolVal is a boolean
local boolVal = tar.no_absolute_paths
tar.no_absolute_paths = boolVal

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.

top
NumDirRoots
-- intVal is an integer (read-only)
local intVal = tar.num_dir_roots

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.

top
PercentDoneScale
-- intVal is an integer
local intVal = tar.percent_done_scale
tar.percent_done_scale = intVal
Introduced in version 9.5.0.49

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.

top
ScriptFileMode
-- intVal is an integer
local intVal = tar.script_file_mode
tar.script_file_mode = intVal

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.

top
SuppressOutput
-- boolVal is a boolean
local boolVal = tar.suppress_output
tar.suppress_output = boolVal
Introduced in version 9.5.0.46

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.

top
UntarCaseSensitive
-- boolVal is a boolean
local boolVal = tar.untar_case_sensitive
tar.untar_case_sensitive = boolVal

Deprecated. Use MatchCaseSensitive instead.

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

top
UntarDebugLog
-- boolVal is a boolean
local boolVal = tar.untar_debug_log
tar.untar_debug_log = boolVal

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.

top
UntarDiscardPaths
-- boolVal is a boolean
local boolVal = tar.untar_discard_paths
tar.untar_discard_paths = boolVal

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.

top
UntarFromDir
-- strVal is a string
local strVal = tar.untar_from_dir
tar.untar_from_dir = strVal

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.

top
UntarMaxCount
-- intVal is an integer
local intVal = tar.untar_max_count
tar.untar_max_count = intVal

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.

top
UserId
-- intVal is an integer
local intVal = tar.user_id
tar.user_id = intVal

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.

top
UserName
-- strVal is a string
local strVal = tar.user_name
tar.user_name = strVal

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.

top
VerboseLogging
-- boolVal is a boolean
local boolVal = tar.verbose_logging
tar.verbose_logging = boolVal

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

top
Version
-- strVal is a string (read-only)
local strVal = tar.version

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

More Information and Examples
top
WriteFormat
-- strVal is a string
local strVal = tar.write_format
tar.write_format = strVal

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

ValueUse
gnuGNU TAR format and extensions. This is the Chilkat default and supports archive metadata beyond classic ustar limits.
paxPOSIX pax extended format. It is designed to represent long names and additional metadata through extensible records.
ustarPOSIX 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.

top
XmlListing
-- strVal is a string
local strVal = tar.xml_listing
tar.xml_listing = strVal
Introduced in version 9.5.0.46

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.

top

Methods

AddDirRoot
-- dir_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:add_dir_root(dir_path)

Adds the directory tree at dir_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
AddDirRoot2
-- root_prefix is a string
-- root_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:add_dir_root2(root_prefix, root_path)
Introduced in version 9.5.0.56

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

root_prefix 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
AddFile
-- path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:add_file(path)
Introduced in version 9.5.0.46

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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
AddFile2
-- file_path is a string
-- path_within_tar is a string
-- ok is true, or nil and err on failure
local ok, err = tar:add_file2(file_path, path_within_tar)
Introduced in version 9.5.0.69

Adds the local file at file_path to the archive-creation source list and stores it using the exact archive path supplied in path_within_tar. 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 path_within_tar 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
ClearDirRootsAndFiles
-- ok is true, or nil and err on failure
local ok, err = tar:clear_dir_roots_and_files()
Introduced in version 9.5.0.84

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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
CreateDeb
-- control_path is a string
-- data_path is a string
-- deb_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:create_deb(control_path, data_path, deb_path)
Introduced in version 9.5.0.66

Creates a Debian binary package at deb_path from the prepared control archive at control_path and data archive at data_path. 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
GetDirRoot
-- index is an integer
-- str is a string, or nil and err on failure
local str, err = tar:get_dir_root(index)

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 the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
ListXml
-- tar_path is a string
-- str is a string, or nil and err on failure
local str, err = tar:list_xml(tar_path)

Scans the uncompressed TAR archive at tar_path 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 the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
Untar
-- tar_path is a string
-- n is an integer
local n = tar:untar(tar_path)

Extracts the uncompressed TAR archive at tar_path 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.
More Information and Examples
top
UntarBz2
-- tar_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:untar_bz2(tar_path)

Decompresses and extracts the .tar.bz2 archive at tar_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

More Information and Examples
top
UntarFirstMatchingToBd
-- tar_path is a string
-- match_pattern is a string
-- bd is a chilkat.BinData
-- ok is true, or nil and err on failure
local ok, err = tar:untar_first_matching_to_bd(tar_path, match_pattern, bd)
Introduced in version 9.5.0.82

Scans the uncompressed TAR archive at tar_path and copies the contents of the first file whose archive path matches match_pattern 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
UntarGz
-- tar_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:untar_gz(tar_path)

Decompresses and extracts the .tar.gz archive at tar_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

More Information and Examples
top
UntarZ
-- tar_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:untar_z(tar_path)

Decompresses and extracts the .tar.Z archive at tar_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

More Information and Examples
top
VerifyTar
-- tar_path is a string
-- flag is true or false
local flag = tar:verify_tar(tar_path)

Opens the uncompressed TAR archive at tar_path 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.

Returns true or false: an answer, not a success flag.

top
WriteTar
-- tar_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:write_tar(tar_path)

Creates an uncompressed TAR archive at tar_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

More Information and Examples
top
WriteTarBz2
-- bz2_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:write_tar_bz2(bz2_path)

Creates a bzip2-compressed TAR archive at bz2_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
WriteTarGz
-- gz_path is a string
-- ok is true, or nil and err on failure
local ok, err = tar:write_tar_gz(gz_path)

Creates a gzip-compressed TAR archive at gz_path 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 on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

More Information and Examples
top

Events

All Chilkat methods are synchronous: the call returns when the work is done. During a long-running call, chilkat.Tar reports progress to the functions given to set_event_handler, in a table keyed by event name (plain functions, not methods: closures carry whatever state they need):

tar:set_event_handler({
    percent_done  = function(pct) print(pct .. "%") end,              -- return true to abort
    progress_info = function(name, value) print(name, value) end,
})
tar.heartbeat_ms = 250   -- abort_check is called 4 times per second
tar:set_event_handler({ event_name = function(...) ... end, ... })

Installs the handlers, replacing any installed before; tar:set_event_handler(nil) removes them. The event names are checked when the table is installed: a misspelled one raises an error.

The abort_check handler is called at the interval set by the heartbeat_ms property (0, the default, disables it); percent_done is called when an operation's completion percentage is known; progress_info delivers named progress values. A true return from abort_check or percent_done aborts the running method, which then fails in the usual way (nil, err). An error raised in a handler aborts the method and is raised again from the method call; the object remains usable.

AbortCheck
-- handler: function() ... return abort end -- a true return aborts the method in progress
tar:set_event_handler({ abort_check = function() ... end })

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.

More Information and Examples

Example

local deadline = os.time() + 30                  -- give up after 30 seconds
tar.heartbeat_ms = 250                      -- call the handler 4 times per second
tar:set_event_handler({ abort_check = function() return os.time() > deadline end })
top
PercentDone
-- handler: function(pct_done) ... return abort end -- a true return aborts
tar:set_event_handler({ percent_done = function(pct_done) ... end })

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.

More Information and Examples

Example

tar:set_event_handler({
    percent_done = function(pct_done)     -- 0 to 100
        print("Percent done: " .. pct_done)
        return false                       -- return true to abort the method in progress
    end,
})
top
ProgressInfo
-- handler: function(name, value) ... end
tar:set_event_handler({ progress_info = function(name, value) ... end })

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.

More Information and Examples

Example

tar:set_event_handler({
    progress_info = function(name, value) print(name .. ": " .. value) end,
})
top