program DTest;

uses Classes, SysUtils, DZLib;

const
  BufferSize = 4096;
  
type
  TTest = class
    InFile: TStream;
    OutFile: TStream;
    ZStream: TCustomZLibStream;
    Buffer: array[0..BufferSize-1] of Byte;
    procedure Expand;
    procedure Shrink;
    procedure Status(Sender: TObject);
  end;

procedure TTest.Shrink;
begin
  InFile := TFileStream.Create('u:\graphed\graphed.exe', fmOpenRead);
  try

    OutFile := TFileStream.Create('u:\test.dat', fmCreate);
    try

      ZStream := TCompressionStream.Create(clFastest, OutFile);
      try
        TCompressionStream(ZStream).OnProgress := Status;
        ZStream.CopyFrom(InFile, 0);
      finally
        ZStream.Free;
      end;

    finally
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end;


procedure TTest.Expand;
var
  Count: Integer;
begin
  InFile := TFileStream.Create('u:\test.dat', fmOpenRead);
  try

    OutFile := TFileStream.Create('u:\graphed.new', fmCreate);
    try

      ZStream := TDecompressionStream.Create(InFile);
      try
        TDecompressionStream(ZStream).OnProgress := Status;
        while True do
          begin
            Count := ZStream.Read(Buffer, BufferSize);
            if Count <> 0 then OutFile.WriteBuffer(Buffer, Count) else Break;
          end;
      finally
        ZStream.Free;
      end;

    finally
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end;

procedure TTest.Status(Sender: TObject);
begin
  Writeln(TCustomZLibStream(Sender).Position);
end;

var
  T: TTest;
begin
  T := TTest.Create;
  try
    T.Shrink;
    T.Expand;
  finally
    T.Free;
  end;
  Readln;
end.