@@ -344,17 +344,18 @@ def reset_for_each_execution(each_option):
344344 return api , format_option
345345
346346
347+ def generate_ion_file_with_format (file , binary ):
348+ cf = open ("converted_file" , "wb" )
349+ with open (file , "br" ) as fp :
350+ ion .dump (ion .load (fp , single_value = False ), cf , binary = binary )
351+ return cf .name
352+
353+
347354def convert_file_to_desired_format (f , file ):
348355 if f == Format .ION_BINARY .value :
349- cf = open ("converted_file" , "wb" )
350- with open (file , "br" ) as fp :
351- ion .dump (ion .load (fp , single_value = False ), cf , binary = True )
352- return cf .name
356+ return generate_ion_file_with_format (file , True )
353357 elif f == Format .ION_TEXT .value :
354- cf = open ("converted_file" , "wb" )
355- with open (file , "br" ) as fp :
356- ion .dump (ion .load (fp , single_value = False ), cf , binary = False )
357- return cf .name
358+ return generate_ion_file_with_format (file , False )
358359 else :
359360 raise Exception ('Failed to convert file due to unknown format.' )
360361
0 commit comments