iOS compression_encode_buffer 不包含 zlib header?
iOS compression_encode_buffer doesn't include zlib header?
我在 iOS 应用程序中使用 compression_encode_buffer
和 COMPRESSION_ZLIB
到 zlib-compress 数据,但结果缺少 zlib header。
例如:
size = compression_encode_buffer(
destinationBuffer, destinationBufferSize,
sourceBuffer, sourceBufferSize, nil,
COMPRESSION_ZLIB
)
请问return字节数:
AD 53 C1 8E 9B 30 …
例如,在同一数据上使用 Python 的 data.encode("zlib")
时将 return:
78 9C AD 53 C1 8E 9B 30 …
^^ ^^ correct zlib header
这是怎么回事?为什么不包含 header?有没有 "correct" 添加方法?
这两个字节是一个zlib header,不是幻数。您很可能也遗漏了流的最后 4 个字节(ADLER32 校验和),并且只有您希望包装在 zlib 数据流中的 "deflate" 数据流。 iOS documentation 表示:
ZLIB
The encoded format is the raw DEFLATE format as described
in IETF RFC 1951 Using the ZLIB library
他们应该调用压缩方法 "DEFLATE" 而不是 "ZLIB"。
查看此related question关于处理 ZLIB 与 DEFLATE 数据的信息。
我在 iOS 应用程序中使用 compression_encode_buffer
和 COMPRESSION_ZLIB
到 zlib-compress 数据,但结果缺少 zlib header。
例如:
size = compression_encode_buffer(
destinationBuffer, destinationBufferSize,
sourceBuffer, sourceBufferSize, nil,
COMPRESSION_ZLIB
)
请问return字节数:
AD 53 C1 8E 9B 30 …
例如,在同一数据上使用 Python 的 data.encode("zlib")
时将 return:
78 9C AD 53 C1 8E 9B 30 …
^^ ^^ correct zlib header
这是怎么回事?为什么不包含 header?有没有 "correct" 添加方法?
这两个字节是一个zlib header,不是幻数。您很可能也遗漏了流的最后 4 个字节(ADLER32 校验和),并且只有您希望包装在 zlib 数据流中的 "deflate" 数据流。 iOS documentation 表示:
ZLIB
The encoded format is the raw DEFLATE format as described
in IETF RFC 1951 Using the ZLIB library
他们应该调用压缩方法 "DEFLATE" 而不是 "ZLIB"。
查看此related question关于处理 ZLIB 与 DEFLATE 数据的信息。