问题描述
我正在使用 LZ4 库,并在使用
解压缩数据时使用
I'm using LZ4 library and when decompressing data with
int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize);
我想估计最大的解压缩数据大小.但是我找不到
I want to estimate maximum decompressed data size. But I can not find reverse function of
int LZ4_compressBound(int isize);
通过它我可以确定解压缩数据的上限,该上限将提供给解压缩功能的最后一个参数maxDecompressedSize
.
with which I can determine the upper bound for decompressed data, which to provide to last parameter maxDecompressedSize
, of decompressing function.
例如其他压缩库(例如 snappy )提供了此类功能.
Other compression libraries like snappy for example, provides such function.
bool GetUncompressedLength(Source* source, uint32* result);
如果我无法保存初始数据大小(在压缩之前),并且我不想对必须分配的缓冲区大小过于悲观,该怎么办?
What can I do if I have not capability to save initial data size (before compression), and if I don't want to be over pessimistic for the size of the buffer which I must allocate?
推荐答案
LZ4的最大压缩率是255,因此,保证解压缩数据大小的过高估计是输入大小的255倍.
The maximum compression ratio of LZ4 is 255, so a guaranteed over-estimation of decompressed data size is 255 times input size.
这显然太多了,不能真正有用,因此没有"reverse LZ4_compressBound()"函数的原因.
That's obviously too much to be really useful, hence the reason why there is no "reverse LZ4_compressBound()" function available.
恐怕没有其他方法可以保存或知道未压缩的大小. LZ4原始"压缩格式没有定义保存此类信息的方法,因为最佳选择是特定于应用程序的.例如,某些应用程序预先知道任何块都不能大于16KB,因此在调用LZ4_decompress_safe()时,它们可以使用maxDecompressedSize = 16 KB.
I'm afraid there is no other way than to save, or know, the uncompressed size. The LZ4 "raw" compression format doesn't define a way to save such information, because optimal choice is application specific. For example, some application know in advance that no block can be > 16KB, so they can use maxDecompressedSize = 16 KB when calling LZ4_decompress_safe().
现在,如果您正在寻找一种负责这种责任的信封格式,则可以创建自己的自定义格式,也可以使用LZ4取景格式: http://fastcompression.blogspot.fr/2013/04/lz4-streaming-format-final.html (在源代码包中也以LZ4_Framing_Format.html的形式出现). las,能够生成和读取此格式的库目前处于beta阶段( https://github. com/Cyan4973/lz4/tree/frame )
Now, if you are looking for an envelope format that will take in charge such responsibility, you could either create your own custom one, or use the LZ4 Framing format : http://fastcompression.blogspot.fr/2013/04/lz4-streaming-format-final.html (also present as LZ4_Framing_Format.html within source package). Alas, the library able to generate and read this format is currently in beta stage (https://github.com/Cyan4973/lz4/tree/frame)
这篇关于LZ4库解压缩数据上限大小估计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!