c# - FileStream.copyTo(Net.ConnectStream) what happens intern? -


this code works fine. question happens within net.connectionstream when use copyto() method?

system.net.httpwebrequest request  using (filestream filestream = new filestream("c:\\myfile.txt") {                             using (stream str = request.getrequeststream())     {                             filestream.copyto(str);     } } 

more specific: happens data?
1. write memory , upload then? (what's big files?) 2. write network directly? (how work?)

thanks answers

it creates byte[] buffer , calls read on source , write on destination until source doesn't have anymore data.

so when doing big files don't need concerned running out of memory because you'll allocate as buffer size, 81920 bytes default.

here's actual implementation -

public void copyto(stream destination) {     // ... bunch of argument validation stuff (omitted)     this.internalcopyto(destination, 81920); }  private void internalcopyto(stream destination, int buffersize) {     byte[] array = new byte[buffersize];     int count;     while ((count = this.read(array, 0, array.length)) != 0)     {         destination.write(array, 0, count);     } } 

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 -