比如说我有一个c:\tt
在tt目录下面有十个文件,我想把tt进行压缩,
应该怎么搞
谢谢!
在tt目录下面有十个文件,我想把tt进行压缩,
应该怎么搞
谢谢!
解决方案 »
- 在局域网内能通过计算机名与IP互相访问,但是PING不通(防火墙之类的就不用考虑了)
- 如何查看打印机的队列是否快满了!
- 大家讨论选择什么数据库最好!
- 请问,我想把一个32位,大小为48*48的图标的每一个点色值读出来,请问如何做呢?
- 有使用过ExpressQuantumGrid 4 Suite中的TcxDBColorComboBox的吗?
- Pascal语言写法问题
- delphi(rad) xe2可能要发布了, 开启了世界之旅(可惜不来中国大陆)
- wise 9打包问题
- 我在Form上自己画了个Button,请问如何给这个Button添加OnClick事件,并响应OnClick事件?
- 临时数据存储的问题
- 一个关于字符串的问题!
- 我在一个主表单1的一个按钮中SHOWMODAL另一个表单2,想让FORM2能直接使用FORM1中的。。。
PlayIcq.com可以下载
调用rar.exe 就是
用Delphi调用Rar.exe,得用户机上装有Winrar,或程序自带一个rar.exe,这种方法比较方便简单,但不太适合。所以建议最好用第三方压缩控件,比如VCLZIP、ZIPTV,这些控件技术成熟,功能强。
ZLib; { Compress a stream } procedure CompressStream(inpStream, outStream: TStream);
var
InpBuf, OutBuf: Pointer;
InpBytes, OutBytes: Integer;
begin
InpBuf := nil;
OutBuf := nil;
try
GetMem(InpBuf, inpStream.Size);
inpStream.Position := 0;
InpBytes := inpStream.Read(InpBuf^, inpStream.Size);
CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);
outStream.Write(OutBuf^, OutBytes);
finally
if InpBuf <> nil then FreeMem(InpBuf);
if OutBuf <> nil then FreeMem(OutBuf);
end;
end;
{ Decompress a stream }
procedure DecompressStream(inpStream, outStream: TStream);
var
InpBuf, OutBuf: Pointer;
OutBytes, sz: Integer;
begin
InpBuf := nil;
OutBuf := nil;
sz := inpStream.Size - inpStream.Position;
if sz > 0 then
try
GetMem(InpBuf, sz);
inpStream.Read(InpBuf^, sz);
DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes);
outStream.Write(OutBuf^, OutBytes);
finally
if InpBuf <> nil then FreeMem(InpBuf);
if OutBuf <> nil then FreeMem(OutBuf);
end;
outStream.Position := 0;
end;
{
Example:
Compress the contents of RichEdit1 and
calculate the compression rate.
Then save the stream to a file (ms2.dat) Beispiel:
Komprimiert den Inhalt von RichEdit1 und
berechnet die Kompressionsrate.
Dann wird der Stream in eine Datei (ms2.dat) gespeichert.
} procedure TForm1.Button1Click(Sender: TObject);
var
ms1, ms2: TMemoryStream;
begin
ms1 := TMemoryStream.Create;
try
ms2 := TMemoryStream.Create;
try
RichEdit1.Lines.SaveToStream(ms1);
CompressStream(ms1, ms2);
ShowMessage(Format('Stream Compression Rate: %d %%',
[round(100 / ms1.Size * ms2.Size)]));
ms2.SaveToFile('C:\ms2.dat');
finally
ms1.Free;
end;
finally
ms2.Free;
end;
end; {
Loads the stream from a file (ms2.dat)
and decompresses it.
Then loads the Stream to RichEdit1. Lädt den komprimierten Stream von einer Datei (ms2.dat)
und dekomprimiert ihn.
Dann wird der Stream wieder in RichEdit1 geladen.
} procedure TForm1.Button2Click(Sender: TObject);
var
ms1, ms2: TMemoryStream;
begin
ms1 := TMemoryStream.Create;
try
ms2 := TMemoryStream.Create;
try
ms1.LoadFromFile('C:\ms2.dat');
DecompressStream(ms1, ms2);
RichEdit1.Lines.LoadFromStream(ms2);
finally
ms1.Free;
end;
finally
ms2.Free;
end;
end;
**********************************
procedure Compress(var CompressedStream: TMemoryStream);
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: Integer;
Begin
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream:=TCompressionStream.Create(clMax, DestStream);
Try
CompressedStream.SaveToStream(SourceStream);
SourceStream.Free;
CompressedStream.Clear;
CompressedStream.WriteBuffer(Count, SizeOf(Count));
CompressedStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
end;procedure UnCompress(const CompressedStream: TMemoryStream);
var
SourceStream: TDecompressionStream;
DestStream: TMemoryStream;
Buffer: PChar;
Count: integer;
Begin
CompressedStream.Seek(0,soFromBeginning);
CompressedStream.ReadBuffer(Count, SizeOf(Count));
GetMem(Buffer, Count);
DestStream := TMemoryStream.Create;
SourceStream := TDecompressionStream.Create(CompressedStream);
Try
SourceStream.ReadBuffer(Buffer^, Count);
DestStream.WriteBuffer(Buffer^, Count);
DestStream.Position := 0;//复位流指针
CompressedStream.LoadFromStream(DestStream);
finally
FreeMem(Buffer);
DestStream.Free;
end;
end;