def downloadDb(ip, port, clusterId, location): s = RCP.make_socket(ip, port) try: with open(location,'w+b') as db_file: RCP._prologue(clusterId, s) cmd = RCP._int_to(RCP._DOWNLOAD_DB | RCP._MAGIC) s.send(cmd) RCP.check_error_code(s) db_size = RCP._receive_int64(s) while (db_size > 0 ) : chunkSize = min(4*1024, db_size) chunk = RCP._receive_all(s, chunkSize) db_size -= len(chunk) db_file.write(chunk) finally: s.close()
def downloadDb(ip, port, clusterId, location): s = RCP.make_socket(ip, port) try: with open(location, 'w+b') as db_file: RCP._prologue(clusterId, s) cmd = RCP._int_to(RCP._DOWNLOAD_DB | RCP._MAGIC) s.send(cmd) RCP.check_error_code(s) db_size = RCP._receive_int64(s) while (db_size > 0): chunkSize = min(4 * 1024, db_size) chunk = RCP._receive_all(s, chunkSize) db_size -= len(chunk) db_file.write(chunk) finally: s.close()