(file_path_or_obj: Union[str, Path, bytes, BinaryIO])
| 189 | |
| 190 | |
| 191 | def get_file_size(file_path_or_obj: Union[str, Path, bytes, BinaryIO]) -> int: |
| 192 | if isinstance(file_path_or_obj, (str, Path)): |
| 193 | file_path = Path(file_path_or_obj) |
| 194 | return file_path.stat().st_size |
| 195 | elif isinstance(file_path_or_obj, bytes): |
| 196 | return len(file_path_or_obj) |
| 197 | elif isinstance(file_path_or_obj, io.BufferedIOBase): |
| 198 | current_position = file_path_or_obj.tell() |
| 199 | file_path_or_obj.seek(0, os.SEEK_END) |
| 200 | size = file_path_or_obj.tell() |
| 201 | file_path_or_obj.seek(current_position) |
| 202 | return size |
| 203 | else: |
| 204 | raise TypeError( |
| 205 | 'Unsupported type: must be string, Path, bytes, or io.BufferedIOBase' |
| 206 | ) |
| 207 | |
| 208 | |
| 209 | def get_file_hash( |
no test coverage detected
searching dependent graphs…