Class Tar
- All Implemented Interfaces:
AutoCloseable
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.
</section>
Event-capable: long-running methods report progress through a ProgressListener installed
with setProgressListener(ProgressListener), onAbortCheck(BooleanSupplier),
onPercentDone(IntPredicate) or onProgressInfo(BiConsumer).
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDirRoot(String dirPath)Adds the directory tree atdirPathto the set of sources used by the nextWriteTar*operation.voidaddDirRoot2(String rootPrefix, String rootPath)Adds the directory tree atrootPathto the archive-creation source list and stores its entries beneath the archive prefix supplied inrootPrefix.voidAdds the local file atpathto the set of sources used by the nextWriteTar*operation.voidAdds the local file atfilePathto the archive-creation source list and stores it using the exact archive path supplied inpathWithinTar.voidRemoves all files and directory roots previously registered by,addDirRoot(String),addDirRoot2(String, String), andaddFile(String).addFile2(String, String)voidCreates a Debian binary package atdebPathfrom the prepared control archive atcontrolPathand data archive atdataPath.booleanControls whether extraction methods also capture an XML inventory of the archive.Specifies the character encoding used to decode filenames stored in a TAR archive during extraction.intSpecifies the UNIX permission bits written to the TAR header for directory entries created by theWriteTar*methods.Specifies a path prefix to prepend to entries when a TAR archive is created.getDirRoot(int index)Returns a directory root previously added withoraddDirRoot(String).addDirRoot2(String, String)intSpecifies the UNIX permission bits written to the TAR header for ordinary file entries created by theWriteTar*methods.intSpecifies the numeric group identifier (GID) written to TAR headers when an archive is created.Specifies the group name written to TAR headers when an archive is created.intSpecifies the approximate interval, in milliseconds, betweenevent callbacks during supported long-running operations.AbortCheckbooleanControls whether the patterns inandgetMustMatch()are matched case-sensitively.getMustNotMatch()Specifies an inclusion pattern applied when creating or extracting TAR archives, including compressed TAR formats.Specifies an exclusion pattern applied when creating or extracting TAR archives, including compressed TAR formats.booleanControls whether absolute archive paths are converted to relative paths during extraction.intReturns the number of directory roots currently registered for archive creation by calls toandaddDirRoot(String).addDirRoot2(String, String)intSpecifies the value reported byPercentDonewhen an eligible operation is 100% complete.Returns the installed listener, ornull.intSpecifies the UNIX permission bits written to TAR headers for shell-script files recognized by extensions such as.sh,.csh,.bash, and.bsh.booleanControls whether untar operations write extracted files and directories to the filesystem.booleanDeprecated. Useinstead.getMatchCaseSensitive()booleanControls whether untar methods add per-entry extraction details toLastErrorText,LastErrorXml, andLastErrorHtml.booleanControls whether directory components from archive entry names are discarded during extraction.Specifies the destination directory for extraction.intLimits the number of matching entries extracted by an untar operation.intSpecifies the numeric user identifier (UID) written to TAR headers when an archive is created.Specifies the user name written to TAR headers when an archive is created.Specifies the TAR header format used by theWriteTar*methods.Contains the XML listing captured by the most recent untar operation for whichwasgetCaptureXmlListing()true.Scans the uncompressed TAR archive attarPathand returns an XML description of its files, directories, and archive metadata.voidonAbortCheck(BooleanSupplier callback)Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it.voidonPercentDone(IntPredicate callback)Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it.voidonProgressInfo(BiConsumer<String,String> callback)Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds.voidsetCaptureXmlListing(boolean value)Sets theCaptureXmlListingproperty; seegetCaptureXmlListing().voidsetCharset(String value)Sets theCharsetproperty; seegetCharset().voidsetDirMode(int value)Sets theDirModeproperty; seegetDirMode().voidsetDirPrefix(String value)Sets theDirPrefixproperty; seegetDirPrefix().voidsetFileMode(int value)Sets theFileModeproperty; seegetFileMode().voidsetGroupId(int value)Sets theGroupIdproperty; seegetGroupId().voidsetGroupName(String value)Sets theGroupNameproperty; seegetGroupName().voidsetHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().voidsetMatchCaseSensitive(boolean value)Sets theMatchCaseSensitiveproperty; seegetMatchCaseSensitive().voidsetMustMatch(String value)Sets theMustMatchproperty; seegetMustMatch().voidsetMustNotMatch(String value)Sets theMustNotMatchproperty; seegetMustNotMatch().voidsetNoAbsolutePaths(boolean value)Sets theNoAbsolutePathsproperty; seegetNoAbsolutePaths().voidsetPercentDoneScale(int value)Sets thePercentDoneScaleproperty; seegetPercentDoneScale().voidsetProgressListener(ProgressListener listener)Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.voidsetScriptFileMode(int value)Sets theScriptFileModeproperty; seegetScriptFileMode().voidsetSuppressOutput(boolean value)Sets theSuppressOutputproperty; seegetSuppressOutput().voidsetUntarCaseSensitive(boolean value)Sets theUntarCaseSensitiveproperty; seegetUntarCaseSensitive().voidsetUntarDebugLog(boolean value)Sets theUntarDebugLogproperty; seegetUntarDebugLog().voidsetUntarDiscardPaths(boolean value)Sets theUntarDiscardPathsproperty; seegetUntarDiscardPaths().voidsetUntarFromDir(String value)Sets theUntarFromDirproperty; seegetUntarFromDir().voidsetUntarMaxCount(int value)Sets theUntarMaxCountproperty; seegetUntarMaxCount().voidsetUserId(int value)Sets theUserIdproperty; seegetUserId().voidsetUserName(String value)Sets theUserNameproperty; seegetUserName().voidsetWriteFormat(String value)Sets theWriteFormatproperty; seegetWriteFormat().voidsetXmlListing(String value)Sets theXmlListingproperty; seegetXmlListing().intExtracts the uncompressed TAR archive attarPathinto the directory specified by.getUntarFromDir()voidvoiduntarFirstMatchingToBd(String tarPath, String matchPattern, BinData bd)Scans the uncompressed TAR archive attarPathand copies the contents of the first file whose archive path matchesmatchPatterninto theBinDataobject supplied inbd.voidvoidbooleanOpens the uncompressed TAR archive attarPathand scans its headers through the end of the archive.voidCreates an uncompressed TAR archive attarPathfrom the files and directory trees previously added withAddFile,AddFile2,AddDirRoot, andAddDirRoot2.voidwriteTarBz2(String bz2Path)Creates a bzip2-compressed TAR archive atbz2Pathfrom the files and directory trees previously added to this object.voidwriteTarGz(String gzPath)Creates a gzip-compressed TAR archive atgzPathfrom the files and directory trees previously added to this object.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Tar
public Tar()Creates a newTarobject.
-
-
Method Details
-
getCaptureXmlListing
public boolean getCaptureXmlListing()Controls whether extraction methods also capture an XML inventory of the archive. When set totrue, methods such asUntar,UntarGz,UntarBz2, andUntarZstore the listing in. The XML has the same structure as the string returned bygetXmlListing(). The default islistXml(String)false.Inspect without extracting: Set
CaptureXmlListingandtogetSuppressOutput()truebefore an untar operation to scan the archive and obtain its XML listing without writing archive entries to disk.- Returns:
- the value of the
CaptureXmlListingproperty
-
setCaptureXmlListing
public void setCaptureXmlListing(boolean value)Sets theCaptureXmlListingproperty; seegetCaptureXmlListing().- Parameters:
value- the new value
-
getCharset
Specifies the character encoding used to decode filenames stored in a TAR archive during extraction. The default isutf-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.
- Returns:
- the value of the
Charsetproperty
-
setCharset
Sets theCharsetproperty; seegetCharset().- Parameters:
value- the new value (notnull)
-
getDirMode
public int getDirMode()Specifies the UNIX permission bits written to the TAR header for directory entries created by theWriteTar*methods. The default is octal0755, which representsrwxr-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.
- Returns:
- the value of the
DirModeproperty
-
setDirMode
public void setDirMode(int value)Sets theDirModeproperty; seegetDirMode().- Parameters:
value- the new value
-
getDirPrefix
Specifies a path prefix to prepend to entries when a TAR archive is created. For example, setting this property tosubdir1causes an entry such asreport.txtto be stored assubdir1/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:
explicitly supplies the complete path within the archive, soaddFile2(String, String)DirPrefixis not applied to files added by that method.- Returns:
- the value of the
DirPrefixproperty
-
setDirPrefix
Sets theDirPrefixproperty; seegetDirPrefix().- Parameters:
value- the new value (notnull)
-
getFileMode
public int getFileMode()Specifies the UNIX permission bits written to the TAR header for ordinary file entries created by theWriteTar*methods. The default is octal0644, which representsrw-r--r--.Shell scripts: Files recognized as shell scripts use
instead, allowing executable permissions to be recorded separately.getScriptFileMode()- Returns:
- the value of the
FileModeproperty
-
setFileMode
public void setFileMode(int value)Sets theFileModeproperty; seegetFileMode().- Parameters:
value- the new value
-
getGroupId
public int getGroupId()Specifies the numeric group identifier (GID) written to TAR headers when an archive is created. The default value is1000.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.
- Returns:
- the value of the
GroupIdproperty
-
setGroupId
public void setGroupId(int value)Sets theGroupIdproperty; seegetGroupId().- Parameters:
value- the new value
-
getGroupName
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
. Extraction tools and operating systems may give different precedence to these fields.getGroupId()- Returns:
- the value of the
GroupNameproperty
-
setGroupName
Sets theGroupNameproperty; seegetGroupName().- Parameters:
value- the new value (notnull)
-
getHeartbeatMs
public int getHeartbeatMs()Specifies the approximate interval, in milliseconds, betweenevent callbacks during supported long-running operations. The default isAbortCheck0, which disables periodicAbortCheckcallbacks.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.
- Returns:
- the value of the
HeartbeatMsproperty
-
setHeartbeatMs
public void setHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().- Parameters:
value- the new value
-
getMatchCaseSensitive
public boolean getMatchCaseSensitive()Controls whether the patterns inandgetMustMatch()are matched case-sensitively. The default isgetMustNotMatch()false.Cross-platform behavior: Case sensitivity in the archive filter is independent of whether the local filesystem itself treats filenames as case-sensitive.
- Returns:
- the value of the
MatchCaseSensitiveproperty
-
setMatchCaseSensitive
public void setMatchCaseSensitive(boolean value)Sets theMatchCaseSensitiveproperty; seegetMatchCaseSensitive().- Parameters:
value- the new value
-
getMustMatch
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,*.txtselects paths ending in.txt. Case handling is controlled by.getMatchCaseSensitive()Combined filters: If both
MustMatchandare set, a path must satisfy the inclusion pattern and must not satisfy the exclusion pattern.getMustNotMatch()- Returns:
- the value of the
MustMatchproperty
-
setMustMatch
Sets theMustMatchproperty; seegetMustMatch().- Parameters:
value- the new value (notnull)
-
getMustNotMatch
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,*.objskips paths ending in.obj. Case handling is controlled by.getMatchCaseSensitive()Exclusion takes effect after inclusion: When both filters are set, matching
does not override a match ingetMustMatch()MustNotMatch.- Returns:
- the value of the
MustNotMatchproperty
-
setMustNotMatch
Sets theMustNotMatchproperty; seegetMustNotMatch().- Parameters:
value- the new value (notnull)
-
getNoAbsolutePaths
public boolean getNoAbsolutePaths()Controls whether absolute archive paths are converted to relative paths during extraction. Whentrue, a leading/or\is removed before the entry is written. The default istrue.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.
- Returns:
- the value of the
NoAbsolutePathsproperty
-
setNoAbsolutePaths
public void setNoAbsolutePaths(boolean value)Sets theNoAbsolutePathsproperty; seegetNoAbsolutePaths().- Parameters:
value- the new value
-
getNumDirRoots
public int getNumDirRoots()Returns the number of directory roots currently registered for archive creation by calls toandaddDirRoot(String). Individual files added withaddDirRoot2(String, String)AddFileorAddFile2are not included in this count.Use zero-based indexes from
0throughNumDirRoots - 1with.getDirRoot(int)- Returns:
- the value of the
NumDirRootsproperty (read-only)
-
getPercentDoneScale
public int getPercentDoneScale()Specifies the value reported byPercentDonewhen an eligible operation is 100% complete. The default is100. Increasing the scale allows finer-grained integer progress values; for example, a scale of1000allows453to represent 45.3%.The value is clamped to the range
10through100000. 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.
- Returns:
- the value of the
PercentDoneScaleproperty
-
setPercentDoneScale
public void setPercentDoneScale(int value)Sets thePercentDoneScaleproperty; seegetPercentDoneScale().- Parameters:
value- the new value
-
getScriptFileMode
public int getScriptFileMode()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 octal0755, which records executable permissions.Other files: Non-script files use
; directories usegetFileMode().getDirMode()- Returns:
- the value of the
ScriptFileModeproperty
-
setScriptFileMode
public void setScriptFileMode(int value)Sets theScriptFileModeproperty; seegetScriptFileMode().- Parameters:
value- the new value
-
getSuppressOutput
public boolean getSuppressOutput()Controls whether untar operations write extracted files and directories to the filesystem. Whentrue, methods such asUntar,UntarGz,UntarBz2, andUntarZscan the archive without producing extracted output. The default isfalse.Archive inventory workflow: Combine this property with
to obtain an XML listing without extracting the archive.getCaptureXmlListing()- Returns:
- the value of the
SuppressOutputproperty
-
setSuppressOutput
public void setSuppressOutput(boolean value)Sets theSuppressOutputproperty; seegetSuppressOutput().- Parameters:
value- the new value
-
getUntarCaseSensitive
public boolean getUntarCaseSensitive()Deprecated. Useinstead.getMatchCaseSensitive()Until this property is removed, reading or setting it has the same effect as reading or setting
MatchCaseSensitive.- Returns:
- the value of the
UntarCaseSensitiveproperty
-
setUntarCaseSensitive
public void setUntarCaseSensitive(boolean value)Sets theUntarCaseSensitiveproperty; seegetUntarCaseSensitive().- Parameters:
value- the new value
-
getUntarDebugLog
public boolean getUntarDebugLog()Controls whether untar methods add per-entry extraction details toLastErrorText,LastErrorXml, andLastErrorHtml. The default isfalse.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.
- Returns:
- the value of the
UntarDebugLogproperty
-
setUntarDebugLog
public void setUntarDebugLog(boolean value)Sets theUntarDebugLogproperty; seegetUntarDebugLog().- Parameters:
value- the new value
-
getUntarDiscardPaths
public boolean getUntarDiscardPaths()Controls whether directory components from archive entry names are discarded during extraction. Whentrue, each file is written directly intorather than recreating the archived directory tree. The default isgetUntarFromDir()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.
- Returns:
- the value of the
UntarDiscardPathsproperty
-
setUntarDiscardPaths
public void setUntarDiscardPaths(boolean value)Sets theUntarDiscardPathsproperty; seegetUntarDiscardPaths().- Parameters:
value- the new value
-
getUntarFromDir
Specifies the destination directory for extraction. The default is., meaning the current working directory of the calling process.When
isgetUntarDiscardPaths()false, archived subdirectories are recreated beneath this directory. When it istrue, 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.
- Returns:
- the value of the
UntarFromDirproperty
-
setUntarFromDir
Sets theUntarFromDirproperty; seegetUntarFromDir().- Parameters:
value- the new value (notnull)
-
getUntarMaxCount
public int getUntarMaxCount()Limits the number of matching entries extracted by an untar operation. The default is0, which means no maximum.For example, set
to select a particular path and setgetMustMatch()UntarMaxCountto1to 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.
- Returns:
- the value of the
UntarMaxCountproperty
-
setUntarMaxCount
public void setUntarMaxCount(int value)Sets theUntarMaxCountproperty; seegetUntarMaxCount().- Parameters:
value- the new value
-
getUserId
public int getUserId()Specifies the numeric user identifier (UID) written to TAR headers when an archive is created. The default value is1000.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.
- Returns:
- the value of the
UserIdproperty
-
setUserId
public void setUserId(int value)Sets theUserIdproperty; seegetUserId().- Parameters:
value- the new value
-
getUserName
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
. Their interpretation depends on the extracting tool and destination system.getUserId()- Returns:
- the value of the
UserNameproperty
-
setUserName
Sets theUserNameproperty; seegetUserName().- Parameters:
value- the new value (notnull)
-
getWriteFormat
Specifies the TAR header format used by theWriteTar*methods. The default isgnu. Supported values are:Value Use
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
ustarwhen compatibility with simple TAR readers is the priority and the archive fits its limits. Usepaxfor portable extended metadata, or retaingnuwhen GNU TAR compatibility is expected.- Returns:
- the value of the
WriteFormatproperty
-
setWriteFormat
Sets theWriteFormatproperty; seegetWriteFormat().- Parameters:
value- the new value (notnull)
-
getXmlListing
Contains the XML listing captured by the most recent untar operation for whichwasgetCaptureXmlListing()true. The XML structure is the same as the output from.listXml(String)Read after the operation: Use the untar method's return value to confirm that the archive was processed successfully before consuming this property.
- Returns:
- the value of the
XmlListingproperty
-
setXmlListing
Sets theXmlListingproperty; seegetXmlListing().- Parameters:
value- the new value (notnull)
-
addDirRoot
Adds the directory tree atdirPathto the set of sources used by the nextWriteTar*operation. Call this method multiple times to include multiple directory trees in one archive.Use
when the tree should appear beneath an explicit prefix inside the archive.addDirRoot2(String, String)Queued archive sources: Directory roots and files are retained by the object until
is called.clearDirRootsAndFiles()- Parameters:
dirPath- thedirPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addDirRoot2
Adds the directory tree atrootPathto the archive-creation source list and stores its entries beneath the archive prefix supplied inrootPrefix. Call this method multiple times, or combine it with, before calling aaddDirRoot(String)WriteTar*method.rootPrefixshould be a relative archive path such asabc/123and should not end with/. Ifis also set,getDirPrefix()DirPrefixis applied first.Path composition example: With
DirPrefix = "package"androotPrefix = "assets", files from this root are stored beneathpackage/assets/.- Parameters:
rootPrefix- therootPrefixargument (notnull)rootPath- therootPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addFile
Adds the local file atpathto the set of sources used by the nextWriteTar*operation. CallAddFile,AddFile2, and the directory-root methods as needed before writing a single archive.Use
when the path stored inside the TAR must be specified independently of the source file path.addFile2(String, String)Queued archive sources: Added files and directory roots remain associated with the object until
is called.clearDirRootsAndFiles()- Parameters:
path- thepathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addFile2
Adds the local file atfilePathto the archive-creation source list and stores it using the exact archive path supplied inpathWithinTar. 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
pathWithinTaralready specifies the path within the TAR,does not modify entries added by this method. Use forward slashes and a relative path for portable archive names.getDirPrefix()- Parameters:
filePath- thefilePathargument (notnull)pathWithinTar- thepathWithinTarargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
clearDirRootsAndFiles
public void clearDirRootsAndFiles()Removes all files and directory roots previously registered by,addDirRoot(String),addDirRoot2(String, String), andaddFile(String).addFile2(String, String)Call this method before building a different archive with the same
Tarobject when the earlier source list should not be reused.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
createDeb
Creates a Debian binary package atdebPathfrom the prepared control archive atcontrolPathand data archive atdataPath. The inputs are typically namedcontrol.tar.gzanddata.tar.gz, or use another compression form accepted by the target Debian tooling.Debian package structure: A modern
.debfile is anararchive containing adebian-binaryformat marker, acontrol.tar.*member for package metadata and maintainer scripts, and adata.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.- Parameters:
controlPath- thecontrolPathargument (notnull)dataPath- thedataPathargument (notnull)debPath- thedebPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getDirRoot
Returns a directory root previously added withoraddDirRoot(String).addDirRoot2(String, String)indexis a zero-based index.Valid indexes range from
0through. For example, after two roots are added,getNumDirRoots()- 1GetDirRoot(0)returns the first andGetDirRoot(1)returns the second.- Parameters:
index- theindexargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
listXml
Scans the uncompressed TAR archive attarPathand 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
. SetgetCaptureXmlListing()as well when no files should be written.getSuppressOutput()- Parameters:
tarPath- thetarPathargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
untar
Extracts the uncompressed TAR archive attarPathinto the directory specified by. Archived directory trees are recreated unlessgetUntarFromDir()isgetUntarDiscardPaths()true.Returns the number of files and directories extracted, or
-1if 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
.tararchive is not compressed. UseUntarGz,UntarBz2, orUntarZfor the corresponding compressed tarball formats.- Parameters:
tarPath- thetarPathargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
untarBz2
Decompresses and extracts the.tar.bz2archive attarPathinto. This format is also commonly namedgetUntarFromDir().tbz,.tbz2, or.tb2.Returns
trueon success andfalseon failure. The same extraction filters, path controls, listing options, and output settings used byalso apply.untar(String)- Parameters:
tarPath- thetarPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
untarFirstMatchingToBd
Scans the uncompressed TAR archive attarPathand copies the contents of the first file whose archive path matchesmatchPatterninto theBinDataobject supplied inbd. Matching is evaluated in archive order.No archive entry is written to the local filesystem. Returns
truewhen a matching file is successfully extracted tobdandfalseotherwise.- Parameters:
tarPath- thetarPathargument (notnull)matchPattern- thematchPatternargument (notnull)bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
untarGz
Decompresses and extracts the.tar.gzarchive attarPathinto. ThegetUntarFromDir().tgzextension is a common short form for the same gzip-compressed TAR structure.Returns
trueon success andfalseon failure. The same extraction filters, path controls, listing options, and output settings used byalso apply.untar(String)- Parameters:
tarPath- thetarPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
untarZ
Decompresses and extracts the.tar.Zarchive attarPathinto. ThegetUntarFromDir().Zsuffix denotes the historical UNIXcompressformat;.tazis a common alternate extension.Returns
trueon success andfalseon failure. The same extraction filters, path controls, listing options, and output settings used byalso apply.untar(String)- Parameters:
tarPath- thetarPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
verifyTar
Opens the uncompressed TAR archive attarPathand scans its headers through the end of the archive. Returnstruewhen the archive structure is accepted and no TAR-format errors are found; otherwise returnsfalse.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.
- Parameters:
tarPath- thetarPathargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
writeTar
Creates an uncompressed TAR archive attarPathfrom the files and directory trees previously added withAddFile,AddFile2,AddDirRoot, andAddDirRoot2. Archive paths, permissions, ownership metadata, filters, and header format are controlled by the corresponding properties.Returns
trueon success andfalseon failure.- Parameters:
tarPath- thetarPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
writeTarBz2
Creates a bzip2-compressed TAR archive atbz2Pathfrom the files and directory trees previously added to this object. Common filename extensions include.tar.bz2,.tbz,.tbz2, and.tb2.Returns
trueon success andfalseon failure.Two-layer format: The result is a TAR byte stream compressed with bzip2. TAR supplies the multi-file archive structure; bzip2 supplies compression.
- Parameters:
bz2Path- thebz2Pathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
writeTarGz
Creates a gzip-compressed TAR archive atgzPathfrom the files and directory trees previously added to this object. The usual extensions are.tar.gzand.tgz.Returns
trueon success andfalseon failure.Two-layer format: The result is a TAR byte stream compressed with gzip. TAR supplies the multi-file archive structure; gzip supplies compression.
- Parameters:
gzPath- thegzPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setProgressListener
Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.- Parameters:
listener- the listener, ornull- Throws:
IllegalStateException- if called from inside one of this object's own callbacks
-
getProgressListener
Returns the installed listener, ornull.- Returns:
- the listener installed with
setProgressListener(ProgressListener)or one of theon...methods
-
onAbortCheck
Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onPercentDone
Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onProgressInfo
Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-