def get_data_dir(): res = os.getenv('DRQA_DATA') if res: return res if os.name == 'nt': path = WindowsPath(__file__) else: path = PosixPath(__file__) return os.path.join(path.absolute().parents[1].as_posix(), 'data')
def actually_send(s: socket.socket, file: pathlib.WindowsPath): size = file.stat().st_size progress = get_progress_bar( f'{Fore.GREEN}Sending {file.name}{Fore.RESET}', size) with open(str(file.absolute()), 'rb') as f: for _ in progress: bytes_read = f.read(BUFFER_SIZE) if not bytes_read: break s.sendall(bytes_read) progress.update(len(bytes_read)) s.close()