summaryrefslogtreecommitdiff
path: root/plugins/Utils.pas/zwrapper.pas
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-10-08 18:43:29 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-10-08 18:43:29 +0000
commit864081102a5f252415f41950b3039a896b4ae9c5 (patch)
treec6b764651e9dd1f8f53b98eab05f16ba4a492a79 /plugins/Utils.pas/zwrapper.pas
parentdb5149b48346c417e18add5702a9dfe7f6e28dd0 (diff)
Awkwars's plugins - welcome to our trunk
git-svn-id: http://svn.miranda-ng.org/main/trunk@1822 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Utils.pas/zwrapper.pas')
-rw-r--r--plugins/Utils.pas/zwrapper.pas58
1 files changed, 58 insertions, 0 deletions
diff --git a/plugins/Utils.pas/zwrapper.pas b/plugins/Utils.pas/zwrapper.pas
new file mode 100644
index 0000000000..7ccffafb14
--- /dev/null
+++ b/plugins/Utils.pas/zwrapper.pas
@@ -0,0 +1,58 @@
+unit zwrapper;
+
+interface
+
+function ZDecompressBuf(const inBuffer: Pointer; inSize: Integer; out outBuffer: Pointer; out outSize: Integer; outEstimate: Integer): Integer;
+
+implementation
+
+uses zlib;
+
+function ZDecompressBuf(const inBuffer: Pointer; inSize: Integer; out outBuffer: Pointer; out outSize: Integer; outEstimate: Integer): Integer;
+var
+ zstream : TZStreamRec;
+ delta : Integer;
+begin
+ FillChar(zstream, SizeOf(TZStreamRec), 0);
+
+ delta := (inSize + 255) and not 255;
+
+ if outEstimate = 0 then outSize := delta
+ else outSize := outEstimate;
+ Result := Z_OK;
+ GetMem(outBuffer, outSize);
+ try
+ zstream.next_in := inBuffer;
+ zstream.avail_in := inSize;
+ zstream.next_out := outBuffer;
+ zstream.avail_out := outSize;
+
+ Result := InflateInit(zstream);
+ if Result < 0 then Exit;
+
+ try
+ Result := inflate(zstream, Z_NO_FLUSH);
+ if Result < 0 then Exit;
+
+ while (Result <> Z_STREAM_END) do begin
+ Inc(outSize, delta);
+ ReallocMem(outBuffer, outSize);
+
+ zstream.next_out := {$IFDEF FPC}PBytef{$ENDIF}(pByte(outBuffer) + zstream.total_out);
+ zstream.avail_out := delta;
+ Result := inflate(zstream, Z_NO_FLUSH);
+ if Result < 0 then Exit;
+ end;
+ finally
+ inflateEnd(zstream);
+ end;
+
+ ReallocMem(outBuffer, zstream.total_out);
+ outSize := zstream.total_out;
+
+ finally
+ if Result < 0 then FreeMem(outBuffer);
+ end;
+end;
+
+end. \ No newline at end of file