@@ -123,16 +123,22 @@ def headers_for_direct_upload(key, content_type:, checksum:, filename: nil, disp
123123    def  compose ( source_keys ,  destination_key ,  filename : nil ,  content_type : nil ,  disposition : nil ,  custom_metadata : { } ) 
124124      content_disposition  =  content_disposition_with ( type : disposition ,  filename : filename )  if  disposition  && filename 
125125
126-       client . create_append_blob ( 
127-         destination_key , 
128-         content_type : content_type , 
129-         content_disposition : content_disposition , 
130-         metadata : custom_metadata , 
131-       ) 
132- 
133-       source_keys . each  do  |source_key |
134-         stream ( source_key )  do  |chunk |
135-           client . append_blob_block ( destination_key ,  chunk ) 
126+       # use copy_blob operation if composing a new blob from a single existing blob 
127+       # and that single blob is <= 256 MiB which is the upper limit for copy_blob operation 
128+       if  source_keys . length  == 1  && client . get_blob_properties ( source_keys [ 0 ] ) . size  <= 256 . megabytes 
129+         client . copy_blob ( destination_key ,  source_keys [ 0 ] ,  metadata : custom_metadata ) 
130+       else 
131+         client . create_append_blob ( 
132+           destination_key , 
133+           content_type : content_type , 
134+           content_disposition : content_disposition , 
135+           metadata : custom_metadata , 
136+         ) 
137+ 
138+         source_keys . each  do  |source_key |
139+           stream ( source_key )  do  |chunk |
140+             client . append_blob_block ( destination_key ,  chunk ) 
141+           end 
136142        end 
137143      end 
138144    end 
0 commit comments