嗯...有点自我解释。我使用Xcode 4和Allegro。
可能重复:
Deflate命令行工具
是的,我知道我可以在shell上使用PHP本身,但我需要在PHP可用之前部署的脚本中使用此功能.
我已经尝试过gzip,unzip但是我的参数不正确或者它们只是不使用相同的压缩.
我想在bash脚本中使用它.进入更高级别的脚本语言不是一种选择.
我编写了以下PHP脚本用于测试目的:
#!/usr/bin/php
<?
$contents = file_get_contents( $argv[1] );
$data = gzuncompress( $contents );
echo substr( $data, 0, 20 ) . "\n";
?>
Run Code Online (Sandbox Code Playgroud)
这会输出我所期望的(解码数据的开头).
如果我将同一个文件传递给gunzip:
$ gunzip -c data
gzip: data: not in gzip format
Run Code Online (Sandbox Code Playgroud)
如果我尝试unzip:
$ unzip data
Archive: data
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory …Run Code Online (Sandbox Code Playgroud) 我编写了一个小应用程序,它应该解压缩以gzip/deflate格式编码的数据.
为了实现这一点,我正在使用ZLIB库,使用解压缩功能.
问题是该功能不起作用!在其他方面,数据不是未压缩的!
我在这里发布代码:
int (*decompress)(PBYTE,PULONG,PBYTE,ULONG);
void DecodeData(PBYTE data,ULONG dataSize){
LoadLibrary("C:\\zlib1.dll");
decompress=(int(*)(PBYTE,PULONG,PBYTE,ULONG))GetProcAddress(
GetModuleHandle("zlib1.dll"),"uncompress");
// Yeah I know the size is hardcoded and it's not right, but it's just a test,
// so nevermind
PBYTE decompressedData=(PBYTE)VirtualAlloc(NULL,300,MEM_COMMIT|MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
ULONG maxSize=250;
decompress(decompressedData,&maxSize,data,dataSize);
MessageBox(0,(char*)decompressedData,0,MB_OK);//MessageBox shows no data, it's blank!
}
Run Code Online (Sandbox Code Playgroud)
GetProcAddress成功获取了该函数的指针,问题是该函数返回NULL(甚至没有zlib文档中列出的错误)
大家好我基本上都在尝试使用zlib库,但是当我尝试给自我放气的文件充气时我遇到了麻烦,尽管当我给其他zlib文件充气时它工作正常.
压缩代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char BYTE;
typedef unsigned int UINT;
#include "zlib.h"
#define HEADERSIZE (1024)
#define CHUNKSIZE 4096
#define SWAPINT(x) (((x)&0xFF) << 24)|(((x)&0xFF00) << 8) | (((x)&0xFF0000) >> 8) | (((x)&0xFF000000) >> 24)
#define DEFLATESIZE 65536
const char *mz_error(int err)
{
static struct { int m_err; const char *m_pDesc; } s_error_descs[] =
{
{ Z_OK, "" }, { Z_STREAM_END, "stream end" }, { Z_NEED_DICT, "need dictionary" }, { Z_ERRNO, "file error" }, { Z_STREAM_ERROR, …Run Code Online (Sandbox Code Playgroud) 您可能知道,"cPickle可以比pickle快1000倍,因为前者是用C实现的".zlib是否也在C中实现?事实上,我正在尝试减少使用zlib压缩字符串时我的程序所花费的时间,并且仍然想知道是否应该将其移植到C++以提高其性能.
谢谢
对于一个项目,我必须存储大量的文本,我希望通过zlib压缩文本来保持数据库大小.有没有办法通过测试子串而不解压缩来搜索zlib压缩文本?
我想做类似以下的事情:
>>> import zlib
>>> lorem = zlib.compress("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
>>> test_string = …Run Code Online (Sandbox Code Playgroud) 我试图用一些使用zlib1.2.8的代码调试问题.问题是这个较大的项目可以创建存档,但Z_DATA_ERROR在尝试提取该存档时会遇到标题问题.
为此,我用C++编写了一个小型测试程序,压缩("缩小")指定的常规文件,将压缩数据写入第二个常规文件,并提取("膨胀")到第三个常规文件,一行为一时间 我然后diff第一个和第三个文件,以确保我得到相同的字节.
作为参考,该测试项目位于:https://github.com/alexpreynolds/zlib-test并在Clang下编译(也应该在GNU GCC下编译).
我更大的问题是如何在我的大项目中正确处理标题数据.
在我的第一个测试场景中,我可以使用以下代码设置压缩机械:
z_error = deflateInit(this->z_stream_ptr, ZLIB_TEST_COMPRESSION_LEVEL);
Run Code Online (Sandbox Code Playgroud)
在这里,ZLIB_TEST_COMPRESSION_LEVEL是1为了提供最佳速度.然后我deflate()在z_stream指针上运行,直到没有任何东西从压缩中消失.
要提取这些字节,我可以使用inflateInit():
int ret = inflateInit(this->z_stream_ptr);
Run Code Online (Sandbox Code Playgroud)
那么在这种情况下标题格式是什么?
在我的第二个测试场景中,我设置了deflate机器,如下所示:
z_error = deflateInit2(this->z_stream_ptr,
ZLIB_TEST_COMPRESSION_LEVEL,
ZLIB_TEST_COMPRESSION_METHOD,
ZLIB_TEST_COMPRESSION_WINDOW_BITS,
ZLIB_TEST_COMPRESSION_MEM_LEVEL,
ZLIB_TEST_COMPRESSION_STRATEGY);
Run Code Online (Sandbox Code Playgroud)
这些放气常数分别是,1对于电平,Z_DEFLATED为方法,15+16或31对窗口位,8用于存储器级,并Z_DEFAULT_STRATEGY为策略.
前inflateInit()呼叫不起作用; 相反,我必须使用inflateInit2()并指定一个修改的窗口位值:
int ret = inflateInit2(this->z_stream_ptr, ZLIB_TEST_COMPRESSION_WINDOW_BITS + 16);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,窗口位值不是31在deflateInit2()调用中,而是15+32或 …
我有一个用zlib压缩的tiff图像,但它们在文件的开头粘贴了4个字符的标识符.
我想开始在5位读取文件,跳过前4个字符,然后解压缩.
我修改了以下代码,但当它到达"LOutput.CopyFrom"行时,它告诉我DataError.
procedure TForm1.DecompressXE3 ;
var
LInput, LOutput: TFileStream;
LUnZip: TZDecompressionStream;
FSize : int64 ;
begin
{ Create the Input, Output, and Decompressed streams. }
LInput := TFileStream.Create(edtDecompressSrcFile.Text, fmOpenRead);
FSize := LInput.Size ;
LInput.Position := 5 ;
LOutput := TFileStream.Create(ChangeFileExt(edtDecompressSrcFile.Text, '.tiff'), fmCreate);
LUnZip := TZDecompressionStream.Create(LInput);
{ Decompress data. }
LOutput.CopyFrom(LUnZip, FSize-4 );
// LOutput.CopyFrom(LUnZip, 0 );
{ Free the streams. }
LUnZip.Free;
LInput.Free;
LOutput.Free;
end;
Run Code Online (Sandbox Code Playgroud) 在我的服务器端,我使用zlib python库压缩(zlib.compress())一个字符串,并将它插入redis.在我的redis中,它显示:
x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]
Run Code Online (Sandbox Code Playgroud)
如果我从redis读到python并使用python zlib.decompress(),它就可以了.它可以打印"Hello World".
我怎么能在java中做到这一点?
我从Java 7官方文档中尝试了这段代码.
String temp ="x\\xda\\xcbH\\xcd\\xc9\\xc9\\x07\\x00\\x06,\\x02\\x15";
byte[] output=temp.getBytes();
System.out.println(new String(output));
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0,output.length);
byte[] result = new byte[10000];
int resultLength = decompresser.inflate(result);
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");
System.out.println(outputString);
Run Code Online (Sandbox Code Playgroud)
Java会抛出错误:
java.util.zip.DataFormatException: incorrect header check
Run Code Online (Sandbox Code Playgroud)
我应该怎么解压缩呢?从其他帖子中,我发现人们正在使用GZIPInputStream.有任何性能差异吗?