This module archives and extract files to and from
a tar file. This module supports reading most common tar formats,
namely v7, STAR, USTAR, and PAX, as well as some of GNU tar's extensions
to the USTAR format (sparse files most notably). It produces tar archives
in USTAR format, unless the files being archived require PAX format due to
restrictions in USTAR (such as unicode metadata, filename length, and more).
As such,
By convention, the name of a tar file is to end in "
Tar files can be created in one operation using function
Alternatively, for more control, use functions
To extract all files from a tar file, use function
To return a list of the files in a tar file,
use function
To convert an error term returned from one of the functions
above to a readable message, use function
If
If
Unicode metadata stored in PAX headers is preserved
The
An example of this is the SFTP support in
If you must remain compatible with the USTAR tar format, you must ensure file paths being
stored are less than 255 bytes in total, with a maximum filename component
length of 100 bytes. USTAR uses a header field (prefix) in addition to the name field, and
splits file paths longer than 100 bytes into two parts. This split is done on a directory boundary,
and is done in such a way to make the best use of the space available in those two fields, but in practice
this will often mean that you have less than 255 bytes for a path.
Like the above, if you must remain USTAR compatible, you must also ensure than paths for symbolic/hard links are no more than 100 bytes, otherwise PAX headers will be used.
Adds a file to a tar file that has been opened for writing by
Options:
By default, symbolic links are stored as symbolic links
in the tar file. To override the default and store the file
that the symbolic link points to into the tar file, use
option
Prints an informational message about the added file.
Reads data in parts from the file. This is intended for
memory-limited machines that, for example, builds a tar file
on a remote machine over SFTP, see
Adds a file to a tar file that has been opened for writing by
Closes a tar file
opened by
Creates a tar file and archives the files whose names are specified
in
Creates a tar file and archives the files whose names are specified
in
The options in
The entire tar file is compressed, as if it has
been run through the
By default, function
By default, symbolic links are stored as symbolic links in
the tar file. To override the default and store the file that
the symbolic link points to into the tar file, use
option
Prints an informational message about each added file.
Extracts all files from a tar archive.
If argument
If argument
Otherwise,
Extracts files from a tar archive.
If argument
If argument
Otherwise,
The following options modify the defaults for the extraction as follows:
Files with relative filenames are by default extracted
to the current working directory. With this option, files are
instead extracted into directory
By default, all files are extracted from the tar file. With
this option, only those files are extracted whose names are
included in
With this option, the file is uncompressed while extracting. If the tar file is not compressed, this option is ignored.
By default, function
Instead of extracting to a directory, this option gives the
result as a list of tuples
By default, all existing files with the same name as files in the tar file are overwritten. With this option, existing files are not overwriten.
Prints an informational message for each extracted file.
Cconverts an error reason term to a human-readable error message string.
The
The
Parameter
The following are the fun clauses parameter lists:
Writes term
Closes the access.
Reads using
Sets the position of
Example:
The following is a complete
ExampleFun =
fun(write, {Fd,Data}) -> file:write(Fd, Data);
(position, {Fd,Pos}) -> file:position(Fd, Pos);
(read2, {Fd,Size}) -> file:read(Fd, Size);
(close, Fd) -> file:close(Fd)
end
Here
{ok,Fd} = file:open(Name, ...).
{ok,TarDesc} = erl_tar:init(Fd, [write], ExampleFun),
erl_tar:add(TarDesc, SomeValueIwantToAdd, FileNameInTarFile),
...,
erl_tar:close(TarDesc)
When the
This example with the
The
Creates a tar file for writing (any existing file with the same name is truncated).
By convention, the name of a tar file is to end in "
Except for the
The entire tar file is compressed, as if it has been run
through the
By default, the tar file is opened in
To add one file at the time into an opened tar file, use function
The
Retrieves the names of all files in the tar file
Retrieves the names of all files in the tar file
Prints the names of all files in the tar file
Prints names and information about all files in the tar file