M
Mclkings
Unregistered / Unconfirmed
GUEST, unregistred user!
怎么使用流进行数据压缩~~~
下面是我写的一个压缩过程,一个解压过程,
压缩可以实现,解压不可以实现~~不知道怎么解决~~~
procedure TFrmMain.btn1Click(Sender: TObject);
var
Count: Integer;
Com: TCompressionStream;
MeM,Source: TMemoryStream;
ComLevel: TCompressionLevel;
begin
ComLevel := clFastest;
MeM := TMemoryStream.Create;
Source := TMemoryStream.Create;
Count := Source.Size;
mmo1.Lines.SaveToStream(Source);
Com := TCompressionStream.Create(ComLevel, MeM);
Source.SaveToStream(Com);
Com.Free;
Source.Clear;
Source.Write(Count, SizeOf(Count));
Source.CopyFrom(MeM, 0);
Source.Position := 0;
Source.SaveToFile('b.txt');
end;
procedure TFrmMain.btn2Click(Sender: TObject);
var
Source: TDecompressionStream;
Mem: TMemoryStream;
Count: Integer;
Buf: PChar;
FileM: TFileStream;
sName : string;
begin
sName := ExtractFilePath(ParamStr(0))+'b.txt';
Mem := TMemoryStream.Create;
FileM := TFileStream.Create(sName, fmOpenRead);
FileM.ReadBuffer(Count , SizeOf(Count));
GetMem(Buf, Count);
Source := TDecompressionStream.Create(FileM);
Source.ReadBuffer(Buf^, Count);
Mem.WriteBuffer(Buf^, Count);
Mem.Position := 0;
Mem.SaveToFile('bb.txt');
FreeMem(Buf);
end;
谢谢~~~~
下面是我写的一个压缩过程,一个解压过程,
压缩可以实现,解压不可以实现~~不知道怎么解决~~~
procedure TFrmMain.btn1Click(Sender: TObject);
var
Count: Integer;
Com: TCompressionStream;
MeM,Source: TMemoryStream;
ComLevel: TCompressionLevel;
begin
ComLevel := clFastest;
MeM := TMemoryStream.Create;
Source := TMemoryStream.Create;
Count := Source.Size;
mmo1.Lines.SaveToStream(Source);
Com := TCompressionStream.Create(ComLevel, MeM);
Source.SaveToStream(Com);
Com.Free;
Source.Clear;
Source.Write(Count, SizeOf(Count));
Source.CopyFrom(MeM, 0);
Source.Position := 0;
Source.SaveToFile('b.txt');
end;
procedure TFrmMain.btn2Click(Sender: TObject);
var
Source: TDecompressionStream;
Mem: TMemoryStream;
Count: Integer;
Buf: PChar;
FileM: TFileStream;
sName : string;
begin
sName := ExtractFilePath(ParamStr(0))+'b.txt';
Mem := TMemoryStream.Create;
FileM := TFileStream.Create(sName, fmOpenRead);
FileM.ReadBuffer(Count , SizeOf(Count));
GetMem(Buf, Count);
Source := TDecompressionStream.Create(FileM);
Source.ReadBuffer(Buf^, Count);
Mem.WriteBuffer(Buf^, Count);
Mem.Position := 0;
Mem.SaveToFile('bb.txt');
FreeMem(Buf);
end;
谢谢~~~~