SPDY协议指定使用预定义的数据块初始化名称/值数据的压缩:
http://mbelshe.github.com/SPDY-Specification/draft-mbelshe-spdy-00.xml#rfc.section.2.6.9.1
( zlib压缩的工作方式是,对于“出现”更多的字符串,它将使用更少的位,所以如果您使用常见的可疑字符预加载压缩,很可能在压缩后更多的时间您最终会得到更少的位。但现在是我真正的问题了:)
从ZLib单元使用Delphi的TCompressionStream,这是可能的吗?
发布于 2012-01-26 07:44:23
您需要使用deflateSetDictionary。它在DelphiXE2的ZLib.pas中可用,但是压缩流类没有公开TZStreamRec字段来调用它。类帮助器可以访问相关类的私有字段,因此您可以通过向TCustomZStream添加一个字段(将其添加到TZCompressionStream不起作用)来绕过该限制。
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;只需在创建压缩流后立即使用SPDY字符串调用SetDictionary。
发布于 2012-01-26 07:10:25
所需的功能在ZLib中,但不是由Delphi公开的。
DelphiXE2的documentation for it's ZLib中列出了所需的函数deflateSetDictionary,仅供内部使用。ZLib manual advanced functions section中对该函数的描述清楚地表明它具有您想要的功能。
https://stackoverflow.com/questions/9011442
复制相似问题