zlib网站上有一个用法示例:http://www.zlib.net/zlib_how.html
但是在示例中,它们正在压缩文件.我想压缩存储在内存缓冲区中的二进制数据.我也不想将压缩缓冲区保存到磁盘.
基本上这是我的缓冲区:
fIplImageHeader->imageData = (char*)imageIn->getFrame();
Run Code Online (Sandbox Code Playgroud)
如何用zlib压缩它?
我会很感激如何做到这一点的代码示例.
我有一个内存和磁盘有限的环境,我需要解压缩基于字符串的块(通过xmlrpc二进制传输)发送给我的gzip文件的内容.但是,在gzip头上使用zlib.decompress()或zlib.decompressobj()/ decompress()两个barf.我试过偏移gzip标题(这里记录),但仍然没有设法避免barf.gzip库本身似乎只支持从文件解压缩.
下面的代码片段简要说明了我想要做的事情(除了在现实生活中缓冲区将从xmlrpc填充,而不是从本地文件读取):
#! /usr/bin/env python
import zlib
CHUNKSIZE=1000
d = zlib.decompressobj()
f=open('23046-8.txt.gz','rb')
buffer=f.read(CHUNKSIZE)
while buffer:
outstr = d.decompress(buffer)
print(outstr)
buffer=f.read(CHUNKSIZE)
outstr = d.flush()
print(outstr)
f.close()
Run Code Online (Sandbox Code Playgroud)
不幸的是,正如我所说,这个barfs:
Traceback (most recent call last):
File "./test.py", line 13, in <module>
outstr = d.decompress(buffer)
zlib.error: Error -3 while decompressing: incorrect header check
Run Code Online (Sandbox Code Playgroud)
从理论上讲,我可以将我的xmlrpc源数据提供给StringIO,然后将其用作gzip.GzipFile()的fileobj,但是,在现实生活中,我没有可用于将整个文件内容保存在内存中的内存作为解压缩的数据.我真的需要一块一块地处理它.
后退将是将我的xmlrpc源数据的压缩从gzip更改为普通zlib,但由于这会影响其他子系统,我希望尽可能避免使用它.
有任何想法吗?
当我brew doctor收到以下错误时:
dyld: Library not loaded: /usr/lib/libltdl.7.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
Error: No available formula for zlib
Run Code Online (Sandbox Code Playgroud)
该文件libltdl.7.dylib不在我的/ usr/lib目录中,但还有其他几个.dylib文件.
我正在运行10.8.1,安装了最新版本的Xcode(4.4.1)及其命令行工具.
知道如何解决这些错误吗?
我需要在zip文件中读取单个文件"test.txt"的内容.整个zip文件是一个非常大的文件(2gb),包含很多文件(10,000,000),因此提取整个文件对我来说不是一个可行的解决方案.我怎样才能读取单个文件?
我一直在尝试编译一个在VC++ 2010中使用zlib压缩的应用程序.
我明白了
error LNK2019: unresolved external symbol _inflateInit2_ referenced in function ...
Run Code Online (Sandbox Code Playgroud)
错误消息,如果我没有链接lib,这不会是不寻常的.我链接静态版本zlib库.
我已经设法让这些完全相同的libs和header配置在不同的解决方案中完美运行,因此这种行为非常出乎意料.
任何想法将不胜感激.
更新:链接器命令行
/OUT:"C:\Documents and Settings\Suthke\My Documents\Visual Studio 2010\Projects\SBRapGen2\Debug\SBRapGen2.exe" /INCREMENTAL /NOLOGO "zlib.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\SBRapGen2.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Documents and Settings\Suthke\My Documents\Visual Studio 2010\Projects\SBRapGen2\Debug\SBRapGen2.pdb" /SUBSYSTEM:CONSOLE /PGD:"C:\Documents and Settings\Suthke\My Documents\Visual Studio 2010\Projects\SBRapGen2\Debug\SBRapGen2.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
更新2:详细链接器输出:
1>------ Build started: Project: SBRapGen2, Configuration: Release Win32 ------
1>
1> Starting pass 1
1> Processed /DEFAULTLIB:uuid.lib …Run Code Online (Sandbox Code Playgroud) 我正在尝试发送一个简单的HTTP POST请求,检索响应正文.以下是我的代码.我正进入(状态
错误:标头检查不正确
在"zlib.gunzip"方法中.我是node.js的新手,我很感激任何帮助.
;
fireRequest: function() {
var rBody = '';
var resBody = '';
var contentLength;
var options = {
'encoding' : 'utf-8'
};
rBody = fSystem.readFileSync('resources/im.json', options);
console.log('Loaded data from im.json ' + rBody);
contentLength = Buffer.byteLength(rBody, 'utf-8');
console.log('Byte length of the request body ' + contentLength);
var httpOptions = {
hostname : 'abc.com',
path : '/path',
method : 'POST',
headers : {
'Authorization' : 'Basic VHJhZasfasNWEWFScsdfsNCdXllcjE6dHJhZGVjYXJk',
'Content-Type' : 'application/json; charset=UTF=8',
// 'Accept' : '*/*',
'Accept-Encoding' : …Run Code Online (Sandbox Code Playgroud) 目标是:
zlib.createGzip())然后将zlib输出的读取流传输到:
1)HTTP response对象
2)和可写文件流以保存gzip压缩输出.
现在我可以做到3.1:
var gzip = zlib.createGzip(),
sourceFileStream = fs.createReadStream(sourceFilePath),
targetFileStream = fs.createWriteStream(targetFilePath);
response.setHeader('Content-Encoding', 'gzip');
sourceFileStream.pipe(gzip).pipe(response);
Run Code Online (Sandbox Code Playgroud)
...工作正常,但我还需要将gzip压缩数据保存到文件中,这样我就不需要每次都重新压缩,并能够直接将gzip压缩数据作为响应流.
那么如何在Node中一次将一个可读流传输到两个可写流中?
将sourceFileStream.pipe(gzip).pipe(response).pipe(targetFileStream);在节点0.8.4工作?
我已经包含<zlib.h>在我的iphone应用程序和源代码中,我正在模拟Brad Larson提供的Molecules示例代码,但是,当我构建项目时,它返回如下错误.任何人都可以向我指出这是一个链接问题的库还是我错过了其他东西?
"_deflate", referenced from: -[NSData(Gzip) gzipDeflate] in NSData+Gzip.o "_inflateEnd",
referenced from: -[NSData(Gzip) initWithGzippedData:] in NSData+Gzip.o "inflateInit2",
referenced from: -[NSData(Gzip) initWithGzippedData:] in NSData+Gzip.o "_inflate",
referenced from: -[NSData(Gzip) initWithGzippedData:] in NSData+Gzip.o "_deflateEnd",
referenced from: -[NSData(Gzip) gzipDeflate] in NSData+Gzip.o "deflateInit2", referenced
from: -[NSData(Gzip) gzipDeflate] in NSData+Gzip.o ld: symbol(s) not found collect2: ld
returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用gcc在我的Linux(Ubuntu 8.04)中编译zpipe.c示例,但是我遇到了一些错误,请看一下:
[ubuntu@eeepc:~/Desktop] gcc zpipe.c
/tmp/ccczEQxz.o: In function `def':
zpipe.c:(.text+0x65): undefined reference to `deflateInit_'
zpipe.c:(.text+0xd3): undefined reference to `deflateEnd'
zpipe.c:(.text+0x150): undefined reference to `deflate'
zpipe.c:(.text+0x1e8): undefined reference to `deflateEnd'
zpipe.c:(.text+0x27b): undefined reference to `deflateEnd'
/tmp/ccczEQxz.o: In function `inf':
zpipe.c:(.text+0x314): undefined reference to `inflateInit_'
zpipe.c:(.text+0x382): undefined reference to `inflateEnd'
zpipe.c:(.text+0x3d7): undefined reference to `inflate'
zpipe.c:(.text+0x44b): undefined reference to `inflateEnd'
zpipe.c:(.text+0x4c1): undefined reference to `inflateEnd'
zpipe.c:(.text+0x4f6): undefined reference to `inflateEnd'
collect2: ld returned 1 exit status
[ubuntu@eeepc:~/Desktop]
Run Code Online (Sandbox Code Playgroud)
请记住,我已正确安装zLib-dev,但为什么我会收到此错误?
我有一个C/C++程序需要读取一个文件,该文件可能是也可能不是gzip压缩的.我知道我们可以使用zlib中的gzread()读取压缩文件和未压缩文件 - 但是,如果文件是gzip压缩的,我只想使用zlib函数(出于性能原因).
那么有没有办法以编程方式检测或检查某个文件是否是从C/C++中删除的?