-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_zip.py
More file actions
61 lines (51 loc) · 1.58 KB
/
debug_zip.py
File metadata and controls
61 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import zipfile
import tempfile
from pathlib import Path
from mdf_zipper import MDFZipper
# Create test data
temp_dir = Path(tempfile.mkdtemp())
test_dir = temp_dir / 'test'
test_dir.mkdir()
sub_dir = test_dir / 'dataset'
sub_dir.mkdir()
(sub_dir / 'data.txt').write_text('Test data\n' * 100)
# Create ZIP
zipper = MDFZipper(max_size_gb=0.01)
zipper.process_directory(str(test_dir))
archive_path = sub_dir / '.mdf' / 'dataset.zip'
print(f"Archive path: {archive_path}")
print(f"Archive exists: {archive_path.exists()}")
# Check original
print(f"Original is_zipfile: {zipfile.is_zipfile(archive_path)}")
with open(archive_path, 'rb') as f:
header = f.read(20)
print(f"Original header: {header}")
# Corrupt the file
with open(archive_path, 'r+b') as f:
f.seek(0)
f.write(b'CORRUPT!')
# Check corrupted
with open(archive_path, 'rb') as f:
header = f.read(20)
print(f"Corrupted header: {header}")
print(f"Corrupted is_zipfile: {zipfile.is_zipfile(archive_path)}")
# Try to open corrupted file
try:
with zipfile.ZipFile(archive_path, 'r') as zf:
print("Successfully opened corrupted ZIP")
try:
files = zf.namelist()
print(f"Files in corrupted ZIP: {files}")
except Exception as e:
print(f"Error reading files: {e}")
try:
result = zf.testzip()
print(f"testzip result: {result}")
except Exception as e:
print(f"testzip error: {e}")
except Exception as e:
print(f"Error opening corrupted ZIP: {e}")
# Clean up
import shutil
shutil.rmtree(temp_dir)