Download 4GB file from .net application

My requirement is to download a 4 GB file from a .net application and download the same file from a .net application. We were able to download and upload a 4 gigabyte file using the .net application.

So, in order to upload a 4 GB file, we split the 4 GB file, and when loading, we combined the file using FileStream objects in C #.

Now I can save the file on the client machine when I click the Download button from my .net application. But when saving file stream objects, it writes a byte byte and saves the file on the user's machine. It takes more time to save the file on the client machine. Even for a 100 MB file, you need to save it for about 2 hours. If I save 4 GB, it will take a long time.

What is the best way to improve speed? Are there any Filestream objects available? please help me download a 4GB file from Networkshare using the .net application. if you find any other solution for uplaod and upload the 4gb file to .net, that will be fine.

I cannot use asp.net to download code to download a 4 GB file. So we followed the principle of separation. Please help me improve the speed of the code below. I am using Asp.net 3.5 application.

my code on boot:

FileStream foption = new FileStream(strFileName, FileMode.Open); len = foption.Length; eachSize = (int)Math.Ceiling((double)len / x); foption.Close(); FileStream inFile = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.Read); for (int i = 0; i < x; i++) { FileStream outFile = new FileStream(strDir + "\\" + i + ".zip", FileMode.OpenOrCreate, FileAccess.Write); int data = 0; byte[] buffer = new byte[eachSize]; if ((data = inFile.Read(buffer, 0, eachSize)) > 0) { outFile.Write(buffer, 0, data); } outFile.Close(); } 

my code on boot

 FileStream outFile = new FileStream("\\\\" + clientIPAddress + "\\upload\\output.zip", FileMode.OpenOrCreate, FileAccess.Write); for (int i = 0; i < 10; i++) { int data = 0; byte[] buffer = new byte[4096]; FileStream inFile = new FileStream(strMediaPath + "\\" + i + ".zip", FileMode.OpenOrCreate, FileAccess.Read); while ((data = inFile.Read(buffer, 0, 4096)) > 0) { outFile.Write(buffer, 0, data); } inFile.Close(); } outFile.Close(); 

Thanks Edwin

+4
source share
1 answer

I see no reason to split the file in the first place, all you do is guarantee another copy operation of the slow disk at the end of the transfer to merge the file.

Do not split the file will require that i in the first block of code be long instead of int . 32-bit integers will go 2 GB from the moment they are signed.

Finally, your buffer should be LOT larger. 4k is what my first TRS-80 computer had in it, that tiny piece of data to read and write inside a loop. Try something more substantial, like 1 MB.

+1
source

Source: https://habr.com/ru/post/1401110/


All Articles