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
Post a Comment