Commit 1d218bc
xxwhirlpool
·
2026-04-24 19:37:21 -0400 EDT
parent 9aa0ec7
stack overflow script i didn't write
1 files changed,
+19,
-0
+19,
-0
| ... | ... | @@ -0,0 +1,19 @@ | |
| 1 | + | #!/usr/bin/env -S uv run --script | |
| 2 | + | # | |
| 3 | + | # by someone on stackoverflow: | |
| 4 | + | # https://stackoverflow.com/questions/6301885/convert-tar-gz-to-zip/43940597#43940597 | |
| 5 | + | ||
| 6 | + | import sys, tarfile, zipfile, glob | |
| 7 | + | ||
| 8 | + | def convert_one_archive(file_name): | |
| 9 | + | out_file = file_name.replace('.tar.gz', '.zip') | |
| 10 | + | with tarfile.open(file_name, mode='r:gz') as tf: | |
| 11 | + | with zipfile.ZipFile(out_file, mode='a', compression=zipfile.ZIP_DEFLATED) as zf: | |
| 12 | + | for m in tf.getmembers(): | |
| 13 | + | f = tf.extractfile( m ) | |
| 14 | + | fl = f.read() | |
| 15 | + | fn = m.name | |
| 16 | + | zf.writestr(fn, fl) | |
| 17 | + | ||
| 18 | + | for f in glob.glob('*.tar.gz'): | |
| 19 | + | convert_one_archive(f) |