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.
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.
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(Te x: 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.Creat e(InFile);
try
while True do
begin
Count := ZStream.Read(BufferZ, BufferSize);
if Count <> 0 then OutFile.WriteBuffer(Buffer Z, 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
const
BufferSize = 4096;
var
functions: Tfunctions;
BufferZ: array[0..BufferSize-1] of Byte;
InFile: TStringStream;
OutFile: TStringStream;
ZStream: TCustomZLibStream;
function TFunctions.CompressText(Te
begin
InFile := TStringStream.Create(Tex);
try
OutFile := TStringStream.Create('');
try
ZStream := TCompressionStream.Create(
try
ZStream.CopyFrom(InFile, 0);
finally
ZStream.Free;
end;
finally
Result:= OutFile.DataString;
OutFile.Free;
end;
finally
InFile.Free;
end;
end;
function TFunctions.DeCompressText(
var Count: Integer;
begin
InFile := TStringStream.Create(Tex);
try
OutFile := TStringStream.Create('');
try
ZStream := TDecompressionStream.Creat
try
while True do
begin
Count := ZStream.Read(BufferZ, BufferSize);
if Count <> 0 then OutFile.WriteBuffer(Buffer
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Motaz: can you mail me that unit
p0seidon@extended.de
thx
p0seidon@extended.de
thx
ASKER
Can you send me that Unit please
to dreamvb@yahoo.com
Thanks
Motaz
to dreamvb@yahoo.com
Thanks
Motaz
can i have it too ?
brian7@teleline.es
thanks
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 )
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 )
just look at zlib compression unit in the extras folder of your delphi cd,it also comes with example of compressing files.