當前位置:首頁 » 文件管理 » zzip解壓

zzip解壓

發布時間: 2023-07-26 03:49:50

① 為什麼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$

希望我的回答能對你有所幫助。

熱點內容
滑板鞋腳本視頻 發布:2025-02-02 09:48:54 瀏覽:433
群暉怎麼玩安卓模擬器 發布:2025-02-02 09:45:23 瀏覽:557
三星安卓12彩蛋怎麼玩 發布:2025-02-02 09:44:39 瀏覽:744
電腦顯示連接伺服器錯誤 發布:2025-02-02 09:24:10 瀏覽:537
瑞芯微開發板編譯 發布:2025-02-02 09:22:54 瀏覽:147
linux虛擬機用gcc編譯時顯示錯誤 發布:2025-02-02 09:14:01 瀏覽:240
java駝峰 發布:2025-02-02 09:13:26 瀏覽:652
魔獸腳本怎麼用 發布:2025-02-02 09:10:28 瀏覽:538
linuxadobe 發布:2025-02-02 09:09:43 瀏覽:212
sql2000資料庫連接 發布:2025-02-02 09:09:43 瀏覽:726