Contents - Index - Previous - Next


TZipMaster.AddStreamToStream


 

TZipMaster

The AddStreamToStream method adds memory stream data to the ZipStream as packed data.

Function  AddStreamToStream( InStream: TMemoryStream ): TZipStream;

Description:

Adds the data from a memory stream to the ZipStream, so no files are involved in this action.

 

The size of the output stream is set to 6 bytes more than the actual output size because:

- 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 := (pFlag ( ZipMaster1.ZipStream.Memory ))^;

- The next four bytes are set to the calculated CRC value.

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

 

The start of the stream (Position) is set to the actual data start, i.e. 6 bytes from the start of the stream.

 

Example:

Var

MyData: TMemoryStream;

 

  MyData.Create;

 

  // Add some text as data...

  MyData.LoadFromFile( 'L:\SomeFile.dat' );

  // MyData.LoadFromStream( aStream ); // Or use data from another stream.

  // MyData.Write( aTextbuffer, NumberOfBytes ); // Or data from a character buffer.

  ZipMaster1.AddStreamToStream( MyData );

  // *** Another possibility ***

  // Var MyOutData: TZipStream;

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

MyData.Free;

 

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