Hello,

I have overloaded the function with different parameters as there was
already some different overloaded versions of it but as you guessed forgot
to mark the changes. Here it is:

procedure ZlibCompressStreamEx(InStream, OutStream: TStream;
            NumLevel: Integer; StreamType : TZStreamType; offset : int64;
length : int64); // May 3, 2011 Fastream.com
const
  //64 KB buffer
  BufSize = 65536;
var
  strm   : z_stream;
  InBuf, OutBuf : PAnsiChar;
  UseInBuf, UseOutBuf : boolean;
  LastOutCount : integer;
  Finished : boolean;
  Cancel: boolean;
  Totcount: int64;
  toRead: integer; // May 3, 2011 Fastream.com
  exitLoop: boolean; // May 3, 2011 Fastream.com

  procedure WriteOut;
  begin
    if UseOutBuf then
    begin
      if LastOutCount > 0 then OutStream.Write(OutBuf^, LastOutCount -
strm.avail_out);
      strm.avail_out := BufSize;
      strm.next_out  := OutBuf;
    end
    else
    begin
      if (strm.avail_out = 0) then ExpandStream(OutStream, OutStream.Size +
BufSize);
      OutStream.Seek(LastOutCount - strm.avail_out, soFromCurrent);
      strm.next_out  := DMAOfStream(OutStream, strm.avail_out);
      //because we can't really know how much resize is increasing!
    end;
    LastOutCount := strm.avail_out;
  end;
begin
  FillChar(strm, sizeof(strm), 0);
  InBuf          := nil;
  OutBuf         := nil;
  LastOutCount   := 0;
  Totcount       := 0;
  exitLoop       := false;
  InStream.Seek(offset, soFromBeginning);
  strm.next_in   := DMAOfStream(InStream, strm.avail_in);
  UseInBuf := strm.next_in = nil;
  if UseInBuf then
    GetMem(InBuf, BufSize);
  UseOutBuf := not (CanResizeDMAStream(OutStream));
  if UseOutBuf then GetMem(OutBuf, BufSize);
  ZlibCCheck(deflateInitEx(strm, NumLevel, StreamType));          { V6.01 }
  try
    repeat
      if strm.avail_in = 0 then
      begin
        if UseInBuf then
        begin
          toRead := BufSize; // May 3, 2011 Fastream.com
          if totCount + BufSize > length then // May 3, 2011 Fastream.com
          begin
            toRead := length - totCount;
            exitLoop := true;
          end;
          strm.avail_in := InStream.Read(InBuf^, toRead);
          strm.next_in  := InBuf;
        end;
        if strm.avail_in = 0 then break;
        if exitLoop then break;
      end;
      if strm.avail_out = 0 then WriteOut;
      ZlibCCheck(deflate(strm, Z_NO_FLUSH));
      inc(Totcount, strm.avail_in);    { V6.01 keep track of data read } //
May 3, 2011 Fastream.com
    until false;
    repeat
      if strm.avail_out = 0 then WriteOut;
      Finished := ZlibCCheck(deflate(strm, Z_FINISH)) = Z_STREAM_END;
      WriteOut;
    until Finished;
    if not UseOutBuf then
    begin
      //truncate when using direct output
      OutStream.Size := OutStream.Position;
    end;
    //adjust position of the input stream
    if UseInBuf then
      //seek back when unused data
      InStream.Seek(-strm.avail_in, soFromCurrent)
    else
      //simple seek
      InStream.Seek(strm.total_in, soFromCurrent);
    ZlibCCheck(deflateEnd(strm));
  finally
    if InBuf <> nil then FreeMem(InBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;

Regards,

SZ

On Tue, May 3, 2011 at 14:13, Angus Robertson - Magenta Systems Ltd <
an...@magsys.co.uk> wrote:

> > Here is a function I
> > wrote for ICSZlibHigh which takes that into consideration:
> >
> > procedure ZlibCompressStreamEx
>
> There is already a procedure of exactly that name in OverbyteIcsZlibHigh,
> although you appeared to have copied an old version or hacked it, so why
> do need to add it again?
>
> Or are you saying you have modified it in some way, without identifying
> the changes?
>
> Angus
>
> --
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be
>
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to