Question

How do I download only a little part of a big file in Delphi? (like Download Manager)

For example, suppose I want to get the first 300 bytes of a 100MB text file over HTTP.

Was it helpful?

Solution

getting the first 300 bytes of a 100MB file.

Using WinInet library you can specify in the parameters how many bytes from the beginning of file do you actually need.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103.aspx


In case you would later want some chunk from in-between you may investigate 3rd-party libraries. With those libraries you need to set HTTP request Range header - https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

However the server may ignore this header. The library that you choose should check if server retirned Content-Range in HTTP Response and do something if it did not. Maybe download from very file start or maybe throw an exception. You should test those libraries and understand their behaviour in such a case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top