GZip library lazarus / 31-LCL ---------------------------------------------------------------------- geraldholdsworth · 2021-05-28 13:19 Hi all, I have been using the GZip library (found in ZStream) to decompress GZip files. Most of the files I have come across only appear to have the single block in the file, so this works (the basis for I found on this forum): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function Inflate(Source: String): TDIByteArray;var GZ     : TGZFileStream; chunk  : TDIByteArray; cnt, i, buflen : Integer;const  ChunkSize=4096; //4K chunksbegin //Initialise the variables Result:=nil; chunk:=nil; //Open the stream try  GZ:=TGZFileStream.Create(Source,gzOpenRead);  //This is our length counter  buflen:=0;  //We'll be reading it in chunks  SetLength(chunk,ChunkSize);  repeat   //Read in the next chunk   cnt:=GZ.Read(chunk[0],ChunkSize);   //Extend the buffer accordingly   SetLength(Result,buflen+cnt);   //Copy the chunk into the buffer   for i:=0 to cnt-1 do Result[buflen+i]:=chunk[i];   //Increase the buffer length counter   inc(buflen,cnt);   //Until we are done  until cnt1 then begin  //Add the file end to the end of the block pointers  SetLength(blockptrs,Length(blockptrs)+1);  blockptrs[Length(blockptrs)-1]:=Length(buffer);  //Set up the container for the inflated file  SetLength(Result,0);  //Get a temporary filename  fn:=GetTempDir+ExtractFileName(filename);  //Iterate through the pointers  for i:=0 to Length(blockptrs)-2 do  begin   //Create the temporary file and write the block to it   try  F:=TFileStream.Create(fn,fmCreate);    F.Write(buffer[blockptrs[i]],blockptrs[i+1]-blockptrs[i]);   except   end;   F.Free;   //Inflate the block   inflated:=L_Inflate(fn);   old:=Length(Result); //Previous length of the inflated file   //Increase the inflated file buffer to accomodate   SetLength(Result,Length(Result)+Length(inflated));   //Move the inflated data across   for ptr:=0 to Length(inflated)-1 do Result[old+ptr]:=inflated[ptr];  end;  //Delete the temporary file  if FileExists(fn) then DeleteFile(fn); end; //If just the one block, then don't bother splitting if Length(blockptrs)=1 then Result:=L_Inflate(filename); //If there are no blocks, then just return the entire file if Length(blockptrs)=0 then Result:=buffer;end; As you can see, the original code is now a sub-function of this one. Incidentally, don't forget: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ZStream,StrUtils,SysUtils,Classes(I think that's all you need) Just thought I'd 'park' this here for anyone else experiencing the same issue, or if anyone wants to improve on it. Cheers, Gerald. ---------------------------------------------------------------------- ChrisR · 2021-05-28 14:04 I believe this issue is related to   https://bugs.freepascal.org/view.php?id=36822 Your solution may help others who encounter this. ---------------------------------------------------------------------- geraldholdsworth · 2021-05-29 11:47 It certainly does sound like it. Although I never got an exception after the second block was inflated, but that could've been handled by the try...except block in the original code.