| 1 | """시스템 임시 폴더보다 큰 독립 ZIP과 7z 입력을 만듦.""" |
| 2 | from pathlib import Path |
| 3 | import sys |
| 4 | import zipfile |
| 5 | |
| 6 | from seven_zip_fixtures import archive, integer, property_bytes, packed, streams, SIGNATURE |
| 7 | import struct |
| 8 | import zlib |
| 9 | |
| 10 | root = Path(sys.argv[1]) |
| 11 | payload = b"spool fallback preview\n" |
| 12 | filler = bytes(range(256)) * (16 * 1024 * 1024 // 256) |
| 13 | with zipfile.ZipFile( |
| 14 | root / "archive" / "input.zip", "w", compression=zipfile.ZIP_STORED |
| 15 | ) as target: |
| 16 | target.writestr("preview.txt", payload) |
| 17 | target.writestr("filler.bin", filler) |
| 18 | (root / "archive" / "input.7z").write_bytes( |
| 19 | archive([("preview.txt", payload, 0x20), ("filler.bin", filler, 0x20)], method="copy") |
| 20 | ) |
| 21 | |
| 22 | if len(sys.argv) > 2 and sys.argv[2] == "non-solid": |
| 23 | entries = [("preview.txt", payload), ("filler.bin", filler)] |
| 24 | packed_bytes = b"".join(data for _, data in entries) |
| 25 | sizes = b"".join(integer(len(data)) for _, data in entries) |
| 26 | digests = b"".join(struct.pack("<I", zlib.crc32(data)) for _, data in entries) |
| 27 | info = b"\x06\x00\x02\x09" + sizes + b"\x0a\x01" + digests + b"\x00" |
| 28 | info += b"\x07\x0b\x02\x00" + b"\x01\x01\x00" * 2 |
| 29 | info += b"\x0c" + sizes + b"\x0a\x01" + digests + b"\x00\x08\x00\x00" |
| 30 | files = b"\x05\x02" + property_bytes( |
| 31 | 17, b"\x00" + b"".join(name.encode("utf-16le") + b"\x00\x00" for name, _ in entries) |
| 32 | ) |
| 33 | files += property_bytes(21, b"\x01\x00" + struct.pack("<II", 0x20, 0x20)) |
| 34 | header = b"\x01\x04" + info + files + b"\x00\x00" |
| 35 | encoded, coder = packed(header, "lzma") |
| 36 | next_header = b"\x17" + streams(len(packed_bytes), encoded, coder, header, [header]) |
| 37 | packed_bytes += encoded |
| 38 | start = struct.pack("<QQI", len(packed_bytes), len(next_header), zlib.crc32(next_header)) |
| 39 | (root / "archive" / "input.7z").write_bytes( |
| 40 | SIGNATURE + struct.pack("<I", zlib.crc32(start)) + start + packed_bytes + next_header |
| 41 | ) |