導航:首頁 > 文件處理 > zlib壓縮zip

zlib壓縮zip

發布時間:2022-06-27 12:22:44

❶ zip、bzip、lzma和ZLib如果極限壓縮的話,那種壓縮率最高除這幾種之外,還有沒有壓縮率更高的壓縮方式

LZMA和ZLIB壓縮測試:
輸出結果:
zlib壓縮:255ms size:5.08MB
zlib解壓:12ms
lzma壓縮:1974ms size:5.11MB
lzma解壓:399ms
LZMA.AS解壓:27381ms
這結果真讓人大失所望,不知道是不是測試的有問題,沒有更小,反而更大了。而且解壓時間長了幾十倍。as版的LZMA解壓時間更是無法接受。還是繼續用zlib吧。

ZLIB最高

❷ 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;
}

❸ 有沒有會使用zlib庫解壓zip包的

bool unzip(const char *DestName, const char *SrcName) { //解壓縮文件時的源buffer char* uSorceBuffer = new char[1024*1024*2]; memset(uSorceBuffer,0,sizeof(char)*1024*1024*2); FILE* fp3; //打開欲解壓文件的文件指針 FILE* fp4; //創...

java zlib 壓縮和解壓縮怎麼實現

使用java.util.zip.ZipFile 類及相關的類實現 如解壓縮 ZipInputStream zin = new ZipInputStream(in); ZipEntry entry = null; while((entry=zin.getNextEntry())!=null){ if(entry.isDirectory()||entry.getName().equals("..\\")) continue; ...

python怎樣壓縮和解壓縮ZIP文件

1、說明

python使用zipfile模塊來壓縮和解壓zip文件

2、代碼

importos,os.path
importzipfile

defzip_dir(dirname,zipfilename):
filelist=[]
ifos.path.isfile(dirname):
filelist.append(dirname)
else:
forroot,dirs,filesinos.walk(dirname):
fornameinfiles:
filelist.append(os.path.join(root,name))

zf=zipfile.ZipFile(zipfilename,"w",zipfile.zlib.DEFLATED)
fortarinfilelist:
arcname=tar[len(dirname):]
#printarcname
zf.write(tar,arcname)
zf.close()


defunzip_file(zipfilename,unziptodir):
ifnotos.path.exists(unziptodir):os.mkdir(unziptodir)
zfobj=zipfile.ZipFile(zipfilename)
fornameinzfobj.namelist():
name=name.replace('\','/')

ifname.endswith('/'):
os.mkdir(os.path.join(unziptodir,name))
else:
ext_filename=os.path.join(unziptodir,name)
ext_dir=os.path.dirname(ext_filename)
ifnotos.path.exists(ext_dir):os.mkdir(ext_dir)
outfile=open(ext_filename,'wb')
outfile.write(zfobj.read(name))
outfile.close()

if__name__=='__main__':
zip_dir(r'd:/python/test',r'd:/python/test.zip')
unzip_file(r'd:/python/test.zip',r'd:/python/test2')

執行結果

順利生成相應文件

3、備注

zip文件格式是通用的文檔壓縮標准,在zipfile模塊中,使用ZipFile類來操作zip文件,下面具體介紹一下:
class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]])

創建一個ZipFile對象,表示一個zip文件。參數file表示文件的路徑或類文件對象(file-like object);參數mode指示打開zip文件的模式,默認值為'r',表示讀已經存在的zip文件,也可以為'w'或'a','w'表示新建一個zip文檔或覆蓋一個已經存在的zip文檔,'a'表示將數據附加到一個現存的zip文檔中。參數compression表示在寫zip文檔時使用的壓縮方法,它的值可以是zipfile. ZIP_STORED 或zipfile. ZIP_DEFLATED。如果要操作的zip文件大小超過2G,應該將allowZip64設置為True。

ZipFile還提供了如下常用的方法和屬性:
ZipFile.getinfo(name):

獲取zip文檔內指定文件的信息。返回一個zipfile.ZipInfo對象,它包括文件的詳細信息。將在下面 具體介紹該對象。
ZipFile.infolist()

獲取zip文檔內所有文件的信息,返回一個zipfile.ZipInfo的列表。
ZipFile.namelist()

獲取zip文檔內所有文件的名稱列表。
ZipFile.extract(member[, path[, pwd]])

❻ 怎麼用zlib生成標准zip壓縮文件和解壓縮zip文件

你用的是什麼壓縮軟體?7-Zip? rar是Winrar的私有格式,其它壓縮軟體通常只能打開和解壓縮,而不能生成(否則必須得到Winrar的授權)。 其它你用7z格式就可以了,Winrar等都可以打開7z(7-Zip是開源軟體)。你發給別人7z格式,他不論裝什麼壓縮.

❼ python怎樣壓縮和解壓縮ZIP文件(轉)

榭梢越�姓庋�牟僮鰲2還� Python 中的 zipfile 模塊不能處理多卷的情況,不過這種情況並不多見,因此在通常情況下已經足夠使用了。下面我只是對一些基本的 zipfile 操作進行了記錄,足以應付大部分的情況了。zipfile 模塊可以讓你打開或寫入一個 zip 文件。比如:import zipfilez = zipfile.ZipFile('zipfilename', mode='r') 這樣就打開了一個 zip 文件,如果mode為'w'或'a'則表示要寫入一個 zip 文件。如果是寫入,則還可以跟上第三個參數: compression=zipfile.ZIP_DEFLATED 或 compression=zipfile.ZIP_STORED ZIP_DEFLATED是壓縮標志,如果使用它需要編譯了zlib模塊。而後一個只是用zip進行打包,並不壓縮。在打開了zip文件之後就可以根據需要是讀出zip文件的內容還是將內容保存到 zip 文件中。讀出zip中的內容很簡單,zipfile 對象提供了一個read(name)的方法。name為 zip文件中的一個文件入口,執行完成之後,將返回讀出的內容,你把它保存到想到的文件中即可。寫入zip文件有兩種方式,一種是直接寫入一個已經存在的文件,另一種是寫入一個字元串。對 於第一種使用 zipfile 對象的 write(filename, arcname, compress_type),後兩個參數是可以忽略的。第一個參數是文件名,第二個參數是表示在 zip 文件中的名字,如果沒有給出,表示使用與filename一樣的名字。compress_type是壓縮標志,它可以覆蓋創建 zipfile 時的參數。第二種是使用 zipfile 對象的 writestr(zinfo_or_arcname, bytes),第一個參數是zipinfo 對象或寫到壓縮文件中的壓縮名,第二個參數是字元串。使用這個方法可以動態的組織文件的內容。類源碼為:[python] view plain# coding:cp936 # Zfile.py # xxteach.com import zipfile import os.path import os class ZFile(object): def __init__(self, filename, mode='r', basedir=''): self.filename = filename self.mode = mode if self.mode in ('w', 'a'): self.zfile = zipfile.ZipFile(filename, self.mode, compression=zipfile.ZIP_DEFLATED) else: self.zfile = zipfile.ZipFile(filename, self.mode) self.basedir = basedir if not self.basedir: self.basedir = os.path.dirname(filename) def addfile(self, path, arcname=None): path = path.replace('//', '/') if not arcname: if path.startswith(self.basedir): arcname = path[len(self.basedir):] else: arcname = '' self.zfile.write(path, arcname) def addfiles(self, paths): for path in paths: if isinstance(path, tuple): self.addfile(*path) else: self.addfile(path) def close(self): self.zfile.close() def extract_to(self, path): for p in self.zfile.namelist(): self.extract(p, path) def extract(self, filename, path): if not filename.endswith('/'): f = os.path.join(path, filename) dir = os.path.dirname(f) if not os.path.exists(dir): os.makedirs(dir) file(f, 'wb').write(self.zfile.read(filename)) def create(zfile, files): z = ZFile(zfile, 'w') z.addfiles(files) z.close() def extract(zfile, path): z = ZFile(zfile) z.extract_to(path) z.close()

❽ Qt怎麼解壓zip的壓縮包

Qt調用zlib解壓縮的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
*返回值:將解壓出來的文件的絕對路徑保存在QStringList中
*
*參數:FileName是要解壓的zip文件的絕對路徑,QStringList其實也就是QList<QString> list類型用來保存解壓後各文件的路徑
*
*功能:解壓指定的zip文件並將解壓出來的文件的絕對路徑保存在list中
**/void WidgetSmallClass::slot_UncompressedFile( QString FileName ,QStringList & ListPic )
{
/**新建一個文件夾,用來保存解壓後的文件*/
QString UnpressPath = FileName.remove( ".zip" );
QDir dir;
dir.mkpath( UnpressPath );

unz_file_info64 FileInfo;
/**打開zip文件,這里記得一定要加上".zip",因為在上面的時候已經將".zip"移出去了。*/
unzFile zFile = unzOpen64( ( FileName + ".zip" ).toStdString().c_str() );
unz_global_info64 gi;
/**獲取文件數量*/
if ( unzGetGlobalInfo64( zFile, &gi ) == UNZ_OK )
{
int result;
for ( int i = 0; i < gi.number_entry; ++i )
{
char file[256] = { 0 };
char ext[256] = { 0 };
char com[1024] = { 0 };
if ( unzGetCurrentFileInfo64( zFile, &FileInfo, file, sizeof(file), ext, 256, com, 1024 ) != UNZ_OK )
{
;
}
if( !( FileInfo.external_fa & FILE_ATT

❾ 在Linux下,用zlib寫解壓文件的C程序,需要事先知道文件壓縮前的大小么怎麼得到

.gz文件的最後4位元組就是壓縮前的原長度(ISIZE),並且倒數第二個4位元組是壓縮前原buffer的CRC32冗餘校驗值。參見標准文檔 rfc1952 (https://tools.ietf.org/html/rfc1952).

❿ 擴展名為「.rar」和「.zip」的壓縮文件有什麼不同

一、發明者不同

1、rar:是一種專利文件格式,用於數據壓縮與歸檔打包,開發者為尤金·羅謝爾。

2、zip:是一種數據壓縮和文檔儲存的文件格式,原名Deflate,發明者為菲爾·卡茨。

二、特點不同

1、rar:RAR通常情況比ZIP壓縮比高,但壓縮/解壓縮速度較慢。分卷壓縮:壓縮後分割為多個文件。

2、zip:指出文件可以不經壓縮或者使用不同的壓縮演算法來存儲。然而,在實際上,ZIP幾乎差不多總是在使用卡茨(Katz)的DEFLATE演算法。


三、加密演算法不同

1、rar:RAR 2.0使用AES-128-cbc,(rar5.0以後為AES-256CBC)。之前RAR的加密演算法為私有。加入冗餘數據用於修復,在壓縮包本身損壞但恢復記錄夠多時可對損壞壓縮包進行恢復。

2、zip:持基於對稱加密系統的一個簡單的密碼,現在已知有嚴重的缺陷,已知明文攻擊,字典攻擊和暴力攻擊。ZIP也支持分卷壓縮。


閱讀全文

與zlib壓縮zip相關的資料

熱點內容
cnc手動編程銑圓 瀏覽:720
cad中幾種命令的意思 瀏覽:324
oraclelinux安裝目錄 瀏覽:133
安卓系統可以安裝編譯器嗎 瀏覽:570
javajson實體類 瀏覽:690
板加密鋼筋是否取代原鋼筋 瀏覽:66
學習編程的思路 瀏覽:230
app易語言post怎麼學 瀏覽:965
地梁的箍筋加密區位置 瀏覽:302
二分法排序程序及編譯結果 瀏覽:679
日語命令形和禁止型 瀏覽:285
安裝軟體用管理員解壓 瀏覽:505
編譯原理代碼塊 瀏覽:400
小孩可以用壓縮面膜嗎 瀏覽:14
錐形倒角怎麼計演算法 瀏覽:883
java合並鏈表 瀏覽:508
pic單片機編譯器 瀏覽:807
麗水四軸加工中心編程 瀏覽:692
國產系統怎麼解壓 瀏覽:554
戰雙程序員 瀏覽:485