| 1 | import bz2 |
| 2 | import gzip |
| 3 | import lzma |
| 4 | from pathlib import Path |
| 5 | import sys |
| 6 | |
| 7 | |
| 8 | root = Path(sys.argv[1]) |
| 9 | case = sys.argv[2] |
| 10 | if case == "bomb": |
| 11 | with gzip.open(root / "input", "wb", compresslevel=9) as output: |
| 12 | block = bytes(1024 * 1024) |
| 13 | for _ in range(257): |
| 14 | output.write(block) |
| 15 | elif case in {"bz2", "xz"}: |
| 16 | source = Path(__file__).with_name("fixtures").joinpath("sample.tar").read_bytes() |
| 17 | encode = bz2.compress if case == "bz2" else lzma.compress |
| 18 | (root / "input").write_bytes(encode(source)) |
| 19 | else: |
| 20 | raise ValueError(case) |