Link to home
Start Free TrialLog in
Avatar of dreamvb
dreamvb

asked on

Compressing text files

Hi can someone please help me
I am thinking of writeing my own little program for compressing text files and just text files nothing else.
Ok so what i want to now is were I might find some projects, tutors, or code. No OCXS,DLLS,LIBARYS as I now were to find ocx,dlls I just want to make my own prgram form basic code
Thanks.
Avatar of inthe
inthe

Hi,
just look at zlib compression unit in the extras folder of your delphi cd,it also comes with example of compressing files.
compressing text with ZLIB:

const
  BufferSize = 4096;

var
  functions: Tfunctions;

  BufferZ: array[0..BufferSize-1] of Byte;
  InFile: TStringStream;
  OutFile: TStringStream;
  ZStream: TCustomZLibStream;

function TFunctions.CompressText(Tex: string): string;
begin
  InFile := TStringStream.Create(Tex);
  try
    OutFile := TStringStream.Create('');
    try
      ZStream := TCompressionStream.Create( clFastest, OutFile);
      try
        ZStream.CopyFrom(InFile, 0);
      finally
        ZStream.Free;
      end;
    finally
    Result:= OutFile.DataString;
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end;

function TFunctions.DeCompressText(Tex: string): string;
var Count: Integer;
begin
  InFile :=  TStringStream.Create(Tex);
  try
    OutFile := TStringStream.Create('');
    try
      ZStream := TDecompressionStream.Create(InFile);
      try
        while True do
          begin
            Count := ZStream.Read(BufferZ, BufferSize);
            if Count <> 0 then OutFile.WriteBuffer(BufferZ, Count) else Break;
          end;
      finally
        ZStream.Free;
      end;
    finally
    Result:= OutFile.DataString;
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end;

-------

with a little changes you can use it also with files.. using TFileStream

---

if you don't want to use zlib and make everything for your own.. you can learn how zlib works..
the only things I can teach you are RLA and HUFFMAN compression..
huffman is quite good
ASKER CERTIFIED SOLUTION
Avatar of Motaz
Motaz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Motaz: can you mail me that unit
p0seidon@extended.de

thx
Avatar of dreamvb

ASKER

Can you send me that Unit please
 to dreamvb@yahoo.com

  Thanks
       Motaz
can i have it too ?

brian7@teleline.es

thanks
Hi Motaz,

I'm very interested at you original code to turbo pascal. I'm looking for a zip/unzip code  to turbo pascal too. Have it you ?

Thanks, Radler( roger@ars.com.br )