| 1 | import gzip |
| 2 | from io import BytesIO |
| 3 | from pathlib import Path |
| 4 | import tarfile |
| 5 | import zipfile |
| 6 | |
| 7 | ROOT = Path(__file__).resolve().parent / "fixtures" |
| 8 | PAYLOAD = b"Zipelo real worker flow\n" |
| 9 | ROOT.mkdir(exist_ok=True) |
| 10 | stream = BytesIO() |
| 11 | with zipfile.ZipFile(stream, "w") as archive: |
| 12 | info = zipfile.ZipInfo("content.txt", (1980, 1, 1, 0, 0, 0)) |
| 13 | info.compress_type = zipfile.ZIP_DEFLATED |
| 14 | archive.writestr(info, PAYLOAD) |
| 15 | (ROOT / "sample.zip").write_bytes(stream.getvalue()) |
| 16 | stream = BytesIO() |
| 17 | with tarfile.open(fileobj=stream, mode="w", format=tarfile.USTAR_FORMAT) as archive: |
| 18 | info = tarfile.TarInfo("content.txt") |
| 19 | info.size = len(PAYLOAD) |
| 20 | info.mode = 0o600 |
| 21 | archive.addfile(info, BytesIO(PAYLOAD)) |
| 22 | compressed = bytearray(gzip.compress(stream.getvalue(), mtime=0)) |
| 23 | compressed[9] = 255 |
| 24 | (ROOT / "sample.tar.gz").write_bytes(compressed) |