zipfile-deflate64
zipfile-deflate64 is a Python library that extends the standard `zipfile` module to enable extraction of ZIP archives compressed with the Deflate64 algorithm. This is particularly useful for handling large ZIP files (>2GB) created by tools like Microsoft Windows Explorer, which often use Deflate64 compression. It is currently at version 0.2.0 and has a release cadence driven by bug fixes and Python version compatibility updates.
Warnings
- gotcha The standard `zipfile` module in Python does not natively support Deflate64 compression. Attempting to open or extract a Deflate64 ZIP archive without importing `zipfile_deflate64` will result in errors like `BadZipFile` or 'compression method not supported'.
- breaking Version 0.2.0 fixed significant bugs in `zipfile_deflate64.extractall` and `zipfile_deflate64.extract` (especially with larger files). Users on older versions might encounter issues or incorrect extractions.
- gotcha The library's PyPI page lists its development status as '3 - Alpha'. While it provides crucial functionality, this status indicates it may not be fully stable for all production scenarios and could introduce breaking changes in future minor versions.
Install
-
pip install zipfile-deflate64
Imports
- zipfile_deflate64
import zipfile_deflate64
- ZipFile
import zipfile_deflate64 as zipfile archive = zipfile.ZipFile('path/to/archive.zip', 'r')
Quickstart
import os
import zipfile
import zipfile_deflate64 as custom_zipfile # This line enables Deflate64 support
# Create a dummy (standard Deflate) zip file for demonstration
dummy_zip_path = 'my_test_archive.zip'
with zipfile.ZipFile(dummy_zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
zf.writestr('file1.txt', 'Hello from file 1!')
zf.writestr('folder/file2.txt', 'Content for file 2.')
# Directory to extract to
extract_dir = 'extracted_content'
os.makedirs(extract_dir, exist_ok=True)
try:
# Use the patched zipfile API to extract
# This would work for both standard and Deflate64 archives after the import
with custom_zipfile.ZipFile(dummy_zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_dir)
print(f"Successfully extracted '{dummy_zip_path}' to '{extract_dir}'")
# Verify extraction
print(f"Content of {os.path.join(extract_dir, 'file1.txt')}: ")
with open(os.path.join(extract_dir, 'file1.txt'), 'r') as f:
print(f.read())
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Clean up dummy files
if os.path.exists(dummy_zip_path):
os.remove(dummy_zip_path)
if os.path.exists(os.path.join(extract_dir, 'file1.txt')):
os.remove(os.path.join(extract_dir, 'file1.txt'))
if os.path.exists(os.path.join(extract_dir, 'folder', 'file2.txt')):
os.remove(os.path.join(extract_dir, 'folder', 'file2.txt'))
if os.path.exists(os.path.join(extract_dir, 'folder')):
os.rmdir(os.path.join(extract_dir, 'folder'))
if os.path.exists(extract_dir):
os.rmdir(extract_dir)