Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2017, 09:53 PM
DonaldAdams1951 DonaldAdams1951 is offline
Senior Member
 
Join Date: Nov 2009
Posts: 102
Default How do I successfully zlib compress an RTF

Delphi XE3

I decompressed an RTF file that had zlib compression applied to it and it worked just fine. I then tried to compress it so I could compare to the original zlibbed RTF. When I compressed the file it was in HEX.

What do I need to do to zlib compress an RTF file.

Here is my Delphi code.


Code:
procedure TMainForm.CompressRTFFileToZlib;
var
  LInput, LOutput: TFileStream;
  LZip: TZCompressionStream;
  zlibfilename : string ;
begin
  { Create the Input, Output, and Compressed streams. }

  try

    zlibfilename := ChangeFileExt(ZlibTargetFileEdit.Text, '.zip') ;

    LInput  := TFileStream.Create(ZlibTargetFileEdit.Text, fmOpenRead);

    LOutput := TFileStream.Create(zlibfilename, fmCreate);
//    LZip := TZCompressionStream.Create(LOutput, zcDefault);
    LZip := TZCompressionStream.Create(LOutput);

    { Compress data. }
    LZip.CopyFrom(LInput, LInput.Size);

  finally
    { Free the streams. }
    LZip.Free;
    LInput.Free;
    LOutput.Free;
  end ;

end;
Reply With Quote
  #2  
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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:54 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.