Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: seek of closed file - add actual files to an image #114

Open
milahu opened this issue Apr 26, 2023 · 0 comments
Open

ValueError: seek of closed file - add actual files to an image #114

milahu opened this issue Apr 26, 2023 · 0 comments

Comments

@milahu
Copy link

milahu commented Apr 26, 2023

please add example on how to add actual files to an image

a naive attempt fails with 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant