zzip解压
① 为什么nodejs 使用zlib解压文件出现错误
安装nodeJs流程:1、下载nodejs引擎,32bitversion或者64bitversion2、下载最新版的npm zip格式压缩包:3、在硬盘某个位置,如D盘下建立一个文件nodejs,把上面两个下载的东西都放在这里,npm要解压。4、配置两个环境变量:一个是PATH上增加node.exe的目录D:\\nodejs,一个是增加环境变量NODE_PATH,值为D:\\nodejs\\node_moles。5、win7环境配置在系统》高级系统设置》高级》环境变量》系统变量中查找PATH,编辑加上D:\\nodejs,再加上NODE_PATH变量和值。6、安装express:打开cmd命令行,使用命令行定位到这Node目录下,键入指令npminstallexpress[安装express至相对路径]或npminstallexpress-g[安装express至绝对路径]到这里,你在命令行里面输入node-v如果输出nodejs的版本则安装成功。更新nodejs的版本可以在命令行中输入: npmupdatenpm-g
② 如何在linux平台下使用C++语言实现多文件的压缩解压缩(使用zlib依赖库)必重谢!
由于Unix系一贯坚持功能分离,所以通常是先tar再gzip来完成多文件一次压缩。
开发中一般是借助zlib-X.X.X.tar.gzzlib-X.X.X.tarzlib-X.X.Xcontribminizip实例中的接口:
ZLib可能并不是一个针对ZIP文件的库,它只是一个针对gzip以及deflate算法的库。它提供了一个叫做minizip
(contribminizip)例子来给出操作ZIP文件的方法。下文将从ZLib出发,归结出两个傻瓜接口:BOOLZipCompress(LPCTSTRlpszSourceFiles,LPCTSTRlpszDestFile);
BOOLZipExtract(LPCTSTRlpszSourceFile,LPCTSTRlpszDestFolder);
要引入的源文件
ZLib主目录下的代码,除minigzip.c、example.c外;
contribminizip下的代码,除minizip.c、miniunz.c外。
相关API
虽
然minizip更像是个例子,但是除去其主程序minizip.c和miniunz.c后,剩下的部分我们可以看作是ZLib
的一个上层库,它封装了与ZIP文件格式相关的操作。而minizip.c和miniunz.c
就是我们要改写的——把它从命令行程序改为上述傻瓜接口。minizip.c和miniunz.c中用到的API主要有:
压缩相关:
zipOpen64
zipClose
zipOpenNewFileInZip
zipCloseFileInZip
zipWriteInFileInZip
解压相关:
unzOpen64
unzClose
unzGetGlobalInfo64
unzGoToNextFile
unzGetCurrentFileInfo64
unzOpenCurrentFile
unzCloseCurrentFile
unzReadCurrentFile
想必看到这些名字都能猜到怎么用了吧。好的接口果然能带给人愉悦的。minizip中的这些函数有的是带“64”的有的是不带的,有的还有“2”、“3”、“4”版本。这里一律用带64的,不带“2”、“3”、“4”的。
来源参考:http://www.cppblog.com/Streamlet/archive/2010/09/22/127368.html
③ 在Linux下,用zlib写解压文件的C程序,需要事先知道文件压缩前的大小么怎么得到
.gz文件的最后4字节就是压缩前的原长度(ISIZE),并且倒数第二个4字节是压缩前原buffer的CRC32冗余校验值。参见标准文档 rfc1952 (https://tools.ietf.org/html/rfc1952).
④ java 如何用zlib解压缩tar.gz文件
public static void makeZip(List<File> fileList,String zipPath,boolean isDelete) {
byte[] buf = new byte[1024];
try {
// Create the ZIP file
File zipFile = new File(zipPath);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
// Compress the files
for (int i = 0; i < fileList.size(); i++) {
FileInputStream in = new FileInputStream(fileList.get(i));
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(fileList.get(i).getName()));
// Transfer bytes from the file to the ZIP file
int len;
while ( (len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
System.out.println("压缩完成.");
//把旧的文件删除
if(isDelete == true){
for (int i = 0; i < fileList.size(); i++) {
File oldFile = fileList.get(i);
oldFile.delete();
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
File in1=new File("D:\\a.txt");
File in2=new File("D:\\b.txt");
File[] file=new File[]{in1,in2};
File zip=new File("D:\\ab.zip");
IDMZip mgr=new IDMZip();
mgr.ZipFiles(file, zip);
}
这个方法不管你是在windows下还是在linux下,都能正常执行。
⑤ C++语言怎么用zlib库来解压.ISO或.zip文件
下面是使用zlib库的压缩和解压缩演示代码:
#include <stdlib.h>
#include <stdio.h>
#include <zlib.h>
int main(int argc, char* argv[])
{
FILE* file;
uLong flen;
unsigned char* fbuf = NULL;
uLong clen;
unsigned char* cbuf = NULL;
/* 通过命令行参数将srcfile文件的数据压缩后存放到dstfile文件中 */
if(argc < 3)
{
printf("Usage: zcdemo srcfile dstfile\n");
return -1;
}
if((file = fopen(argv[1], "rb")) == NULL)
{
printf("Can\'t open %s!\n", argv[1]);
return -1;
}
/* 装载源文件数据到缓冲区 */
fseek(file, 0L, SEEK_END); /* 跳到文件末尾 */
flen = ftell(file); /* 获取文件长度 */
fseek(file, 0L, SEEK_SET);
if((fbuf = (unsigned char*)malloc(sizeof(unsigned char) * flen)) == NULL)
{
printf("No enough memory!\n");
fclose(file);
return -1;
}
fread(fbuf, sizeof(unsigned char), flen, file);
/* 压缩数据 */
clen = compressBound(flen);
if((cbuf = (unsigned char*)malloc(sizeof(unsigned char) * clen)) == NULL)
{
printf("No enough memory!\n");
fclose(file);
return -1;
}
if(compress(cbuf, &clen, fbuf, flen) != Z_OK)
{
printf("Compress %s failed!\n", argv[1]);
return -1;
}
fclose(file);
if((file = fopen(argv[2], "wb")) == NULL)
{
printf("Can\'t create %s!\n", argv[2]);
return -1;
}
/* 保存压缩后的数据到目标文件 */
fwrite(&flen, sizeof(uLong), 1, file); /* 写入源文件长度 */
fwrite(&clen, sizeof(uLong), 1, file); /* 写入目标数据长度 */
fwrite(cbuf, sizeof(unsigned char), clen, file);
fclose(file);
free(fbuf);
free(cbuf);
return 0;
}
⑥ delphi中用zlib怎样压缩和解压
数据压缩和解压的示例代码:
{压缩流}
function CompressStream(ASrcStream: TStream; ALevel: TSfCompressionLevel): TStream;
var
SrcData,Buffer:Pointer;
BufSize:Integer;
begin
Buffer:=nil;
Result:=nil;
BufSize:=0;
GetMem(SrcData,ASrcStream.Size);
ASrcStream.Position:=0;
ASrcStream.Read(SrcData^,ASrcStream.Size);
try
try
SfCompressBuf(SrcData,ASrcStream.Size,Buffer,BufSize,ALevel);
except
on E:Exception do
SfRaiseException(E,'Exception raised in CompressStream call');
end;
finally
FreeMem(SrcData);
SrcData:=nil;
end;
//由于try...except块中重引发了异常,所以在发生了异常的情况下,以下的代码不会执行
Result:=TMemoryStream.Create;
Result.Write(Buffer^,BufSize);
FreeMem(Buffer);
end;
{解压流}
function CompressStream(ASrcStream: TStream; ALevel: TSfCompressionLevel): TStream;
var
SrcData,Buffer:Pointer;
BufSize:Integer;
begin
Buffer:=nil;
Result:=nil;
BufSize:=0;
GetMem(SrcData,ASrcStream.Size);
ASrcStream.Position:=0;
ASrcStream.Read(SrcData^,ASrcStream.Size);
try
try
SfCompressBuf(SrcData,ASrcStream.Size,Buffer,BufSize,ALevel);
except
on E:Exception do
SfRaiseException(E,'Exception raised in CompressStream call');
end;
finally
FreeMem(SrcData);
SrcData:=nil;
end;
//由于try...except块中重引发了异常,所以在发生了异常的情况下,以下的代码不会执行
Result:=TMemoryStream.Create;
Result.Write(Buffer^,BufSize);
FreeMem(Buffer);
end;
{压缩字节数组}
function CompressBytes(ASrcBytes: TBytes; ALevel: TSfCompressionLevel): TBytes;
var
Buffer:Pointer;
BufSize:Integer;
begin
Buffer:=nil;
BufSize:=0;
try
SfCompressBuf(@ASrcBytes[0],Length(ASrcBytes),Buffer,BufSize,ALevel);
SetLength(Result,BufSize);
Move(Buffer^,Result[0],BufSize);
except
on E:Exception do
SfRaiseException(E,'Exception raised in CompressBytes call');
end;
//由于try...except块中重引发了异常,所以在发生了异常的情况下,以下的代码不会执行
FreeMem(Buffer);
end;
{解压字节数组}
function DecompressBytes(ASrcBytes: TBytes): TBytes;
var
Buffer:Pointer;
BufSize:Integer;
begin
Buffer:=nil;
BufSize:=0;
try
SfDecompressBuf(@ASrcBytes[0],Length(ASrcBytes),0,Buffer,BufSize);
SetLength(Result,BufSize);
Move(Buffer^,Result[0],BufSize);
except
on E:Exception do
SfRaiseException(E,'Exception raised in DecompressBytes call');
end;
//由于try...except块中重引发了异常,所以在发生了异常的情况下,以下的代码不会执行
FreeMem(Buffer);
end;
⑦ 如何发挥zlib压缩解压的最大效
首先说明,这里不是横向比较zlib与别的引擎(rar,leo,powerarc...),是探索如何发挥zlib压缩/解压的最大效率。
先看看如下代码在效率上的差异:
var MS:TMemoryStream;(1):begin MS:=TMemoryStream.Create; MS.Size:=$400000;//4M------------------------------------------------(2):var i:integer;begin MS:=TMemoryStream.Create; for i:=1 to 1024 do MS.Size:=MS.Size+4096;
你会发现,方法(1)只要1个毫秒,方法(2)却要20秒。
因此,如果把解压缩程序写成下面这样,会非常没有效率:
procere ZlibDeCompress(instream,outStream:TStream);var ACS:TDeCompressionStream; buf:array[1..4096] of byte; numread:integer;begin inStream.Position:=0; ACS:=TDeCompressionStream.Create(inStream); try repeat numRead:=ACS.Read(buf,sizeof(buf)); if numread>0 then outStream.Write(buf,numRead); until (numRead=0); finally ACS.Free; end;end;
如果我们知道原始资料的大小,一次确定outStream.Size,效率就可以提高几十倍。方法很简单,我们可以在压缩时,把原始资料的Size写在压缩Stream的头部,如,写一个LongWord的大小,解压时就可以先读出Size,因此,最有效率的解压程序为:
procere ZlibDecompressStream2(Source,Dest:TMemoryStream);var zstream: TZStreamRec; SourceLen,DestLen:LongWord;begin FillChar(zstream,SizeOf(TZStreamRec),0); SourceLen:=Source.Size; Source.Position:=0; Source.Read(DestLen,SizeOf(LongWord)); Dest.Size:=DestLen; zstream.next_in:=Pointer(LongWord(Source.Memory)+SizeOf(LongWord)); zstream.avail_in:=SourceLen-SizeOf(LongWord); zstream.next_out:=Dest.Memory; zstream.avail_out:=DestLen; ZDecompressCheck(InflateInit(zstream)); try ZDecompressCheck(inflate(zstream,Z_NO_FLUSH)); finally ZDecompressCheck(inflateEnd(zstream)); end;end;
用一个4M的文件试试,效率提高近70倍。
同样道理,在压缩的时候,如果能预先知道压缩后的大小,也能提高效率不少,但这似乎是不可能的,也不能盲目的给outStream.Size一个"足够大"的数值,只能按引擎的原理估算一个最接近的数值,zlib推荐的为:
((SourceLen+(SourceLen div 10)+12)+255) and not 255
因此,最有效率的压缩程序为:
procere ZlibCompressStream2(Source,Dest:TMemoryStream; CompressLevel:TZCompressi);var zstream: TZStreamRec; SourceLen,DestLen:LongWord;begin FillChar(zstream,SizeOf(TZStreamRec),0); SourceLen:=Source.Size; DestLen:=SizeOf(LongWord)+((SourceLen+(SourceLen div 10)+12)+255) and not 255; Dest.Size:=DestLen; Dest.Position:=0; Dest.Write(SourceLen,Sizeof(LongWord)); zstream.next_in:=Source.Memory; zstream.avail_in:=SourceLen; zstream.next_out:=Pointer(LongWord(Dest.Memory)+SizeOf(LongWord)); zstream.avail_out:=DestLen-SizeOf(longWord); ZCompressCheck(DeflateInit(zstream,ZLevels[CompressLevel])); try ZCompressCheck(deflate(zstream,Z_FINISH)); finally ZCompressCheck(deflateEnd(zstream)); end; Dest.Size:=zstream.total_out+SizeOf(LongWord);end;
⑧ zlib库可以解压rar压缩包吗
1准备工作。下载zlib.dll。以及相关头文件。将dll文件及头文件加入工程。2压缩:调用函数compress.形式为intcompress(Byte*dest,uLong*destLen,constByte*source,ULONGsourceLen);功能是将source指向的空间,长度为sourceLen的数据进行压缩,压缩数据储存在dest中,长度由参数destLen返回。如果压缩出错,返回对应错误号,否则返回0.3解压缩:调用函数uncompress.形式为intuncompress(Byte*dest,uLong*destLen,constByte*source,ULONGsourceLen);功能是将source指向的空间,长度为sourceLen的数据进行解压缩,解压缩后的数据储存在dest中,长度由参数destLen返回。如果解压缩出错,返回对应错误号,否则返回0.
⑨ zlib下载文件在哪
第一步 下载并解压zlib压缩包
打开zlib官网,找到下载链接,右键复制地址:
在Linux中使用wget命令下载,执行如下命令开始下载:
wget http://zlib.net/zlib-1.2.8.tar.gz
解压:
tar zxvf zlib-1.2.8.tar.gz
第二步 开始安装
安装过程比较简单,进入zlib的解压目录,依次执行下面几条命令即可:
配置:
./configure
如果之前没有安装gcc(C 编译器),这一步将报如下错误信息::
xueliang@dev:~/download/zlib-1.2.8$ ./configure
Checking for gcc…
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.
xueliang@dev:~/download/zlib-1.2.8$
希望我的回答能对你有所帮助。