Read and save part of file stream via IdHTTP

Viewed 1264

I want to download a file from a HTTP server via a file stream and only read (and save to a file) the first few lines, say 100. After reading the first 100 lines the file stream must end: so I do NOT want to download or read the entire file.

Below you can find what I have so far. The website is just an example. Can someone guide me in the right direction?

const
  myURL = https://graphical.weather.gov/xml/DWMLgen/schema/latest_DWML.txt
var
  fs: TMemoryStream;
  http: TIdHTTP; 
begin
  fs := TMemoryStream.Create;
  http := TIdHTTP.Create(nil);
  try
    fs.Position := 0;
    http.Get(myURL, fs);
    fs.SaveToFile('test.xml');
  finally
    fs.Free;
    http.free
  end;
end;
1 Answers
Related