Open milahu opened 1 year ago
please add example on how to add actual files to an image
a naive attempt fails with ValueError: seek of closed file
ValueError: seek of closed file
input_paths = ["test.txt"] output_path = "test.iso" iso = pycdlib.PyCdlib() iso.new(udf="2.60") for input_path in input_paths: size = os.path.getsize(input_path) iso_path = "/" + input_path udf_path = "/" + input_path with open(input_path, "rb") as file_handle: iso.add_fp(file_handle, size, iso_path, udf_path=udf_path) iso.write(output_path) # ValueError: seek of closed file iso.close()
fixed version:
output_path = "test.iso" iso = pycdlib.PyCdlib() iso.new(udf="2.60") +file_handles = [] for input_path in input_paths: size = os.path.getsize(input_path) iso_path = "/" + input_path udf_path = "/" + input_path - with open(input_path, "rb") as file_handle: - iso.add_fp(file_handle, size, iso_path, udf_path=udf_path) + file_handle = open(input_path, "rb") + iso.add_fp(file_handle, size, iso_path, udf_path=udf_path) + file_handles.append(file_handle) iso.write(output_path) iso.close() +for file_handle in file_handles: + file_handle.close()
input_paths = ["test.txt"] output_path = "test.iso" iso = pycdlib.PyCdlib() iso.new(udf="2.60") file_handles = [] for input_path in input_paths: size = os.path.getsize(input_path) iso_path = "/" + input_path udf_path = "/" + input_path file_handle = open(input_path, "rb") iso.add_fp(file_handle, size, iso_path, udf_path=udf_path) file_handles.append(file_handle) iso.write(output_path) iso.close() for file_handle in file_handles: file_handle.close()
please add example on how to add actual files to an image
a naive attempt fails with
ValueError: seek of closed file
fixed version: