問題的根源在於這些網友對於字元串和位元組流的概念非常的模糊,對文本文件和二進制文件的區別常常模稜兩可,其實位元組流可以表示所有的數據,二進制文件才是任何文件的本質。位元組流是一個位元組接一個位元組,並沒有結束符號
㈡ 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 NET 解壓縮多個文件
網上可找到相關的代碼,基於zlib庫來做的
謝謝,請採納。
㈣ 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$
希望我的回答能對你有所幫助。
㈤ zlib.dll 文件是什麼應該放在哪個文件夾
zlib.dll是ZLIB壓縮庫相關文件,用於Windows應用程序壓縮和解壓縮。
zlib.dll必需的鏈接文件,可放在Windows\System中,也可放在NeorageX所在的文件夾中
㈥ 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壓縮的文件
360軟體寶庫裡面下載個快壓就好了
㈧ 怎麼用zlib生成標准zip壓縮文件和解壓縮zip文件
你用的是什麼壓縮軟體?7-Zip? rar是Winrar的私有格式,其它壓縮軟體通常只能打開和解壓縮,而不能生成(否則必須得到Winrar的授權)。 其它你用7z格式就可以了,Winrar等都可以打開7z(7-Zip是開源軟體)。你發給別人7z格式,他不論裝什麼壓縮.