@@ -18,8 +18,8 @@ higher-level functions in :ref:`shutil <archiving-operations>`.
1818
1919Some facts and figures:
2020
21- * reads and writes :mod: `gzip `, :mod: `bz2 ` and :mod: `lzma ` compressed archives
22- if the respective modules are available.
21+ * reads and writes :mod: `gzip `, :mod: `bz2 `, :mod: `compression.zstd `, and
22+ :mod: ` lzma ` compressed archives if the respective modules are available.
2323
2424* read/write support for the POSIX.1-1988 (ustar) format.
2525
@@ -47,6 +47,10 @@ Some facts and figures:
4747 or paths outside of the destination. Previously, the filter strategy
4848 was equivalent to :func: `fully_trusted <fully_trusted_filter> `.
4949
50+ .. versionchanged :: 3.14
51+
52+ Added support for Zstandard compression using :mod: `compression.zstd `.
53+
5054.. function :: open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
5155
5256 Return a :class: `TarFile ` object for the pathname *name *. For detailed
@@ -71,6 +75,8 @@ Some facts and figures:
7175 +------------------+---------------------------------------------+
7276 | ``'r:xz' `` | Open for reading with lzma compression. |
7377 +------------------+---------------------------------------------+
78+ | ``'r:zst' `` | Open for reading with Zstandard compression.|
79+ +------------------+---------------------------------------------+
7480 | ``'x' `` or | Create a tarfile exclusively without |
7581 | ``'x:' `` | compression. |
7682 | | Raise a :exc: `FileExistsError ` exception |
@@ -88,6 +94,10 @@ Some facts and figures:
8894 | | Raise a :exc: `FileExistsError ` exception |
8995 | | if it already exists. |
9096 +------------------+---------------------------------------------+
97+ | ``'x:zst' `` | Create a tarfile with Zstandard compression.|
98+ | | Raise a :exc: `FileExistsError ` exception |
99+ | | if it already exists. |
100+ +------------------+---------------------------------------------+
91101 | ``'a' or 'a:' `` | Open for appending with no compression. The |
92102 | | file is created if it does not exist. |
93103 +------------------+---------------------------------------------+
@@ -99,6 +109,8 @@ Some facts and figures:
99109 +------------------+---------------------------------------------+
100110 | ``'w:xz' `` | Open for lzma compressed writing. |
101111 +------------------+---------------------------------------------+
112+ | ``'w:zst' `` | Open for Zstandard compressed writing. |
113+ +------------------+---------------------------------------------+
102114
103115 Note that ``'a:gz' ``, ``'a:bz2' `` or ``'a:xz' `` is not possible. If *mode *
104116 is not suitable to open a certain (compressed) file for reading,
@@ -115,6 +127,15 @@ Some facts and figures:
115127 For modes ``'w:xz' ``, ``'x:xz' `` and ``'w|xz' ``, :func: `tarfile.open ` accepts the
116128 keyword argument *preset * to specify the compression level of the file.
117129
130+ For modes ``'w:zst' ``, ``'x:zst' `` and ``'w|zst' ``, :func: `tarfile.open `
131+ accepts the keyword argument *level * to specify the compression level of
132+ the file. The keyword argument *options * may also be passed, providing
133+ advanced Zstandard compression parameters described by
134+ :class: `~compression.zstd.CompressionParameter `. The keyword argument
135+ *zstd_dict * can be passed to provide a :class: `~compression.zstd.ZstdDict `,
136+ a Zstandard dictionary used to improve compression of smaller amounts of
137+ data.
138+
118139 For special purposes, there is a second format for *mode *:
119140 ``'filemode|[compression]' ``. :func: `tarfile.open ` will return a :class: `TarFile `
120141 object that processes its data as a stream of blocks. No random seeking will
@@ -146,6 +167,9 @@ Some facts and figures:
146167 | ``'r|xz' `` | Open an lzma compressed *stream * for |
147168 | | reading. |
148169 +-------------+--------------------------------------------+
170+ | ``'r|zst' `` | Open a Zstandard compressed *stream * for |
171+ | | reading. |
172+ +-------------+--------------------------------------------+
149173 | ``'w|' `` | Open an uncompressed *stream * for writing. |
150174 +-------------+--------------------------------------------+
151175 | ``'w|gz' `` | Open a gzip compressed *stream * for |
@@ -157,6 +181,9 @@ Some facts and figures:
157181 | ``'w|xz' `` | Open an lzma compressed *stream * for |
158182 | | writing. |
159183 +-------------+--------------------------------------------+
184+ | ``'w|zst' `` | Open a Zstandard compressed *stream * for |
185+ | | writing. |
186+ +-------------+--------------------------------------------+
160187
161188 .. versionchanged :: 3.5
162189 The ``'x' `` (exclusive creation) mode was added.
0 commit comments