(self)
| 901 | self.doTest(".py", files, "f65536", comment=b"c" * ((1 << 16) - 1)) |
| 902 | |
| 903 | def testZip64LargeFile(self): |
| 904 | support.requires( |
| 905 | "largefile", |
| 906 | f"test generates files >{0xFFFFFFFF} bytes and takes a long time " |
| 907 | "to run" |
| 908 | ) |
| 909 | |
| 910 | # N.B.: We do a lot of gymnastics below in the ZIP_STORED case to save |
| 911 | # and reconstruct a sparse zip on systems that support sparse files. |
| 912 | # Instead of creating a ~8GB zip file mainly consisting of null bytes |
| 913 | # for every run of the test, we create the zip once and save off the |
| 914 | # non-null portions of the resulting file as data blobs with offsets |
| 915 | # that allow re-creating the zip file sparsely. This drops disk space |
| 916 | # usage to ~9KB for the ZIP_STORED case and drops that test time by ~2 |
| 917 | # orders of magnitude. For the ZIP_DEFLATED case, however, we bite the |
| 918 | # bullet. The resulting zip file is ~8MB of non-null data; so the sparse |
| 919 | # trick doesn't work and would result in that full ~8MB zip data file |
| 920 | # being checked in to source control. |
| 921 | parts_glob = f"sparse-zip64-c{self.compression:d}-0x*.part" |
| 922 | full_parts_glob = os.path.join(TEST_DATA_DIR, parts_glob) |
| 923 | pre_built_zip_parts = glob.glob(full_parts_glob) |
| 924 | |
| 925 | self.addCleanup(os_helper.unlink, TEMP_ZIP) |
| 926 | if not pre_built_zip_parts: |
| 927 | if self.compression != ZIP_STORED: |
| 928 | support.requires( |
| 929 | "cpu", |
| 930 | "test requires a lot of CPU for compression." |
| 931 | ) |
| 932 | self.addCleanup(os_helper.unlink, os_helper.TESTFN) |
| 933 | with open(os_helper.TESTFN, "wb") as f: |
| 934 | f.write(b"data") |
| 935 | f.write(os.linesep.encode()) |
| 936 | f.seek(0xffff_ffff, os.SEEK_CUR) |
| 937 | f.write(os.linesep.encode()) |
| 938 | os.utime(os_helper.TESTFN, (0.0, 0.0)) |
| 939 | with ZipFile( |
| 940 | TEMP_ZIP, |
| 941 | "w", |
| 942 | compression=self.compression, |
| 943 | strict_timestamps=False |
| 944 | ) as z: |
| 945 | z.write(os_helper.TESTFN, "data1") |
| 946 | z.writestr( |
| 947 | ZipInfo("module.py", (1980, 1, 1, 0, 0, 0)), test_src |
| 948 | ) |
| 949 | z.write(os_helper.TESTFN, "data2") |
| 950 | |
| 951 | # This "works" but relies on the zip format having a non-empty |
| 952 | # final page due to the trailing central directory to wind up with |
| 953 | # the correct length file. |
| 954 | def make_sparse_zip_parts(name): |
| 955 | empty_page = b"\0" * 4096 |
| 956 | with open(name, "rb") as f: |
| 957 | part = None |
| 958 | try: |
| 959 | while True: |
| 960 | offset = f.tell() |
nothing calls this directly
no test coverage detected