Lines Matching +full:tar +full:- +full:stream
1 :mod:`tarfile` --- Read and write tar archive files
5 :synopsis: Read and write tar-format archive files.
15 --------------
17 The :mod:`tarfile` module makes it possible to read and write tar
20 higher-level functions in :ref:`shutil <archiving-operations>`.
27 * read/write support for the POSIX.1-1988 (ustar) format.
29 * read/write support for the GNU tar format including *longname* and *longlink*
30 extensions, read-only support for the *sparse* extension.
32 * read/write support for the POSIX.1-2001 (pax) format.
45 allowed, see :ref:`tarfile-objects`.
50 +------------------+---------------------------------------------+
55 +------------------+---------------------------------------------+
58 +------------------+---------------------------------------------+
60 +------------------+---------------------------------------------+
62 +------------------+---------------------------------------------+
65 +------------------+---------------------------------------------+
67 +------------------+---------------------------------------------+
69 +------------------+---------------------------------------------+
71 +------------------+---------------------------------------------+
87 object that processes its data as a stream of blocks. No random seeking will
93 not allow random access, see :ref:`tar-examples`. The currently
96 +-------------+--------------------------------------------+
99 | ``'r|*'`` | Open a *stream* of tar blocks for reading |
101 +-------------+--------------------------------------------+
102 | ``'r|'`` | Open a *stream* of uncompressed tar blocks |
104 +-------------+--------------------------------------------+
105 | ``'r|gz'`` | Open a gzip compressed *stream* for |
107 +-------------+--------------------------------------------+
108 | ``'r|bz2'`` | Open a bzip2 compressed *stream* for |
110 +-------------+--------------------------------------------+
111 | ``'w|'`` | Open an uncompressed *stream* for writing. |
112 +-------------+--------------------------------------------+
113 | ``'w|gz'`` | Open a gzip compressed *stream* for |
115 +-------------+--------------------------------------------+
116 | ``'w|bz2'`` | Open a bzip2 compressed *stream* for |
118 +-------------+--------------------------------------------+
123 Class for reading and writing tar archives. Do not use this class directly,
124 better use :func:`tarfile.open` instead. See :ref:`tarfile-objects`.
129 Return :const:`True` if *name* is a tar archive file, that the :mod:`tarfile`
135 Class for limited access to tar archives with a :mod:`zipfile`\ -like interface.
142 Constant for an uncompressed tar archive.
147 Constant for a :mod:`gzip` compressed tar archive.
161 Is raised when a tar archive is opened, that either cannot be handled by the
173 Is raised for the limitations that are typical for stream-like :class:`TarFile`
179 Is raised for *non-fatal* errors when using :meth:`TarFile.extract`, but only if
187 The default character encoding: ``'utf-8'`` on Windows, the value returned by
198 Each of the following constants defines a tar archive format that the
199 :mod:`tarfile` module is able to create. See section :ref:`tar-formats` for
205 POSIX.1-1988 (ustar) format.
210 GNU tar format.
215 POSIX.1-2001 (pax) format.
228 :ref:`archiving-operations`
229 Documentation of the higher-level archiving facilities provided by the
232 …`GNU tar manual, Basic Tar Format <https://www.gnu.org/software/tar/manual/html_node/Standard.html…
233 Documentation for tar archive files, including GNU tar extensions.
236 .. _tarfile-objects:
239 ---------------
241 The :class:`TarFile` object provides an interface to a tar archive. A tar
243 a header block followed by data blocks. It is possible to store a file in a tar
245 object, see :ref:`tarinfo-objects` for details.
251 :ref:`tar-examples` section for a use case.
301 :exc:`IOError` exceptions. If ``2``, all *non-fatal* errors are raised as
306 See section :ref:`tar-unicode` for in-depth information.
330 to be the most up-to-date version.
349 similar to that of :program:`ls -l` is produced.
399 or a :class:`TarInfo` object. If *member* is a regular file, a file-like object
400 is returned. If *member* is a link, a file-like object is constructed from the
405 The file-like object is read-only. It provides the methods
421 object will be excluded from the archive. See :ref:`tar-examples` for an
487 A dictionary containing key-value pairs of pax global headers.
492 .. _tarinfo-objects:
495 ---------------
595 A dictionary containing key-value pairs of an associated pax extended header.
647 .. _tar-examples:
650 --------
652 How to extract an entire tar archive to the current working directory::
655 tar = tarfile.open("sample.tar.gz")
656 tar.extractall()
657 tar.close()
659 How to extract a subset of a tar archive with :meth:`TarFile.extractall` using
670 tar = tarfile.open("sample.tar.gz")
671 tar.extractall(members=py_files(tar))
672 tar.close()
674 How to create an uncompressed tar archive from a list of filenames::
677 tar = tarfile.open("sample.tar", "w")
679 tar.add(name)
680 tar.close()
685 with tarfile.open("sample.tar", "w") as tar:
687 tar.add(name)
689 How to read a gzip compressed tar archive and display some member information::
692 tar = tarfile.open("sample.tar.gz", "r:gz")
693 for tarinfo in tar:
701 tar.close()
711 tar = tarfile.open("sample.tar.gz", "w:gz")
712 tar.add("foo", filter=reset)
713 tar.close()
716 .. _tar-formats:
718 Supported tar formats
719 ---------------------
721 There are three tar formats that can be created with the :mod:`tarfile` module:
723 * The POSIX.1-1988 ustar format (:const:`USTAR_FORMAT`). It supports filenames
728 * The GNU tar format (:const:`GNU_FORMAT`). It supports long filenames and
730 standard on GNU/Linux systems. :mod:`tarfile` fully supports the GNU tar
731 extensions for long names, sparse file support is read-only.
733 * The POSIX.1-2001 pax format (:const:`PAX_FORMAT`). It is the most flexible
735 files and stores pathnames in a portable way. However, not all tar
742 the data in a pax header is encoded in *UTF-8* for portability reasons.
744 There are some more variants of the tar format which can be read, but not
747 * The ancient V7 format. This is the first tar format from Unix Seventh Edition,
750 miscalculated header checksums in case of fields with non-ASCII characters.
752 * The SunOS tar extended format. This format is a variant of the POSIX.1-2001
755 .. _tar-unicode:
758 --------------
760 The tar format was originally conceived to make backups on tape drives with the
761 main focus on preserving file system information. Nowadays tar archives are
765 example, an ordinary tar archive created on a *UTF-8* system cannot be read
766 correctly on a *Latin-1* system if it contains non-ASCII characters. Names (i.e.
771 The pax format was designed to solve this problem. It stores non-ASCII names
772 using the universal character encoding *UTF-8*. When a pax archive is read,
773 these *UTF-8* names are converted to the encoding of the local file system.
783 input names that contain non-ASCII characters need to be decoded before being
784 stored as *UTF-8* strings. The other formats do not make use of *encoding*
785 unless unicode objects are used as input names. These are converted to 8-bit
790 :ref:`codec-base-classes`. In read mode, there is an additional scheme
791 ``'utf-8'`` which means that bad characters are replaced by their *UTF-8*