|
Post by NHustak on Nov 6, 2003 17:02:04 GMT -5
Is there a way to zip a string straight into another string, prefereable with password??
|
|
|
Post by Kevin on Nov 6, 2003 22:43:57 GMT -5
It is possilbe. However, you may not get much if any compression from a string that is not very long. There are no built in functions to do this in VCLZip but you could do the same thing by zipping the string to a TMemoryStream and then copying the TMemoryStream's buffer to a string. You would do something like:
function CompressString(str: String; pwd: String): String; var stream: TMemoryStream; begin stream := TMemoryStream.Create; VCLZip1.ArchiveStream := stream; VCLZip1.Password := pwd; VCLZip1.ZipFromBuffer(PChar(str),Length(str),'dummy.str'); SetLength(Result,VCLZip1.ArchiveStream.Size); Move(VCLZip1.ArchiveStream.Memory, Result[1],Length(Result); // Clean up VCLZip1.ArchiveStream := nil; stream.free; end;
There may be bugs in the above code since I just did it from memory.
Kevin
|
|
|
Post by NHustak on Nov 8, 2003 11:03:13 GMT -5
Aha! The archivestream property is what I was looking for - a way to intercept it from writing to disk. Excellent. Thanks!
|
|