summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 00765fa)
raw | patch | inline | side by side (parent: 00765fa)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 18 Apr 2016 15:20:40 +0000 (18:20 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 18 Apr 2016 15:30:09 +0000 (18:30 +0300) |
src/shared/xstreams.pas | patch | blob | history |
index 5e026e19e6ef9b196087a62e7d5f59d762fd654a..e7e70e70ef79769651fb825edf1243e1f243ef3d 100644 (file)
--- a/src/shared/xstreams.pas
+++ b/src/shared/xstreams.pas
function TUnZStream.readBuf (var buffer; count: LongInt): LongInt;
var
err: Integer;
- lastavail: LongInt;
+ sz: LongInt;
begin
- fZlibSt.next_out := @buffer;
- fZlibSt.avail_out := count;
- lastavail := count;
- while fZlibSt.avail_out <> 0 do
+ result := 0;
+ if count > 0 then
begin
- if fZlibSt.avail_in = 0 then
+ fZlibSt.next_out := @buffer;
+ fZlibSt.avail_out := count;
+ sz := fZlibSt.avail_out;
+ while fZlibSt.avail_out > 0 do
begin
- // refill the buffer
- fZlibSt.next_in := fBuffer;
- fZlibSt.avail_in := fSrcSt.read(Fbuffer^, ZBufSize);
- //Inc(compressed_read, fZlibSt.avail_in);
- Inc(fPos, lastavail-fZlibSt.avail_out);
- lastavail := fZlibSt.avail_out;
+ if fZlibSt.avail_in = 0 then
+ begin
+ // refill the buffer
+ fZlibSt.next_in := fBuffer;
+ fZlibSt.avail_in := fSrcSt.read(Fbuffer^, ZBufSize);
+ end;
+ err := inflate(fZlibSt, Z_NO_FLUSH);
+ if (err <> Z_OK) and (err <> Z_STREAM_END) then raise XStreamError.Create(zerror(err));
+ Inc(result, sz-fZlibSt.avail_out);
+ Inc(fPos, sz-fZlibSt.avail_out);
+ sz := fZlibSt.avail_out;
+ if err = Z_STREAM_END then begin fSize := fPos; break; end;
end;
- err := inflate(fZlibSt, Z_NO_FLUSH);
- if err = Z_STREAM_END then fSize := fPos; break;
- if err <> Z_OK then raise XStreamError.Create(zerror(err));
end;
- //if err = Z_STREAM_END then Dec(compressed_read, fZlibSt.avail_in);
- Inc(fPos, lastavail-fZlibSt.avail_out);
- result := count-fZlibSt.avail_out;
end;