File-like object for reading an archive member. Is returned by ZipFile.open().
| 945 | |
| 946 | |
| 947 | class ZipExtFile(io.BufferedIOBase): |
| 948 | """File-like object for reading an archive member. |
| 949 | Is returned by ZipFile.open(). |
| 950 | """ |
| 951 | |
| 952 | # Max size supported by decompressor. |
| 953 | MAX_N = (1 << 31) - 1 |
| 954 | |
| 955 | # Read from compressed files in 4k blocks. |
| 956 | MIN_READ_SIZE = 4096 |
| 957 | |
| 958 | # Chunk size to read during seek |
| 959 | MAX_SEEK_READ = 1 << 24 |
| 960 | |
| 961 | def __init__(self, fileobj, mode, zipinfo, pwd=None, |
| 962 | close_fileobj=False): |
| 963 | self._fileobj = fileobj |
| 964 | self._pwd = pwd |
| 965 | self._close_fileobj = close_fileobj |
| 966 | |
| 967 | self._compress_type = zipinfo.compress_type |
| 968 | self._compress_left = zipinfo.compress_size |
| 969 | self._left = zipinfo.file_size |
| 970 | |
| 971 | self._decompressor = _get_decompressor(self._compress_type) |
| 972 | |
| 973 | self._eof = False |
| 974 | self._readbuffer = b'' |
| 975 | self._offset = 0 |
| 976 | |
| 977 | self.newlines = None |
| 978 | |
| 979 | self.mode = mode |
| 980 | self.name = zipinfo.filename |
| 981 | |
| 982 | if hasattr(zipinfo, 'CRC'): |
| 983 | self._expected_crc = zipinfo.CRC |
| 984 | self._running_crc = crc32(b'') |
| 985 | else: |
| 986 | self._expected_crc = None |
| 987 | |
| 988 | self._seekable = False |
| 989 | try: |
| 990 | if fileobj.seekable(): |
| 991 | self._orig_compress_start = fileobj.tell() |
| 992 | self._orig_compress_size = zipinfo.compress_size |
| 993 | self._orig_file_size = zipinfo.file_size |
| 994 | self._orig_start_crc = self._running_crc |
| 995 | self._orig_crc = self._expected_crc |
| 996 | self._seekable = True |
| 997 | except AttributeError: |
| 998 | pass |
| 999 | |
| 1000 | self._decrypter = None |
| 1001 | if pwd: |
| 1002 | if zipinfo.flag_bits & _MASK_USE_DATA_DESCRIPTOR: |
| 1003 | # compare against the file type from extended local headers |
| 1004 | check_byte = (zipinfo._raw_time >> 8) & 0xff |
no outgoing calls
no test coverage detected
searching dependent graphs…