c# - Are there any difference in using File.Copy to move a file or to write a stream to the location? -


i refactoring code have question use few comments on.

the original code download file stream. writes stream file in temp directory before using file.copy overwrite existing file in production directory.

are there benefits writing temp dir first , using file.copy in contrast writing stream production directory right away?

one reason file.copy faster writing stream, , reducing chance reading file while being written. can happen? else should have in mind. considering factoring out temp directory.

memorystream stream = new memorystream(); ....download , valiate stream.... using (stream sourcefilestream = stream) {     using (filestream targetfilestream = new filestream(temppath, filemode.createnew))     {         const int buffersize = 8192;         byte[] buffer = new byte[buffersize];         while (true)         {               int read = sourcefilestream.read(buffer, 0, buffersize);               targetfilestream.write(buffer, 0, read);                if (read == 0)                   break;         }     }  } file.copy(temppath, destination, true); 

in contrast writing stream destination.

this code had, use sourcefilestream.copytoasync(targetfilestream);

file.copy encapsulates usage of streams, etc. no difference @ all.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -