How to load a file into chunks with many themes

I need to download a file from a website using different streams and loading several sections of the file at once, I know that I can use the Webclient.downloadfile method, but it does not support downloading the file to pieces. If you could point to a tutorial or give me an idea of ​​how to do this, I would appreciate it. Thanks!

+4
source share
4 answers

To answer Rex's answer, there is no reliable way to find out. Some web servers will give you the length of the content, or some will return -1 for the length. Annoying, I know ..

It is best to specify a fixed range and use some heuristics or analysis to determine the estimated length of your pieces over time.

You will also want to look at this similar SO question on Multipage Download in C # .

0
source

The server on the other end, the one that provides the file, should also support loading in chunks. He would need to somehow indicate at what position of the byte in the file you want to start, instead of starting from the first and sending until the client stops receiving them or reaches the end of the file.

Assuming the server supports this, they will provide some kind of documentation on how to use it, and you will definitely find help turning it into code.

+3
source

The WebClient object has a Headers property, which should allow you to specify a Range header to request only part of the file.

0
source

There are many, but if you upload, say, a gigantic text file, you can split it into many files on the server and return the addresses of each client (or use the file name of the agreement and just indicate how many partitions are there), and the client, in turn, He could expand the streams to load each of the partitions, which he could then restore to one large file.

I'm not sure about your use case, but this particular scenario is unlikely to make things go faster if it is an idea.

0
source

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


All Articles