TCompressionStream initializes data

The SPDY protocol indicates the initialization of data compression name / value with a predefined data block:

http://mbelshe.github.com/SPDY-Specification/draft-mbelshe-spdy-00.xml#rfc.section.2.6.9.1

(The zlib compression method is that it will use fewer bits for the character strings that “appear” to re-display more, so if you preload the compression with the usual suspects, most likely you will get fewer bits after the compression more time But now for my real question :)

Is this possible with a Delphi TCompressionStream from a ZLib block?

+6
source share
2 answers

You need to use deflateSetDictionary . It is available in Delphi XE2 ZLib.pas , but the compression stream classes do not expose the TZStreamRec field to call it. Class helpers can access the private fields of a related class, so you can get around this limitation by adding it to TCustomZStream (adding it to TZCompressionStream will not work).

 type TCustomZStreamHelper = class helper for TCustomZStream function SetDictionary(dictionary: PByte; dictLength: Cardinal): Integer; end; function TCustomZStreamHelper.SetDictionary(dictionary: PByte; dictLength: Cardinal): Integer; begin if Self is TZCompressionStream then Result := deflateSetDictionary(Self.FZStream, dictionary, dictLength) else if Self is TZDecompressionStream then Result := inflateSetDictionary(Self.FZStream, dictionary, dictLength) else raise Exception.Create('Invalid class type'); end; 

Just call SetDictionary with the SPDY line immediately after creating the compression stream.

+6
source

The required functionality is in ZLib, but Delphi is not displayed.

Delphi XE2 documentation for it. ZLib has the desired deflateSetDictionary function, specified for internal use only. The description of the function in the advanced functions section of the ZLib manual makes it clear that it has the necessary functions.

+4
source

Source: https://habr.com/ru/post/906899/


All Articles