View Single Post
 
Old 04-01-2017, 03:18 PM
DonaldAdams1951 DonaldAdams1951 is offline
Senior Member
 
Join Date: Nov 2009
Posts: 102
Default

I found tyhis code and it works fine.

Code:
procedure TMainForm.Compress(const ASrc, ADest: string);
var
  B: array[1..2048] of byte;
  R: Integer;
  vSrc: TStream;  // source file stream
  vDest: TStream;  // destination file stream
  vCompressor: TStream;  // compression stream
begin
  if not FileExists(ASrc) then
    raise Exception.Create('Source file does not exist');

  vDest := TFileStream.Create(ADest, fmCreate);
  try
    vCompressor := TCompressionStream.Create(clMax, vDest);
    try
      vSrc := TFileStream.Create(ASrc, fmOpenRead);
      try
        repeat
          R := vSrc.Read(B, SizeOf(B));
          if R > 0 then
            vCompressor.Write(B, R);
        until R < SizeOf(B);
//        C.CopyFrom(S, 0);
      finally
        vSrc.Free;
      end;
    finally
      vCompressor.Free;
    end;
  finally
    vDest.Free;
  end;
end;
Reply With Quote