support@adelavida.com  
Клипарт · Вернисаж · Конференции · Downloads · Досуг · Сайты · Чат

FAQ (Frequently Asked Questions)
<< Вернуться в конференцию Delphi
 FAQ из конференций:  3D графика Delphi Игры Политика PHP&MySQL QuarkXPress Turbo Pascal WEB-дизайн 
Все вопросы
<<    Delphi FAQ    >>
AL [2003-05-10 21:25:21]
VCLZip & TMemoryStream
Здравствуйте, кто может подсказать, как упаковать TMemoryStream с пом. VCLZip?
В файл я ещё так-сяк упаковад:

VCLZip1.ZipName:='SavedZip.zip';
VCLZip1.ZipFromStream(Mem,'FName'); //Mem — это TMemoryStream

Компонента генерирует файл SavedZip.zip. Всё правильно, только мне нужно не создавать файлы, а упаковать TMemoryStream в другой TMemoryStream.

Кто-то с такой хренью сталкивался? :(

Man in Black ® [2003-05-14 13:37:36]
Zipping and UnZipping to and from streams is as easy as zipping to and from zip files.  This allows your application to read from and save directly to streams as if they were normal files.  You still have full control over all options like encryption, compression level, etc.  

The following example shows just how easy it is to do stream to stream compression and decompression.
Say you have your data to be compressed in a TMemoryStream.  Pass it into the following to compress it.  The compressed stream will be returned.

function CompressStream(StreamToCompress: TMemoryStream): TMemoryStream;

begin

Result := TMemoryStream.Create;
// Point ArchiveStream to your memorystream
VCLZip.ArchiveStream := Result;
// Compress the data from uncompressed stream into the ArchiveStream;
VCLZip.ZipFromStream(StreamToCompress, 'DummyFileName');
// Detach your compressed stream from VCLZip
VCLZip.ArchiveStream := nil;

end;

Now you have the returned stream which contains the compressed data.  You can do what you need with this stream.  Now uncompress it into a stream by passing it into the following function.  The decompressed stream will be returned.

function UnCompressStream(StreamToDecompress: TMemoryStream):

TMemoryStream;
begin

// Point ArchiveStream at the compressed stream
VCLZip.ArchiveStream := StreamToDecompress;
// Create stream to uncompress into
Result := TMemoryStream.Create;
// Unzip using the same dummy filename as you used to zip it
VCLZip.UnZipToStream( Result, 'DummyFileName');
// Done with the compressed stream
VCLZip.ArchiveStream := nil;

end;


Вопрос, я думаю, исчерпан.


Всего просмотров: 698. За последние 24 часа: 0


Rambler's Top100       Рейтинг@Mail.ru