Hello,

Somehow Delphi could not link with two functions so here is my solution:

procedure ZlibCompressStreamEx( InStream, OutStream: TStream;
                                NumLevel: Integer;
                                StreamType : TZStreamType;
                                UseDirectOut: boolean;
                                Sender: TObject;
                                ProgCallback: TZlibProg;
                                offset : int64 = 0;
                                length : int64 = -1); overload;
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;
  exitLoop: boolean;
  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
  InStream.Seek(offset, soBeginning); // fastream.com May 4 2011
  exitLoop := false; // fastream.com May 4 2011
  if length = -1 then // fastream.com May 4 2011
      length := InStream.Size - offset; // fastream.com May 4 2011
  FillChar(strm, sizeof(strm), 0);
  InBuf          := nil;
  OutBuf         := nil;
  LastOutCount   := 0;
  Totcount       := 0;
  strm.next_in   := DMAOfStream(InStream, strm.avail_in);
  UseInBuf := strm.next_in = nil;
  if UseInBuf then
    GetMem(InBuf, BufSize);
  UseOutBuf := not (UseDirectOut and 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;  // fastream.com May 4 2011
          if totCount + BufSize > length then  // fastream.com May 4 2011
          begin
            toRead := length - totCount;  // fastream.com May 4 2011
            exitLoop := true;  // fastream.com May 4 2011
          end;
          strm.avail_in := InStream.Read(InBuf^, toRead); //
fastream.comMay 4 2011
          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));
      if Assigned(ProgCallback) then begin   { V6.01 tell user }
        Cancel := false;
        ProgCallback(Sender, TotCount, Cancel);
        if Cancel then break;
      end;
      inc(Totcount, strm.avail_in); // fastream.com May 4 2011
    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;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*   V6.01 }
procedure ZlibCompressStreamEx(InStream, OutStream: TStream; Level:
TCompressionLevel; StreamType: TZStreamType; UseDirectOut: boolean);
overload; // fastream.com May 4 2011
begin
    ZlibCompressStreamEx(InStream, OutStream, Levels[Level], StreamType,
                                                     UseDirectOut, Nil, Nil,
0, -1);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
procedure ZlibCompressStreamEx( InStream, OutStream: TStream; //
fastream.com May 4 2011
                                NumLevel: Integer;
                                StreamType : TZStreamType;
                                UseDirectOut: boolean;
                                Sender: TObject;
                                ProgCallback: TZlibProg); overload;
begin
    ZlibCompressStreamEx(       InStream, OutStream,
                                NumLevel,
                                StreamType,
                                UseDirectOut,
                                Sender,
                                ProgCallback,
                                0,
                                -1);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}

Please add this to SVN.

Thanks,

SubZero

On Wed, May 4, 2011 at 09:05, Francois PIETTE <francois.pie...@skynet.be>wrote:

> Is there any way to set a default value to a parameter in Delphi? In C++
>> it's like (in .h or .hpp header file)
>>
>> void function(int param = value);
>> so the function can now be called as function() without the requirement of
>> expicit param specification.
>>
>
> Same in Delphi.
>
> --
> francois.pie...@overbyte.be
> 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
>
--
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