.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_archive_extraction.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_07_archive_extraction.py: Archive Extraction =================== This example demonstrates how to extract archives using the `parq_tools` library. The utility supports both standard extraction using Python's `zipfile` module and a fallback to `7-Zip` for cases where unsupported compression methods, such as Deflate64, are used. Use Case -------- Large files zipped in Windows can result in compression with Deflate64. In such cases, `parq_tools` provides a fallback mechanism to use `7-Zip` for extraction. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python from pathlib import Path import tempfile from parq_tools.utils.archive_utils import extract_archive .. GENERATED FROM PYTHON SOURCE LINES 20-26 Create an Example Archive -------------------------- For demonstration purposes, we create a simple ZIP archive. Note that this example assumes the archive does not use unsupported compression methods like Deflate64. If such a method is used, the fallback to `7-Zip` will be triggered during extraction. .. GENERATED FROM PYTHON SOURCE LINES 26-39 .. code-block:: Python import zipfile def create_example_archive(archive_path: Path): with zipfile.ZipFile(archive_path, 'w') as zipf: zipf.writestr("example.txt", "This is an example file.") # Create a temporary directory and archive temp_dir = Path(tempfile.gettempdir()) / "archive_example" temp_dir.mkdir(parents=True, exist_ok=True) example_archive = temp_dir / "example.zip" create_example_archive(example_archive) .. GENERATED FROM PYTHON SOURCE LINES 40-45 Extract the Archive -------------------- Use the `extract_archive` function to extract the contents of the archive. If the archive uses an unsupported compression method, the function will automatically fall back to `7-Zip` (if installed). .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python output_dir = temp_dir / "extracted" extract_archive(example_archive, output_dir, show_progress=True) .. rst-class:: sphx-glr-script-out .. code-block:: none Extracting: 0%| | 0.00/24.0 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 07_archive_extraction.py <07_archive_extraction.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_