Q
question
Unregistered / Unconfirmed
GUEST, unregistred user!
使用压缩过程编码一个文件,没有问题,问题出在我用解压缩过程还原压缩过程产生的文件
时,出现错误,错误应该出在 ZStream := TDecompressionStream.Create(OutStream);
具体代码附后,如何解决?
uses ZLib;
压缩过程:
procedure TForm1.Button4Click(Sender: TObject);
var
InStream, OutStream: TStream;
DestStream: TFileStream;
ZStream: TCompressionStream;
TempFile : String;
S:String;
begin
S := 'D:/ls01.xml';
TempFile := 'd:/school.uc';
InStream := TFileStream.Create(S, fmOpenRead);
OutStream := TMemoryStream.Create;
try
ZStream := TCompressionStream.Create(clDefault, OutStream);
ZStream.CopyFrom(InStream,0);
ZStream.free;
except
InStream.Free;
ShowMessage('编码上报文件失败!');
Exit;
end;
try
DestStream := TFileStream.Create(TempFile, fmCreate);
except
OutStream.Free;
ShowMessage('创建临时文件失败!');
Exit;
end;
DestStream.CopyFrom(OutStream, 0);
DestStream.Free;
InStream.Free;
OutStream.Free;
end;
解压缩
var
SourceDBName : String;
InStream, OutStream : TStream;
ZStream: TDecompressionStream;
DestStream: TFileStream;
TempFile : String;
begin
//开始导入
//检验文件的合法性
SourceDBName := Trim(Edit1.Text);
TempFile := 'c:/input.xml';
OutStream := TMemoryStream.Create;
InStream := TFileStream.Create(SourceDBName, fmOpenRead);
OutStream.CopyFrom(InStream,0);
try
ZStream := TDecompressionStream.Create(OutStream);
//应该是上面这句执行无效,导致下面这句出现错误。
ShowMessage(InttoStr(zStream.Size));
OutStream.CopyFrom(ZStream, 0);
ZStream.Free;
except
SetScreenInfo;
InStream.Free;
OutStream.Free;
ShowMessage('解码上报文件失败!');
Exit;
end;
try
DestStream := TFileStream.Create(TempFile, fmCreate);
except
SetScreenInfo;
InStream.Free;
OutStream.Free;
ShowMessage('创建临时文件失败!');
Exit;
end;
DestStream.CopyFrom(OutStream, 0);
DestStream.Free;
end;
时,出现错误,错误应该出在 ZStream := TDecompressionStream.Create(OutStream);
具体代码附后,如何解决?
uses ZLib;
压缩过程:
procedure TForm1.Button4Click(Sender: TObject);
var
InStream, OutStream: TStream;
DestStream: TFileStream;
ZStream: TCompressionStream;
TempFile : String;
S:String;
begin
S := 'D:/ls01.xml';
TempFile := 'd:/school.uc';
InStream := TFileStream.Create(S, fmOpenRead);
OutStream := TMemoryStream.Create;
try
ZStream := TCompressionStream.Create(clDefault, OutStream);
ZStream.CopyFrom(InStream,0);
ZStream.free;
except
InStream.Free;
ShowMessage('编码上报文件失败!');
Exit;
end;
try
DestStream := TFileStream.Create(TempFile, fmCreate);
except
OutStream.Free;
ShowMessage('创建临时文件失败!');
Exit;
end;
DestStream.CopyFrom(OutStream, 0);
DestStream.Free;
InStream.Free;
OutStream.Free;
end;
解压缩
var
SourceDBName : String;
InStream, OutStream : TStream;
ZStream: TDecompressionStream;
DestStream: TFileStream;
TempFile : String;
begin
//开始导入
//检验文件的合法性
SourceDBName := Trim(Edit1.Text);
TempFile := 'c:/input.xml';
OutStream := TMemoryStream.Create;
InStream := TFileStream.Create(SourceDBName, fmOpenRead);
OutStream.CopyFrom(InStream,0);
try
ZStream := TDecompressionStream.Create(OutStream);
//应该是上面这句执行无效,导致下面这句出现错误。
ShowMessage(InttoStr(zStream.Size));
OutStream.CopyFrom(ZStream, 0);
ZStream.Free;
except
SetScreenInfo;
InStream.Free;
OutStream.Free;
ShowMessage('解码上报文件失败!');
Exit;
end;
try
DestStream := TFileStream.Create(TempFile, fmCreate);
except
SetScreenInfo;
InStream.Free;
OutStream.Free;
ShowMessage('创建临时文件失败!');
Exit;
end;
DestStream.CopyFrom(OutStream, 0);
DestStream.Free;
end;