GUnzip/BUnzip2/UnXZ

Description

Expands a resource packed using GZip, BZip2 or XZ.

If dest is a directory the name of the destination file is the same as src (with the .gz, .bz2 or .xz extension removed if present). If dest is omitted, the parent dir of src is taken. The file is only expanded if the source resource is newer than the destination file, or when the destination file does not exist.

XZ compression support has been added since Apache Ant 1.10.1 and depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.

Parameters

Attribute Description Required
src the file to expand. Yes, or a nested resource collection
dest the destination file or directory. No

Parameters specified as nested elements

any resource or single element resource collection

The specified resource will be used as src.

Examples

Expand test.tar.gz to test.tar

<gunzip src="test.tar.gz"/>

Expand test.tar.bz2 to test.tar

<bunzip2 src="test.tar.bz2"/>

Expand test.tar.xz to test.tar

<unxz src="test.tar.xz"/>

Expand test.tar.gz to test2.tar

<gunzip src="test.tar.gz" dest="test2.tar"/>

Expand test.tar.gz to subdir/test.tar (assuming subdir is a directory).

<gunzip src="test.tar.gz" dest="subdir"/>

Download https://example.org/archive.tar.gz and expand it to archive.tar in the project's basedir on the fly.

<gunzip dest=".">
  <url url="https://example.org/archive.tar.gz"/>
</gunzip>

Related tasks

The following

<gunzip src="some-archive.gz" dest="some-dest-dir"/>

is identical to

<copy todir="some-dest-dir">
  <gzipresource>
    <file file="some-archive.gz"/>
  </gzipresource>
  <mapper type="glob" from="*.gz" to="*"/>
</copy>

The same is also true for <bunzip2> and <bzip2resource> or <unxz> and <xzresource>. <copy> offers additional features like filtering files on the fly, allowing a file to be mapped to multiple destinations, preserving the last modified time or a configurable file system timestamp granularity.