@@ -671,8 +671,8 @@ def sign_file(
671671 # Create a builder from the manifest
672672 builder = Builder (manifest )
673673
674- # Open source and destination files
675- with open (source_path , 'rb' ) as source_file , open ( dest_path , 'wb' ) as dest_file :
674+ # Open source file and create BytesIO for destination
675+ with open (source_path , 'rb' ) as source_file :
676676 # Get the MIME type from the file extension
677677 mime_type = mimetypes .guess_type (str (source_path ))[0 ]
678678 if not mime_type :
@@ -682,23 +682,34 @@ def sign_file(
682682 if return_manifest_as_bytes :
683683 # Convert Python streams to Stream objects for internal signing
684684 source_stream = Stream (source_file )
685- dest_stream = Stream (dest_file )
685+ dest_stream = Stream (io . BytesIO ( bytearray ()) )
686686
687687 # Use the builder's internal signing logic to get manifest
688688 # bytes
689689 manifest_bytes = builder ._sign_internal (
690690 signer , mime_type , source_stream , dest_stream )
691691
692+ # Write the signed content from BytesIO to the destination file
693+ dest_stream ._file .seek (0 ) # Reset to beginning of stream
694+ with open (dest_path , 'wb' ) as dest_file :
695+ dest_file .write (dest_stream ._file .getvalue ())
696+
692697 return manifest_bytes
693698 else :
694- # Sign the file using the builder
699+ # Sign the file using the builder with BytesIO destination
700+ dest_stream = io .BytesIO (bytearray ())
695701 builder .sign (
696702 signer = signer ,
697703 format = mime_type ,
698704 source = source_file ,
699- dest = dest_file
705+ dest = dest_stream
700706 )
701707
708+ # Write the signed content from BytesIO to the destination file
709+ dest_stream .seek (0 ) # Reset to beginning of stream
710+ with open (dest_path , 'wb' ) as dest_file :
711+ dest_file .write (dest_stream .getvalue ())
712+
702713 # Read the signed manifest from the destination file
703714 with Reader (dest_path ) as reader :
704715 return reader .json ()
0 commit comments