File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env -S uv run --script
2+ # /// script
3+ # dependencies = [
4+ # "zopflipy",
5+ # ]
6+ # ///
7+
8+ import io
9+ import sys
10+ import zipfile
11+ from collections .abc import Sequence
12+ from pathlib import Path
13+ from zopfli import ZipFile
14+
15+ def compress_zip_file (path : Path ) -> str | None :
16+ data = io .BytesIO (path .read_bytes ())
17+
18+ with ZipFile (data , "r" , zipfile .ZIP_DEFLATED ) as source :
19+ with ZipFile (path , "w" , zipfile .ZIP_DEFLATED ) as out :
20+ for zip_info in source .infolist ():
21+ out .writestr (zip_info , source .read (zip_info .filename ))
22+
23+ return None
24+
25+ def main (args : Sequence [str ]) -> str | int :
26+ if not args :
27+ return f"USAGE: { sys .argv [0 ]} FILES.."
28+ for arg in args :
29+ path = Path (arg )
30+ if not path .is_file ():
31+ return f"{ path .as_posix ()} is not a file"
32+ if err := compress_zip_file (path ):
33+ return f"Could not compress { path .as_posix ()} : { err } "
34+
35+ return 0
36+
37+ sys .exit (main (sys .argv [1 :]))
You can’t perform that action at this time.
0 commit comments