Contents - Index - Previous - Next


TZipMaster.ExtractStreamToStream


 

TZipMaster See also:

With the ExtractStreamToStream method you can extract a specified stream from another stream.

Function  ExtractStreamToStream( InStream: TMemoryStream; OutSize: LongWord = 32768 ):

Description:

Extracts the specified InStream into an output stream (ZipStream).

Since the uncompressed size is not stored it is possible to specify the output size yourself in OutSize.

If OutSize is not given a start size of 32768 bytes is used and increased when needed in steps of 32768 bytes this will take extra time because with each increment the memory already in use need to be copied to a new location.

 

The first 6 bytes of the input stream are reserved:

 

- The first two bytes are used as a flag, STORED = 0 or DEFLATED = 8.

Type

pFlag = ^Smallint;

pCRC = ^Cardinal;

Var

Flag: SmallInt;

CRC: Cardinal;

Flag := 8;

(pFlag( ZipMaster1.ZipStream.Memory ))^ := Flag;

- The next four bytes should be set to the calculated CRC value, if this value is wrong an OnCRC32Error event will follow.

CRC := xxx;

(pCRC( pChar( ZipMaster1.ZipStream.Memory ) + 2))^ := CRC;

 

After this method returns the stream position is at the begin of the stream.

 

Example:

Var

MyData: TMemoryStream;

Begin

MyData.Create;

 

// Add some text as data...

// MyData.LoadFromFile( 'SomeTextFile.txt' );

MyData.LoadFromStream( ZipMaster1.ZipStream );

// MyData.Write( aTextbuffer, NumberOfBytes );

ZipMaster1.ExtractStreamToStream( MyData );

// *** Another possibility ***

// Var MyOutData: TZipStream;

// MyOutData := ZipMaster1.ExtractStreamToStream( MyData );

MyData.Free;

 

// The Output can be found in the ZipMaster1.ZipStream property.

MsgForm.RichEdit1.Lines.LoadFromStream( ZipMaster1.ZipStream );

MsgForm.Show;