zlib error while attempting compression: "Ran out of output buffer for writing compressed bytes."
2017-04-27 15:54
330 查看
gzip算法
使用Object-C代码来实现gzip的压缩功能,不管网上找的哪个地方的代码,方法都是一样的https://github.com/cscott530/sprite-kit-platformer/blob/master/SuperKoalio/LFCGzipUtility.m
http://www.clintharris.net/2009/how-to-gzip-data-in-memory-using-objective-c/
http://v2it.win/ios/gzip%E6%96%87%E4%BB%B6%E5%8E%8B%E7%BC%A9%E5%92%8C%E8%A7%A3%E5%8E%8B%E7%BC%A9/
在使用大的数据进行gzip压缩时,一切正常,但是使用小的数据,比如几个字节,这是就会出现以下的错误:
zlib error while attempting compression: "Ran out of output buffer for writing compressed bytes."
错误的原因是buffer空间不够。
我们来看下压缩的代码:
gzip压缩时,分配的压缩后的数据空间大小为: 1.01倍 + 12.
// Create output memory buffer for compressed data. The zlib documentation states that
// destination buffer size must be at least 0.1% larger than avail_in plus 12 bytes.
NSMutableData compressedData = [NSMutableData dataWithLength:[pUncompressedData length]
1.01 + 12];
针对小的数据,这个大小远远不够,如果改成 10倍 + 12,可以正常gzip压缩,具体的临界值是多少还没去仔细研究:
1. http://www.jianshu.com/p/a0c94dc75efc
相关文章推荐
- zlib error while attempting compression: "Ran out of output buffer for writing compressed bytes."
- Java # java.lang.OutOfMemoryError: requested 32744 bytes for ChunkPool::allocate. Out of swap space?
- SurfaceFlinger/gralloc Out of Memory error when allocating buffer memory for use with virtual frame
- How-to: resolve " java.lang.OutOfMemoryError: unable to create new native thread" for hbase thrift
- Error: "Out of memory!" attempting SFTP connectio
- VC++6.0中常出现的"unexpected end of file while looking for precompiled header directive"的问题解决方法
- VC++6.0中常出现的"unexpected end of file while looking for precompiled header directive"的问题
- How to fix the dreaded "java.lang.OutOfMemoryError- PermGen space" exception (classloader leaks)
- Jmeter Debug - "Unrecognized VM option '+HeapDumpOnOutOfMemoryError"【转帖】
- VC中头文件编译错误:fatal error C1010:“unexpected end of file while looking for precompiled header directive"
- 960000-byte external allocation too large for this process VM won't let us allocate 960000 bytes java.lang.OutOfMemoryError: bit
- MySQL错误"Out of range value adjusted for column ..."的解决方法
- Eclipse 报 “Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ”错误的解决办法
- Restore SQL Server 2005 error : "The tail of the log for the database "TEST1" has not been backed up."
- Unparsed aapt error(s)! Check the console for output"
- LinkageError之loader (instance of xxx) previously initiated loading for a different type with name "lib/MyData"
- 960000-byte external allocation too large for this process VM won't let us allocate 960000 bytes java.lang.OutOfMemoryError: bi
- Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
- MySQL错误"Out of range value adjusted for column ..."的解决方法
- Eclipse 报 “Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ”错误的解决办法