def test_decodability(args): e_correction = args[0] repair_symbols = int(args[1]) cmp_str = b"AAAAAACHZACHEFAKLF(24z98" assert get_error_correction_decode(e_correction, repair_symbols)( get_error_correction_encode(e_correction, repair_symbols)(cmp_str)) == cmp_str
metavar="file", type=str, help="the file / folder to Decode") parser.add_argument( "--error_correction", metavar="error_correction", type=str, required=False, default="nocode", help="Error Correction Method to use; possible values: \ nocode, crc, reedsolomon (default=nocode)") parser.add_argument( "--repair_symbols", metavar="repair_symbols", type=int, required=False, default=2, help="number of repair symbols for ReedSolomon (default=2)") args = parser.parse_args() filename = args.filename e_correction_str = args.error_correction norepair_symbols = args.repair_symbols error_correction = get_error_correction_decode(e_correction_str, norepair_symbols) print("Zu dekodierende Datei / Ordner: " + str(filename)) demo = demo_decode() demo.decode(filename, error_correction=error_correction) except Exception as e: print(e) # input("Press Enter to continue ...")
static_number_of_chunks=number_of_chunks, read_all=read_all) print("[1/2] Approximation Decode") _internal(x) x.saveDecodedFile(null_is_terminator=null_is_terminator, print_to_output=PRINT_TO_OUTPUT) if __name__ == "__main__": try: parser = argparse.ArgumentParser() parser.add_argument( "filename", metavar="file", type=str, help="the file / folder to Decode" ) parser.add_argument("--error_correction", metavar="error_correction", type=str, required=False, default="nocode", help="Error Correction Method to use; possible values: \ nocode, crc, reedsolomon (default=nocode)") parser.add_argument("--repair_symbols", metavar="repair_symbols", type=int, required=False, default=2, help="number of repairsymbols for ReedSolomon (default=2)") args = parser.parse_args() _file = args.filename _repair_symbols = args.repair_symbols _error_correction = get_error_correction_decode(args.error_correction, _repair_symbols) print("Zu dekodierende Datei / Ordner: " + str(_file)) demo = demo_decode() demo.decode(_file, error_correction=_error_correction) # else: # print("Please add the file you want to Encode as an Argument") except Exception as e: raise e # input("Press Enter to continue ...")
def __decode(self, filename, decode_conf): self.warn_unknown_items(decode_conf) algorithm = decode_conf.get("algorithm") number_of_chunks = decode_conf.getint("number_of_chunks", None) e_correction = decode_conf.get("error_correction", "nocode") # optional repair_symbols = decode_conf.getint("repair_symbols", 2) # optional mode_1_bmp = decode_conf.getboolean("as_mode_1_bmp") # optional, bool number_of_splits = decode_conf.getint("number_of_splits", 0) # optional split_index_position = decode_conf.getint("split_index_position", "end") # optional split_index_length = decode_conf.getint( "split_index_length") # optional last_split_smaller = decode_conf.getboolean( "last_split_smaller") # optional, bool is_null_terminated = decode_conf.getboolean( "is_null_terminated") # optional, bool use_header_chunk = decode_conf.getboolean( "insert_header") # optional, bool id_len_format = decode_conf.get("id_len_format") # optional, str number_of_chunks_len_format = decode_conf.get( "number_of_chunks_len_format", "I") # optional, str packet_len_format = decode_conf.get("packet_len_format", "I") # optional, str crc_len_format = decode_conf.get("crc_len_format", "L") # optional, str read_all_packets = decode_conf.getboolean("read_all", False) distribution_cfg_str = decode_conf.get("distribution", "") # extract preconfig steps: if number_of_splits != 0: split_index_length = find_ceil_power_of_four(number_of_splits) last_split_folder = None if split_index_length != 0 and split_index_length is not None: if filename.lower().endswith("fasta"): folders, last_split_folder = fasta_cluster_and_remove_index( split_index_position, split_index_length, filename) else: folders, last_split_folder = cluster_and_remove_index( split_index_position, split_index_length, filename) # check if the number of folders is equal to the number_of_splits given by user ( if this is != 0 ) if number_of_splits > 0 and number_of_splits != len(folders): print( "[WARNING] Number of Splits given by user differs from number of splits found!" ) else: folders = [filename] error_correction = get_error_correction_decode(e_correction, repair_symbols) decoded_files = [] for f_file in folders: print("File / Folder to decode: " + str(f_file)) if algorithm.lower() == "ru10": demo = demo_raptor_decode() elif algorithm.lower() == "lt": demo = demo_lt_decode() elif algorithm.lower() == "online": demo = demo_online_decode() else: raise RuntimeError( "unsupported algorithm, this version supports: \"RU10\", \"Online\" and \"LT\"" ) self.coder = demo try: decoded_files.append( demo.decode( f_file, error_correction=error_correction, null_is_terminator=is_null_terminated, mode_1_bmp=mode_1_bmp, id_len_format=id_len_format, number_of_chunks_len_format=number_of_chunks_len_format, packet_len_format=packet_len_format, crc_len_format=crc_len_format, number_of_chunks=number_of_chunks + (-1 if f_file == last_split_folder and last_split_smaller else 0), use_header_chunk=use_header_chunk, read_all=read_all_packets, distribution_cfg_str=distribution_cfg_str)) except Exception as ex: raise ex if len(folders) > 1: merge_parts(decoded_files, remove_tmp_on_success=True)