Experts,
I have the following problem. I try to find a solution to create a zip file as a stream, but the zip file should not be stored physically and should exist only as a stream.
I have tried with the following code example, but it doesn't work. If I do it this way, an error message blobs up:
The archive is corrupted or do not contains files.
The zip library that I use is ZipMaster - DelphiZip (http://www.delphizip.org/).
function StreamToZipStream( const InStream: TStream; out OutStream: TStream). Boolean;
var
ZipMaster1 : TZipMaster;
begin
//wird nie benutzt: result := 0;
ZipMaster1 := TZipMaster.create(nil);
try
ZipMaster1.DLLDirectory := GetModuleDir;
ZipMaster1.AddCompLevel := 9; // highest compression
ZipMaster1.AddOptions := [AddHiddenFiles];
InStream.Position := 0;
ZipM.AddStreamToStream(TMemoryStream(InStream));
//after add the inStream to the ZipMaster1.ZipStream
// save it to the OutStream ?
ZipMaster.ZipStream.SaveToStream(OutStream);
result := ZipMaster1.ErrCode = 0;
finally
ZipMaster1.free;
end;
end;
...
InStream := TMemoryStream.Create;
OutStream := TMemoryStream.Create;
try
//load a file to MemoryStream
InStream.LoadFromFile('File.txt');
//ZipMaster operation to create a zip stream, that I can save as .zip from this stream
StreamToZipStream(aInStream, aOutStream ) ;
// I get a file 'File.zip' with the right file size, but I can not handle this file.
// an error message "the archive is corrupted" poped up if I try to do some operations with.
OutStream.SaveToFile('File.zip');
finally
InStream.Free;
OutStream.Free;
end;