You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fast and convenient function, compresses *input_stream* and writes the compressed data to *output_stream*, it doesn't close the streams.
167
-
168
-
If input stream is ``b''``, nothing will be written to output stream.
169
-
170
-
This function tries to zero-copy as much as possible. If the OS has read prefetching and write buffer, it may perform the tasks (read/compress/write) in parallel to some degree.
171
-
172
-
The default values of *read_size* and *write_size* parameters are the buffer sizes recommended by zstd, increasing them may be faster, and reduces the number of callback function calls.
173
-
174
-
.. versionadded:: 0.14.2
175
-
176
-
:param input_stream: Input stream that has a `.readinto(b) <https://docs.python.org/3/library/io.html#io.RawIOBase.readinto>`_ method.
177
-
:param output_stream: Output stream that has a `.write(b) <https://docs.python.org/3/library/io.html#io.RawIOBase.write>`_ method. If use *callback* function, this parameter can be ``None``.
178
-
:param level_or_option: When it's an ``int`` object, it represents :ref:`compression level<compression_level>`. When it's a ``dict`` object, it contains :ref:`advanced compression parameters<CParameter>`. The default value ``None`` means to use zstd's default compression level/parameters.
179
-
:type level_or_option: int or dict
180
-
:param zstd_dict: Pre-trained dictionary for compression.
181
-
:type zstd_dict: ZstdDict
182
-
:param pledged_input_size: If set this parameter to the size of input data, the :ref:`size<content_size>` will be written into the frame header. If the actual input data doesn't match it, a :py:class:`ZstdError` exception will be raised. It may increase compression ratio slightly, and help decompression code to allocate output buffer faster.
183
-
:type pledged_input_size: int
184
-
:param read_size: Input buffer size, in bytes.
185
-
:type read_size: int
186
-
:param write_size: Output buffer size, in bytes.
187
-
:type write_size: int
188
-
:param callback: A callback function that accepts four parameters: ``(total_input, total_output, read_data, write_data)``. The first two are ``int`` objects. The last two are readonly `memoryview <https://docs.python.org/3/library/stdtypes.html#memory-views>`_ objects, if want to reference the data (or its slice) outside the callback function, `convert <https://docs.python.org/3/library/stdtypes.html#memoryview.tobytes>`_ them to ``bytes`` objects. If input stream is ``b''``, the callback function will not be called.
189
-
:type callback: callable
190
-
:return: A 2-item tuple, ``(total_input, total_output)``, the items are ``int`` objects.
191
-
192
-
.. sourcecode:: python
193
-
194
-
# compress an input file, and write to an output file.
This function tries to zero-copy as much as possible. If the OS has read prefetching and write buffer, it may perform the tasks (read/decompress/write) in parallel to some degree.
332
-
333
-
The default values of *read_size* and *write_size* parameters are the buffer sizes recommended by zstd, increasing them may be faster, and reduces the number of callback function calls.
334
-
335
-
.. versionadded:: 0.14.2
336
-
337
-
:param input_stream: Input stream that has a `.readinto(b) <https://docs.python.org/3/library/io.html#io.RawIOBase.readinto>`_ method.
338
-
:param output_stream: Output stream that has a `.write(b) <https://docs.python.org/3/library/io.html#io.RawIOBase.write>`_ method. If use *callback* function, this parameter can be ``None``.
339
-
:param zstd_dict: Pre-trained dictionary for decompression.
340
-
:type zstd_dict: ZstdDict
341
-
:param option: A ``dict`` object, contains :ref:`advanced decompression parameters<DParameter>`.
342
-
:type option: dict
343
-
:param read_size: Input buffer size, in bytes.
344
-
:type read_size: int
345
-
:param write_size: Output buffer size, in bytes.
346
-
:type write_size: int
347
-
:param callback: A callback function that accepts four parameters: ``(total_input, total_output, read_data, write_data)``. The first two are ``int`` objects. The last two are readonly `memoryview <https://docs.python.org/3/library/stdtypes.html#memory-views>`_ objects, if want to reference the data (or its slice) outside the callback function, `convert <https://docs.python.org/3/library/stdtypes.html#memoryview.tobytes>`_ them to ``bytes`` objects. If input stream is ``b''``, the callback function will not be called.
348
-
:type callback: callable
349
-
:return: A 2-item tuple, ``(total_input, total_output)``, the items are ``int`` objects.
350
-
:raises ZstdError: If decompression fails.
351
-
352
-
.. sourcecode:: python
353
-
354
-
# decompress an input file, and write to an output file.
355
-
with io.open(input_file_path, 'rb') as ifh:
356
-
with io.open(output_file_path, 'wb') as ofh:
357
-
decompress_stream(ifh, ofh)
358
-
359
-
# decompress a bytes object, and write to a file.
360
-
with io.BytesIO(compressed_dat) as bi:
361
-
with io.open(output_file_path, 'wb') as ofh:
362
-
decompress_stream(bi, ofh)
363
-
364
-
# Decompress an input file, obtain a bytes object.
365
-
# It's faster than reading a file and decompressing it in
366
-
# memory, tested on Ubuntu(Python3.8)/Windows(Python3.9).
367
-
# Maybe the OS has prefetching, it can read and decompress
368
-
# data in parallel to some degree, reading file from HDD
with pyzstd.open(name, level_or_option=level_or_option, zstd_dict=zstd_dict) as ifh:
1416
+
shutil.copyfile(ifh, tmp_file)
1550
1417
tmp_file.seek(0)
1551
1418
with tarfile.TarFile(fileobj=tmp_file, **kwargs) as tar:
1552
1419
yield tar
@@ -1718,3 +1585,11 @@ Build pyzstd module with options
1718
1585
3️⃣ Disable mremap output buffer on CPython+Linux.
1719
1586
1720
1587
On CPython(3.5~3.12)+Linux, pyzstd uses another output buffer code that can utilize the ``mremap`` mechanism, which brings some performance improvements. If this causes problems, you may use ``--no-mremap`` option to disable this code.
1588
+
1589
+
1590
+
Deprecations
1591
+
>>>>>>>>>>>>
1592
+
1593
+
See `list of deprecations with alternatives <./deprecated.html>`_.
1594
+
1595
+
Also, note that `unsupported Python versions <https://devguide.python.org/versions/#supported-versions>` are not tested against and have no wheels uploaded on PyPI.
0 commit comments