-2

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Sky
  • 4,244
  • 7
  • 54
  • 83
  • http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103.aspx – Arioch 'The Jul 11 '13 at 15:35
  • 1
    The answer to the question you asked is "Yes, it is possible.". There's no other information needed to answer it. Since that's probably not useful to you, you should perhaps [edit] your question to make it a little more clear what you're asking. :-) What, for instance, is "server"? And what exactly does it "support" (ftp, http, something else)? – Ken White Jul 11 '13 at 15:36
  • http://synapse.ararat.cz/doc/help/httpsend.THTTPSend.html#RangeStart – Arioch 'The Jul 11 '13 at 15:37
  • 1
    http://www.indyproject.org/docsite/html/TIdRequestHeaderInfo_Range.html – Arioch 'The Jul 11 '13 at 15:40
  • 1
    I'm rolling back your last edit, because it's an entirely new question. Once you've received an answer to the question asked, it's improper to then edit to ask a totally different question. Post a new one instead, and ask there. This is not a site for evolving your code in your question. Ask a question, get an answer. Accept one if it helps you. If you then have a new question, post a new question. – Ken White Jul 11 '13 at 17:30

1 Answers1

3

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.

Arioch 'The
  • 15,799
  • 35
  • 62