Tar File Manual¶
This project provides functionality to read and write a variety of tar archive
formats. Currently supported are the POSIX ustar, PAX (ustar with a few new
entry types), GNU, and v7 (very old) formats.
This project is rather low level and is focused exclusively on reading and
writing physical tar file entries using streams. Therefore, it contains no
functionality to automatically build archives from a set of files on the
filesystem or write the contents of a file to the filesystem. Additionally,
there are no smarts that read multiple physical entries and combine them into a
single logical entry (e.g., with PAX extended headers or GNU long link/path
name support). This approach is taken to both improve portability (the CL spec
has no facility for things like detecting symlinks or modifying/reading file
owners, etc.) and properly separate concerns.
For a higher level library that reads and writes logical entries, as well as includes file system integration, see cl-tar.
This project is a fork of Nathan Froyd's archive library. Much code remains, but the non-portable bits have been stripped, better support for multiple archive types (and autodetection) has been added, better blocking support added (tar readers/writers are supposed to read/write in multiples of 512 bytes), cpio support removed, and a test suite added, along with other miscellaneous fixes and improvements.
One major user visible difference between this library and the original archive
is that there is no need to discard entries when you are finished with them and
support has been added for seeking within a stream (using FILE-POSITION under
the hood). This means you can do something like iterate over all entries in one
go and then get a stream containing the contents of an arbitrary entry.
However, care must be taken if you hop around in a tar file as it will only
work if the underlying stream containing the tar archive is
seekable. Typically, streams backed by files are seekable, but all other
input streams (including stdin) are not. Therefore if there is any chance
your code that uses tar-file will read files from non-seekable streams, you
should process entries sequentially and completely before moving on to the next
one. Alternatively, you can set the blocking factor high enough that the entire
file is read into memory at once (yikes!).
Opening and Closing Tar Files¶
-
[variable]
:latin-1
The default encoding to use for strings read from/written to tar headers. Must be recognized by Babel.
-
[macro]
(tar-file-var pathname-or-stream &key (direction :input)
(if-exists nil) (if-does-not-exist nil) (type :auto) (blocking-factor 20)
(header-encoding '\*default-header-encoding\*)) &body body
Bind
TAR-FILE-VARto a newly openedtar-file, backed byPATHNAME-OR-STREAM. IfPATHNAME-OR-STREAMevaluates to a stream, that stream is used directly, otherwise, it is opened viaOPEN. IfPATHNAME-OR-STREAMis a stream, that stream is not closed upon exiting the body of the macro.DIRECTIONmust be either:INPUTor:OUTPUT.IF-EXISTSandIF-DOES-NOT-EXISTare passed toOPENifPATHNAME-OR-STREAMis not a stream.See
open-tar-filefor a description ofTYPE,BLOCKING-FACTOR, andHEADER-ENCODING.
-
[function]
stream &key (direction :input) (type :auto)
(blocking-factor 20) (header-encoding \*default-header-encoding\*)
Create a
tar-fileobject backed bySTREAM. TheSTREAMshould not be read from or written to any more.DIRECTIONis either:INPUTor:OUTPUT.BLOCKING-FACTORis an integer that specifies how many 512-byte blocks should be read from or written toSTREAMat any one time.TYPEis eitherAUTOor a class designator for a subclass oftar-file. If:AUTO, the appropriate class will be determined by looking at the first tar header.HEADER-ENCODINGis an encoding specifier recognized by Babel.
-
[generic-function]
tar-file
Perform any necessary processing for finalizing
TAR-FILE. This function must be called prior to callingclose-tar-file.
-
[generic-function]
tar-file
Closes the stream associated with
TAR-FILEand the tar-file itself. Further operations on the tar-file are undefined.Does
NOTclose the underlyingSTREAMthat backed theTAR-FILE.
Tar Archive Types¶
There are three different types of tar archives that this system can handle, with a common base class.
-
[class]
Base class of a tar file.
- [class]
A ustar tar file.
- [class]
A gnu tar file.
- [class]
A v7 tar file.
Entries¶
-
[macro]
(entry tar-file &optional result) &body body
Iterate over the entries in
tar-file. For each entry,entryis bound to anentryrepresenting the entry.RESULTis used as inDOTIMES.
-
[generic-function]
tar-file
Return the next entry in
TAR-FILEorNILif there is no next entry
-
[class]
Base class for all entries in a tar file.
-
[generic-function]
entry
Returns non-
NILifENTRYhas associated data that can be read usingmake-entry-stream.
-
[generic-function]
entry
Returns a new binary stream that contains
ENTRY's data.
-
[generic-function]
entry
Return the name of the
ENTRY(a string).
-
[generic-function]
entry
Return the size of the
ENTRY(an integer).
-
[generic-function]
entry
Return the uname of the
ENTRY(a string).
-
[generic-function]
entry
Return the gname of the
ENTRY(a string).
-
[generic-function]
entry
Return the mode of the
ENTRY(an integer).
-
[generic-function]
entry
Return the mtime of the
ENTRY(an integer).
-
[generic-function]
entry
Return the uid of the
ENTRY(an integer).
-
[generic-function]
entry
Return the gid of the
ENTRY(an integer).
-
[generic-function]
entry
Return the linkname of the
ENTRY(a string).
-
[generic-function]
entry
Return the major device of the
ENTRY(an integer).
-
[generic-function]
entry
Return the minor device of the
ENTRY(an integer).
-
[generic-function]
entry
Return the prefix of the
ENTRY(a string).
-
[generic-function]
entry
Return the atime of the
ENTRY(an integer).
-
[generic-function]
entry
Return the ctime of the
ENTRY(an integer).
-
[generic-function]
entry
Return the offset of the
ENTRY(an integer).
-
[generic-function]
entry
Return the offset of the first sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the numbytes of the first sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the offset of the second sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the numbytes of the second sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the offset of the third sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the numbytes of the third sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the offset of the fourth sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the numbytes of the fourth sparse block of the
ENTRY(an integer).
-
[generic-function]
entry
Return the isextended field of the
ENTRY(an integer).
-
[generic-function]
entry
Return the realsize of the
ENTRY(an integer).
-
[generic-function]
entry name &optional default
Get the
NAMEattribute fromENTRY.
-
[generic-function]
entry
Return a list of attribute names contained within
ENTRY.
-
[macro]
(name value entry &optional result) &body body
Given a
PAXentrywith attributes, executeBODYfor every attribute, withnamebound to the attribute name andVALUEbound to the attribute value.
File Entry¶
-
[class]
A regular file.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid size data prefix
Write a
file-entrytoTAR-FILE.DATAcan be eitherNIL(no data is written), an octet vector (written as is), a string (encoded usingUTF-8and written), or aPATHNAME(opened, read, and written to the archive).
-
[generic-function]
entry
Returns non-
NILifENTRYdenotes a regular file.
Symbolic Link Entry ¶
- [class]
A symbolic link.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid linkname prefix
Write a
symbolic-link-entrytoTAR-FILE.
-
[generic-function]
entry
Returns non-
NILifENTRYdenotes a symbolic link.
Hard Link Entry¶
- [class]
A hard link.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid linkname prefix
Write a
hard-link-entrytoTAR-FILE.
Character Device Entry ¶
-
[class]
A character device.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid devmajor devminor prefix
Write a
character-device-entrytoTAR-FILE.
-
[generic-function]
entry
Returns non-
NILifENTRYdenotes a character device.
Block Device Entry ¶
-
[class]
A block device.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid devmajor devminor prefix
Write a
block-device-entrytoTAR-FILE.
-
[generic-function]
entry
Returns non-
NILifENTRYdenotes a block device.
Fifo Entry¶
-
[class]
A
FIFO.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid prefix
Write a
fifo-entrytoTAR-FILE.
-
[generic-function]
entry
Returns non-
NILifENTRYdenotes a fifo.
Directory Entry¶
-
[class]
A directory.
-
[generic-function]
tar-file name &rest args &key uname gname mode mtime
uid gid size prefix
Write a
directory-entrytoTAR-FILE.
-
[generic-function]
entry
Returns non-
NILifENTRYdenotes a directory.
Pax Extended Attributes Entry ¶
-
[class]
Extended attributes for the subsequent record.
-
[generic-function]
tar-file name &rest args &key attributes
Write a
pax-extended-attributes-entrytoTAR-FILE.ATTRIBUTESmust be either a hash table mapping strings to strings or an alist mapping strings to strings. If it is an alist, ordering is preserved.
-
[generic-function]
entry
Returns non-
NILifENTRYcontainsPAXextended attributes.
Pax Global Attributes Entry ¶
-
[class]
Extended attributes for all subsequent records.
-
[generic-function]
tar-file name &rest args &key attributes
Write a
pax-global-attributes-entrytoTAR-FILE.ATTRIBUTESmust be either a hash table mapping strings to strings or an alist mapping strings to strings. If it is an alist, ordering is preserved.
-
[generic-function]
entry
Returns non-
NILifENTRYcontainsPAXglobal attributes.
Gnu Long Link Name Entry ¶
-
[generic-function]
tar-file name &rest args &key data
Write a
gnu-long-link-name-entrytoTAR-FILE.DATAmust be either a string (which is thenUTF-8encoded) or a byte vector.
-
[generic-function]
entry
Returns non-
NILifENTRYcontains aGNUlong link name.
Gnu Long Name Entry ¶
-
[generic-function]
tar-file name &rest args &key data
Write a
gnu-long-name-entrytoTAR-FILE.DATAmust be either a string (which is thenUTF-8encoded) or a byte vector.
-
[generic-function]
entry
Returns non-
NILifENTRYcontains aGNUlong name.
Gnu Directory Dump Entry ¶
-
[generic-function]
entry
Returns non-
NILifENTRYcontains aGNUdirectory dump.
Gnu-Sparse-File Entry ¶
-
[generic-function]
entry
Returns non-
NILifENTRYcontains aGNUsparse file.
Gnu Volume Header Name Entry ¶
-
[generic-function]
entry
Returns non-
NILifENTRYcontains aGNUvolume header name.
Unknown Entry¶
-
[class]
An unknown entry.
-
[generic-function]
entry
Returns non-
NILifENTRYis unknown.
Conditions¶
-
[condition]
All errors signaled are of this type.
-
[condition]
Signaled when the checksum in a tar header is invalid.