@@ -18,8 +18,8 @@ higher-level functions in :ref:`shutil <archiving-operations>`.
18
18
19
19
Some facts and figures:
20
20
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.
23
23
24
24
* read/write support for the POSIX.1-1988 (ustar) format.
25
25
@@ -47,6 +47,10 @@ Some facts and figures:
47
47
or paths outside of the destination. Previously, the filter strategy
48
48
was equivalent to :func: `fully_trusted <fully_trusted_filter> `.
49
49
50
+ .. versionchanged :: 3.14
51
+
52
+ Added support for Zstandard compression using :mod: `compression.zstd `.
53
+
50
54
.. function :: open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
51
55
52
56
Return a :class: `TarFile ` object for the pathname *name *. For detailed
@@ -71,6 +75,8 @@ Some facts and figures:
71
75
+------------------+---------------------------------------------+
72
76
| ``'r:xz' `` | Open for reading with lzma compression. |
73
77
+------------------+---------------------------------------------+
78
+ | ``'r:zst' `` | Open for reading with Zstandard compression.|
79
+ +------------------+---------------------------------------------+
74
80
| ``'x' `` or | Create a tarfile exclusively without |
75
81
| ``'x:' `` | compression. |
76
82
| | Raise a :exc: `FileExistsError ` exception |
@@ -88,6 +94,10 @@ Some facts and figures:
88
94
| | Raise a :exc: `FileExistsError ` exception |
89
95
| | if it already exists. |
90
96
+------------------+---------------------------------------------+
97
+ | ``'x:zst' `` | Create a tarfile with Zstandard compression.|
98
+ | | Raise a :exc: `FileExistsError ` exception |
99
+ | | if it already exists. |
100
+ +------------------+---------------------------------------------+
91
101
| ``'a' or 'a:' `` | Open for appending with no compression. The |
92
102
| | file is created if it does not exist. |
93
103
+------------------+---------------------------------------------+
@@ -99,6 +109,8 @@ Some facts and figures:
99
109
+------------------+---------------------------------------------+
100
110
| ``'w:xz' `` | Open for lzma compressed writing. |
101
111
+------------------+---------------------------------------------+
112
+ | ``'w:zst' `` | Open for Zstandard compressed writing. |
113
+ +------------------+---------------------------------------------+
102
114
103
115
Note that ``'a:gz' ``, ``'a:bz2' `` or ``'a:xz' `` is not possible. If *mode *
104
116
is not suitable to open a certain (compressed) file for reading,
@@ -115,6 +127,15 @@ Some facts and figures:
115
127
For modes ``'w:xz' ``, ``'x:xz' `` and ``'w|xz' ``, :func: `tarfile.open ` accepts the
116
128
keyword argument *preset * to specify the compression level of the file.
117
129
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
+
118
139
For special purposes, there is a second format for *mode *:
119
140
``'filemode|[compression]' ``. :func: `tarfile.open ` will return a :class: `TarFile `
120
141
object that processes its data as a stream of blocks. No random seeking will
@@ -146,6 +167,9 @@ Some facts and figures:
146
167
| ``'r|xz' `` | Open an lzma compressed *stream * for |
147
168
| | reading. |
148
169
+-------------+--------------------------------------------+
170
+ | ``'r|zst' `` | Open a Zstandard compressed *stream * for |
171
+ | | reading. |
172
+ +-------------+--------------------------------------------+
149
173
| ``'w|' `` | Open an uncompressed *stream * for writing. |
150
174
+-------------+--------------------------------------------+
151
175
| ``'w|gz' `` | Open a gzip compressed *stream * for |
@@ -157,6 +181,9 @@ Some facts and figures:
157
181
| ``'w|xz' `` | Open an lzma compressed *stream * for |
158
182
| | writing. |
159
183
+-------------+--------------------------------------------+
184
+ | ``'w|zst' `` | Open a Zstandard compressed *stream * for |
185
+ | | writing. |
186
+ +-------------+--------------------------------------------+
160
187
161
188
.. versionchanged :: 3.5
162
189
The ``'x' `` (exclusive creation) mode was added.
0 commit comments