Heiko
New Member
Posts: 18
|
Post by Heiko on Apr 21, 2007 3:29:41 GMT -5
Hi,
I want to zip a text file via ZipFromStream.
I want to use the following code, but no file "streamtest.zip" will be created. What's going wrong? I hope anybody can help me. Thanks.
var aMemStrm : TkpMemoryStream; begin Zip.Create(nil); try Zip.ZipName := 'C:\temp\streamtest.zip';
aMemStrm := TkpMemoryStream.Create; aMemStrm.LoadFromFile('C:\temp\test.txt'); aMemStrm.Position := 0;
Zip.DoProcessMessages := False; Zip.ArchiveStream := TkpMemoryStream.Create; Zip.PackLevel := 6;
Zip.ZipFromStream(aMemStrm, 'xyz'); finally Zip.Free; end; end;
|
|
|
Post by Kevin on Apr 21, 2007 6:52:25 GMT -5
If you want the archive to go to streamtest.zip then do not create an ArchiveStream. Once you create an ArchiveStream and then call Zip, you are creating an in-memory archive. So, in your code, the first thing you did is set VCLZip up to zip to streamtest.zip and then you turned around and set VCLZip up to zip directly to a memory stream by setting the ArchiveStream property. If you remove the line that sets the ArchiveStream property I think your code should work.
If your intent is to create the archive in memory, then remove the line that sets the ZipName property, leave the line that sets the ArchiveStream property and then, after calling Zip, write the contents of ArchiveStream out to a file on disk.
Kevin
|
|
Heiko
New Member
Posts: 18
|
Post by Heiko on Apr 22, 2007 1:56:57 GMT -5
Hello Kevin,
thanks for your fast reply.
I tried it out and your first solution works.
At the second I have a problem. I work with Delphi 5 and have to use the TkpMemoryStream. How can I write the content of the ArchiveStream out to a file? I didn't found any explanations. Could you explain it? Thanks.
|
|
|
Post by Kevin on Apr 22, 2007 20:19:20 GMT -5
For Delphi 4 TKpStreams has this procedure:
procedure SaveToStream(Stream: TStream); override;
I think that should do what you want.
|
|