Advertisement
Guest User

Untitled

a guest
Aug 14th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.04 KB | None | 0 0
  1. procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
  2.   OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
  3. var
  4.   strm: TZStreamRec;
  5.   P: Pointer;
  6.   BufInc: Integer;
  7. begin
  8.   FillChar(strm, sizeof(strm), 0);
  9.   BufInc := (InBytes + 255) and not 255;
  10.   if OutEstimate = 0 then
  11.     OutBytes := BufInc
  12.   else
  13.     OutBytes := OutEstimate;
  14.   GetMem(OutBuf, OutBytes);
  15.   try
  16.     strm.next_in := InBuf;
  17.     strm.avail_in := InBytes;
  18.     strm.next_out := OutBuf;
  19.     strm.avail_out := OutBytes;
  20.     inflateInit_(strm, zlib_version, sizeof(strm));
  21.     try
  22.       while inflate(strm, Z_FINISH) <> Z_STREAM_END do
  23.       begin
  24.         P := OutBuf;
  25.         Inc(OutBytes, BufInc);
  26.         ReallocMem(OutBuf, OutBytes);
  27.         strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
  28.         strm.avail_out := BufInc;
  29.       end;
  30.     finally
  31.       inflateEnd(strm);
  32.     end;
  33.     ReallocMem(OutBuf, strm.total_out);
  34.     OutBytes := strm.total_out;
  35.   except
  36.     FreeMem(OutBuf);
  37.     raise
  38.   end;
  39. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement