Recent

Author Topic: Error in TdecompressionStream?  (Read 1262 times)

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 344
Re: Error in TdecompressionStream?
« Reply #15 on: September 25, 2023, 12:13:49 pm »
I'm not sure where TGZipDecompressionStream comes from? Not in my version of ZStream and perhaps that's my problem. Anyway, for someone else blocked where I am, this code removes the header from all the gz sources I've run into and means that the bytes can be read by TdecompressionStream:

Code: Pascal  [Select][+][-]
  1. function readZLibHeader(stream : TStream) : TBytes;
  2. var
  3.   b : TBytes;
  4.   p : int64;
  5.   i : integer;
  6. begin
  7.   b := StreamToBytes(stream);
  8.   if (length(b) < 10) or (b[0] <> $1F) or (b[1] <> $8B) then
  9.     result := b
  10.   else
  11.   begin
  12.     i := 10;
  13.     if ((b[3] and $08) > 0) then
  14.     begin
  15.       repeat
  16.         inc(i);
  17.       until (i = length(b)) or (b[i] = 0);
  18.       inc(i);
  19.     end;
  20.     if i >= length(b) then
  21.       result := b
  22.     else
  23.        result := copy(b, i, length(b)-i-8);
  24.   end;
  25. end;              
  26.  

Fibonacci

  • Full Member
  • ***
  • Posts: 222
  • #PDK
Re: Error in TdecompressionStream?
« Reply #16 on: September 25, 2023, 12:21:45 pm »
I'm not sure where TGZipDecompressionStream comes from? Not in my version of ZStream and perhaps that's my problem.

https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/paszlib/src/zstream.pp#L124

Grahame Grieve

  • Sr. Member
  • ****
  • Posts: 344
Re: Error in TdecompressionStream?
« Reply #17 on: September 25, 2023, 01:25:24 pm »
Thx. might be time to upgrade soon

 

TinyPortal © 2005-2018