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

c解壓縮文件

發布時間: 2023-02-09 12:20:06

A. 請問如何用C語言寫一個輸入路徑,壓縮解壓文件的代碼 能分享一下源碼嗎 我想學習一下

這個如果是在linux下面的話可以調用系統自帶的壓縮工具

大致給你說一下步驟吧。具體還是靠你自己實現

  1. 輸入路徑。這個就不多說。scanf

  2. 分析輸入的文件路徑,或者後綴名。然後調用 tar gzip等壓縮,解壓縮命令。

壓縮的演算法如果有興趣你也可以自己去實現一下。不過不容易實現。還是調用系統自帶的壓縮命令吧。

B. 如何用C語言編寫暴力破解壓縮文件解壓密碼的程序

由於有一個重要的Rar文件,極需解開,首先試用了ARPC,但是解壓的速度極慢,每秒只有30個左右,所以斷了窮舉破解的念頭,卻仍不死心,因為我從不崇尚窮舉破解的方法,除非每秒可以跑幾千萬次的,我或許可以一試,所以決定研究一下Winrar3.x密碼演算法,以期是否可以破解該密碼。查看了網路上的資料,包括看雪FAQ里的回答,都聲稱只能用窮舉法破解,起先並不理解,但通過研究,我理解了看雪前輩們在FAQ里所說的原因,不禁讓我佩服

Winrar加密思路的成熟。雖然研究的結果沒有什麼新意,但我還是決定把我的研究結果與大家一起分享,為那些仍然以為winrar密碼可以象破解注冊碼一樣的,通過修改winrar彈出框之類的更改文件流程指向可以達到跳過密碼檢驗的朋友,做一個簡要的說明。

一、Rar文件生成的流程。
Winrar加密文件時,總的分兩個步驟:
1:先把源文件壓縮,壓成一段數據段。
2:再將壓縮完的數據段加密。
對於同一個源文件來說,不進行加密,壓縮完,其rar文件中的數據段是一模一樣的。但是如果對同一個源文件來說,即使使用同一個密碼,加密完rar文件中的數據段是不一樣的,這是由於加密的密鑰是依賴於一個Salt(8個位元組的密鑰,用來加密時使用,存放在rar文件頭中里)
所以要解密rar加密文件關鍵在於數據解密這一步,那我們接下來研究一下如何加密的。
二、加密「壓縮完的數據段」的流程
1、獲取密鑰:
將明文的密碼與Salt一起,通過HASH演算法,生成兩個16位元組的密鑰。(一個是KEY(AES演算法的參數),一個是initVector)
2、以Key和initVector來加密壓縮數據:
這里,是一個循環加密的結構,每16位元組作為一個塊,進行加密(這可能正是為什麼加密完的文件長度總為16倍數的原因)。加密採用AES演算法(RAR採用的是AES的rijndael的標准應用)。這里注意:AES加密前,有一個異或運算,是先將每16位元組塊與上一個16位元組塊加密結果進行異或,然後再進行AES演算法的。我用一個簡單的示意代碼看說明:
;===============================================
packblock[0]=packblock[i]^initVector
encryptBlock[0]=AES(packblock[0]) ;(KEY為AES的密鑰)
for i=1to 塊數量-1
packblock[i]=packblock[i]^encryptBlock[i-1]
encryptBlock[i]=AES(packblock[i]);(KEY為AES的密鑰)
next
;packblock[i]表示壓縮完的每16位元組數據
;encryptBlock[i]表示加密完的每16位元組數據
;===============================================
三、解密的過程
由於AES演算法是對稱的,所以解密的過程,是加密過程的逆運算。但解密時AES演算法過程與加密所用的不一樣(是因為解密過程中由KEY生成的子密鑰表不一樣)。仍然需要我們將密碼輸入,與salt一起生成兩個16位元組密鑰,KEY和initVector。

;===============================================
packblock[0]=AES1(encryptBlock[0]) ;(KEY為AES的密鑰)
packblock[0]=packblock[i]^initVector
for i=1to 塊數量-1
packblock[i]=AES1(encryptBlock[i]) ;(KEY為AES的密鑰)
packblock[i]=packblock[i]^encryptBlock[i-1]

next
;===============================================
那判斷密碼是否正確的在什麼地方呢?
解密的過程是解密後的數據塊進行解壓縮,然後解成源文件,對該文件進行CRC校驗,存在RAR文件中的源文件CRC校驗碼比較,相同則密碼正確,不相同則密碼錯誤。

四、無法秒破的原因
從上面,我們了解了RAR文件的整體思路。地球人都知道,解密時,肯定有個步驟是來判斷密碼的正確與否。而且,依據以往的經驗,我們也許可以將某些判斷的點移動,那樣可以縮減破解的流程思路。那RAR的這一步在哪裡?它把校驗放在了最後的一步。如果要秒破,我們該怎麼做泥?至少我認為目前是不可能的。
我們從解密過程逆反過來看看:
1、CRC檢驗這一塊修改跳轉?根本毫無意義,因為它已經是最後一步了。你可以修改RAR文件頭的CRC值,你可以將它改得和你用任意密碼解壓出來的文件CRC值一樣,但你的文件根本就不是原來的文件了。可能已經完全面目全非了。所以,對這一過程不可行。CRC校驗本身是不可逆的
2、那麼把判斷提前到壓縮完的數據?
解壓的時候,有沒有什麼來判斷壓縮數據是否正確?壓縮完的數據,有沒有固定的特徵,是否可以做為解壓的判斷,在這一步里,我們也無法找到有效的可用的固定特徵。因為這一步涉及到RAR的壓縮演算法。即使一個源文件,即使你的文件前一部分是完全相同的,只對後面的部分進行改過,那麼壓縮完,數據也是完全一樣的。因為壓縮完的數據首先是一個壓縮表,後面是編碼。文件不一樣,掃描完的壓縮表也不一樣,編碼又是依賴於壓縮表,所以,這里頭找不到壓縮完的數據有任何的固定特徵可以用來判斷的。
不管壓縮數據是什麼樣的,Winrar都一如既往地進行解壓,沒有進行壓縮數據是否有效的判斷。
3、那假如我們破解了AES了泥?
由於AES只依賴於KEY,如果AES演算法被破解了,我們知道了KEY,我們可以解出壓縮完的數據,但是這里有一個問題,還有一個initVector密鑰,用來第一個16位元組塊的異或,你沒有initVector參數,你第一個16位元組塊的數據便無法解得出來。
4、那就只能從第一步Hash的演算法入手
即使你能破解hash,但hash後的結果泥?沒有結果,你怎麼返推密碼。

所以綜上,我發現rar的加密是由hash和AES兩種演算法互相牽制,而兩種演算法當前都無法破解,至少目前還沒有辦法秒破,也理解了看雪高手講的道理。
五、對窮舉提高演算法效率的一些設想。
我用匯編寫完了RAR窮舉解密的演算法模塊,但是如何提高效率,優化窮舉的速度泥?我有如下的想法:
1、從壓縮數據里找尋特徵,省掉解壓縮、CRC檢驗代碼和生成initVector生成代碼。目前,通過多次實驗,我找到的一個特徵(不知道這個是否正確),即解密完的最後一個16位元組塊的最後一個位元組必須為0。因為經過多次的試驗,我發現有加密的數據段長度都會比未加密前的數據長,那麼,最後一個

16個位元組的數據塊解密完,多出的部分就都為0,但多出幾個位元組泥?多次實驗,長度不一,我試想著從加密數據段最後一個16個位元組塊著手,只解這一塊,看是否一個位元組為0,這樣,只解密16個位元組的數據,來大大提高效率?如果能進行到這一步了,再通過解全部數據,進行CRC校驗的判斷。
2、如果第一個特徵不成立的話,針對特定格式的壓縮文件,比如doc、jpg等,部分數據固定,壓縮完的數據是否存在相互牽制的數據?從而把判斷提前,這一步,我不知道如何找到壓縮完的數據是否存在相互牽制的數據。

C. 如何用C語言編寫暴力破解壓縮文件解壓密碼

winrar有個命令行解壓
rar.exe -y x -p密碼 "c:\test.rar" "d:\"
只需要在C語言里把要爆破用的密碼生成或者從別的字典導入
然後拼接成命令循環執行就好了

D. 用C語言簡單演示如何藉助zlib庫實現文件的壓縮和解壓縮

問題的根源在於這些網友對於字元串和位元組流的概念非常的模糊,對文本文件和二進制文件的區別常常模稜兩可,其實位元組流可以表示所有的數據,二進制文件才是任何文件的本質。位元組流是一個位元組接一個位元組,並沒有結束符號,所以需要給它一個長度信息。二進制文件是一個位元組接一個位元組,並沒有換行符之類的。文件壓縮的時候,可以通過源文件的長度自動計算緩沖區的長度,壓縮後寫入目標文件之前,需先保留源文件和目標數據的長度作為解壓縮的依據,參考如下代碼:#include #include #include 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; }文件解壓縮的時候,可以通過保留信息得到緩沖區和數據流的大小,這樣解壓縮後直接保存即可,參考如下代碼:#include #include #include int main(int argc, char* argv[]) { FILE* file; uLong flen; unsigned char* fbuf = NULL; uLong ulen; unsigned char* ubuf = NULL; /* 通過命令行參數將srcfile文件的數據解壓縮後存放到dstfile文件中 */ if(argc < 3) { printf("Usage: zudemo srcfile dstfile\n"); return -1; } if((file = fopen(argv[1], "rb")) == NULL) { printf("Can\'t open %s!\n", argv[1]); return -1; } /* 裝載源文件數據到緩沖區 */ fread(&ulen, sizeof(uLong), 1, file); /* 獲取緩沖區大小 */ fread(&flen, sizeof(uLong), 1, file); /* 獲取數據流大小 */ 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); /* 解壓縮數據 */ if((ubuf = (unsigned char*)malloc(sizeof(unsigned char) * ulen)) == NULL) { printf("No enough memory!\n"); fclose(file); return -1; } if(uncompress(ubuf, &ulen, fbuf, flen) != Z_OK) { printf("Uncompress %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(ubuf, sizeof(unsigned char), ulen, file); fclose(file); free(fbuf); free(ubuf); return 0; }

E. C++怎麼實現解壓RAR或者ZIP文件

用Zlib庫,下載地址: http://download.chinaunix.net/download/0013000/12241.shtml
BOOL ZipCompress(LPCTSTR lpszSourceFiles, LPCTSTR lpszDestFile);
BOOL ZipExtract(LPCTSTR lpszSourceFile, LPCTSTR lpszDestFolder); 要引入的源文件 ZLib 主目錄下的代碼,除 minigzip.c、example.c 外; contrib\minizip 下的代碼,除 minizip.c、miniunz.c 外。壓縮相關: zipOpen64 zipClose zipOpenNewFileInZip zipCloseFileInZip zipWriteInFileInZip解壓相關: unzOpen64 unzClose unzGetGlobalInfo64 unzGoToNextFile unzGetCurrentFileInfo64 unzOpenCurrentFile unzCloseCurrentFile unzReadCurrentFile

F. (20分)用C語言編譯的文件壓縮解壓縮程序

是用霍夫曼樹做的
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
struct head
{
unsigned char b; /*the charactor*/
long count; /*the frequency*/
long parent,lch,rch; /*make a tree*/
char bits[256]; /*the haffuman code*/
}
header[512],tmp;

void compress()
{
char filename[255],outputfile[255],buf[512];
unsigned char c;
long i,j,m,n,f;
long min1,pt1,flength;
FILE *ifp,*ofp;
printf("source filename:");
gets(filename);
ifp=fopen(filename,"rb");
if(ifp==NULL)
{
printf("source file open error!\n");
return;
}
printf("destination filename:");
gets(outputfile);
ofp=fopen(outputfile,"wb");
if(ofp==NULL)
{
printf("destination file open error!\n");
return;
}
flength=0;
while(!feof(ifp))
{
fread(&c,1,1,ifp);
header[c].count++;
flength++;
}
flength--;
header[c].count--;
for(i=0;i<512;i++)
{
if(header[i].count!=0) header[i].b=(unsigned char)i;
else header[i].b=0;
header[i].parent=-1;
header[i].lch=header[i].rch=-1;
}
for(i=0;i<256;i++)
{
for(j=i+1;j<256;j++)
{
if(header[i].count<header[j].count)
{
tmp=header[i];
header[i]=header[j];
header[j]=tmp;
}
}
}
for(i=0;i<256;i++) if(header[i].count==0) break;
n=i;
m=2*n-1;
for(i=n;i<m;i++)
{
min1=999999999;
for(j=0;j<i;j++)
{
if(header[j].parent!=-1) continue;
if(min1>header[j].count)
{
pt1=j;
min1=header[j].count;
continue;
}
}
header[i].count=header[pt1].count;
header[pt1].parent=i;
header[i].lch=pt1;
min1=999999999;
for(j=0;j<i;j++)
{
if(header[j].parent!=-1) continue;
if(min1>header[j].count)
{
pt1=j;
min1=header[j].count;
continue;
}
}
header[i].count+=header[pt1].count;
header[i].rch=pt1;
header[pt1].parent=i;
}
for(i=0;i<n;i++)
{
f=i;
header[i].bits[0]=0;
while(header[f].parent!=-1)
{
j=f;
f=header[f].parent;
if(header[f].lch==j)
{
j=strlen(header[i].bits);
memmove(header[i].bits+1,header[i].bits,j+1);
header[i].bits[0]='0';
}
else
{
j=strlen(header[i].bits);
memmove(header[i].bits+1,header[i].bits,j+1);
header[i].bits[0]='1';
}
}
}
fseek(ifp,0,SEEK_SET);
fwrite(&flength,sizeof(int),1,ofp);
fseek(ofp,8,SEEK_SET);
buf[0]=0;
f=0;
pt1=8;
while(!feof(ifp))
{
c=fgetc(ifp);
f++;
for(i=0;i<n;i++)
{
if(c==header[i].b) break;
}
strcat(buf,header[i].bits);
j=strlen(buf);
c=0;
while(j>=8)
{
for(i=0;i<8;i++)
{
if(buf[i]=='1') c=(c<<1)|1;
else c=c<<1;
}
fwrite(&c,1,1,ofp);
pt1++;
strcpy(buf,buf+8);
j=strlen(buf);
}
if(f==flength) break;
}
if(j>0)
{
strcat(buf,"00000000");
for(i=0;i<8;i++)
{
if(buf[i]=='1') c=(c<<1)|1;
else c=c<<1;
}
fwrite(&c,1,1,ofp);
pt1++;
}
fseek(ofp,4,SEEK_SET);
fwrite(&pt1,sizeof(long),1,ofp);
fseek(ofp,pt1,SEEK_SET);
fwrite(&n,sizeof(long),1,ofp);
for(i=0;i<n;i++)
{
fwrite(&(header[i].b),1,1,ofp);
c=strlen(header[i].bits);
fwrite(&c,1,1,ofp);
j=strlen(header[i].bits);
if(j%8!=0)
{
for(f=j%8;f<8;f++)
strcat(header[i].bits,"0");
}
while(header[i].bits[0]!=0)
{
c=0;
for(j=0;j<8;j++)
{
if(header[i].bits[j]=='1') c=(c<<1)|1;
else c=c<<1;
}
strcpy(header[i].bits,header[i].bits+8);
fwrite(&c,1,1,ofp);
}
}
fclose(ifp);
fclose(ofp);
printf("compress successfully!\n");
return;
}
void uncompress()
{
char filename[255],outputfile[255],buf[255],bx[255];
unsigned char c;
long i,j,m,n,f,p,l;
long flength;
FILE *ifp,*ofp;
printf("source filename:");
gets(filename);
ifp=fopen(filename,"rb");
if(ifp==NULL)
{
printf("source file open error!\n");
return;
}
printf("destination filename:");
gets(outputfile);
ofp=fopen(outputfile,"wb");
if(ofp==NULL)
{
printf("destination file open error!\n");
return;
}
fread(&flength,sizeof(long),1,ifp);
fread(&f,sizeof(long),1,ifp);
fseek(ifp,f,SEEK_SET);
fread(&n,sizeof(long),1,ifp);
for(i=0;i<n;i++)
{
fread(&header[i].b,1,1,ifp);
fread(&c,1,1,ifp);
p=(long)c;
header[i].count=p;
header[i].bits[0]=0;
if(p%8>0) m=p/8+1;
else m=p/8;
for(j=0;j<m;j++)
{
fread(&c,1,1,ifp);
f=c;
itoa(f,buf,2);
f=strlen(buf);
for(l=8;l>f;l--)
{
strcat(header[i].bits,"0");
}
strcat(header[i].bits,buf);
}
header[i].bits[p]=0;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strlen(header[i].bits)>strlen(header[j].bits))
{
tmp=header[i];
header[i]=header[j];
header[j]=tmp;
}
}
}
p=strlen(header[n-1].bits);
fseek(ifp,8,SEEK_SET);
m=0;
bx[0]=0;
while(1)
{
while(strlen(bx)<(unsigned int)p)
{
fread(&c,1,1,ifp);
f=c;
itoa(f,buf,2);
f=strlen(buf);
for(l=8;l>f;l--)
{
strcat(bx,"0");
}
strcat(bx,buf);
}
for(i=0;i<n;i++)
{
if(memcmp(header[i].bits,bx,header[i].count)==0) break;
}
strcpy(bx,bx+header[i].count);
c=header[i].b;
fwrite(&c,1,1,ofp);
m++;
if(m==flength) break;
}
fclose(ifp);
fclose(ofp);
printf("Uncompress successfully!\n");
return;
}
int main()
{
int c;
printf("1--Compress file\n");
printf("2--Uncompress file\n");
printf("Select 1 or 2:");
c=getch();
printf("%c\n",c);
if(c=='1') compress();
else if(c=='2') uncompress();
return 0;
}

G. 如何用C語言解壓縮文件

如果你自己設計演算法,就另當別論,如果想利用第3方的演算法,我推薦用zlib,生成的壓縮包是流行的zip格式.源代碼很好找(www.zlib.net)

H. 如何用CZip/CUnzip類壓縮/解壓縮文件

Zip/Unzip dll源代碼下載 范常式序下載 lishixin/Article/program/c/201401/30257

I. c#壓縮解壓 文件夾

我在做項目的時候需要將文件進行壓縮和解壓縮,於是就從http://www.icsharpcode.net下載了關於壓縮和解壓縮的源碼,但是下載下來後,面對這么多的代碼,一時不知如何下手。只好耐下心來,慢慢的研究,總算找到了門路。針對自己的需要改寫了文件壓縮和解壓縮的兩個類,分別為ZipClass和UnZipClass。其中碰到了不少困難,就決定寫出來壓縮和解壓的程序後,一定把源碼貼出來共享,讓首次接觸壓縮和解壓縮的朋友可以少走些彎路。下面就來解釋如何在C#里用http://www.icsharpcode.net下載的SharpZipLib進行文件的壓縮和解壓縮。

首先需要在項目里引用SharpZipLib.dll。然後修改其中的關於壓縮和解壓縮的類。實現源碼如下:

/// <summary>
/// 壓縮文件
/// </summary>

using System;
using System.IO;

using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;

namespace Compression
{
public class ZipClass
{

public void ZipFile(string FileToZip, string ZipedFile ,int CompressionLevel, int BlockSize)
{
//如果文件沒有找到,則報錯
if (! System.IO.File.Exists(FileToZip))
{
throw new System.IO.FileNotFoundException("The specified file " + FileToZip + " could not be found. Zipping aborderd");
}

System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip,System.IO.FileMode.Open , System.IO.FileAccess.Read);
System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
ZipEntry ZipEntry = new ZipEntry("ZippedFile");
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(CompressionLevel);
byte[] buffer = new byte[BlockSize];
System.Int32 size =StreamToZip.Read(buffer,0,buffer.Length);
ZipStream.Write(buffer,0,size);
try
{
while (size < StreamToZip.Length)
{
int sizeRead =StreamToZip.Read(buffer,0,buffer.Length);
ZipStream.Write(buffer,0,sizeRead);
size += sizeRead;
}
}
catch(System.Exception ex)
{
throw ex;
}
ZipStream.Finish();
ZipStream.Close();
StreamToZip.Close();
}

public void ZipFileMain(string[] args)
{
string[] filenames = Directory.GetFiles(args[0]);

Crc32 crc = new Crc32();
ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));

s.SetLevel(6); // 0 - store only to 9 - means best compression

foreach (string file in filenames)
{
//打開壓縮文件
FileStream fs = File.OpenRead(file);

byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(file);

entry.DateTime = DateTime.Now;

// set Size and the crc, because the information
// about the size and crc should be stored in the header
// if it is not set it is automatically written in the footer.
// (in this case size == crc == -1 in the header)
// Some ZIP programs have problems with zip files that don't store
// the size and crc in the header.
entry.Size = fs.Length;
fs.Close();

crc.Reset();
crc.Update(buffer);

entry.Crc = crc.Value;

s.PutNextEntry(entry);

s.Write(buffer, 0, buffer.Length);

}

s.Finish();
s.Close();
}
}
}

現在再來看看解壓文件類的源碼

/// <summary>
/// 解壓文件
/// </summary>

using System;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;

using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;

namespace DeCompression
{
public class UnZipClass
{
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));

ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{

string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);

//生成解壓目錄
Directory.CreateDirectory(directoryName);

if (fileName != String.Empty)
{
//解壓文件到指定的目錄
FileStream streamWriter = File.Create(args[1]+theEntry.Name);

int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}

streamWriter.Close();
}
}
s.Close();
}
}
}

有了壓縮和解壓縮的類以後,就要在窗體里調用了。怎麼?是新手,不會調用?Ok,接著往下看如何在窗體里調用。

首先在窗體里放置兩個命令按鈕(不要告訴我你不會放啊~),然後編寫以下源碼

/// <summary>
/// 調用源碼
/// </summary>

private void button2_Click_1(object sender, System.EventArgs e)
{
string []FileProperties=new string[2];
FileProperties[0]="C:\\unzipped\\";//待壓縮文件目錄
FileProperties[1]="C:\\zip\\a.zip"; //壓縮後的目標文件
ZipClass Zc=new ZipClass();
Zc.ZipFileMain(FileProperties);
}

private void button2_Click(object sender, System.EventArgs e)
{
string []FileProperties=new string[2];
FileProperties[0]="C:\\zip\\test.zip";//待解壓的文件
FileProperties[1]="C:\\unzipped\\";//解壓後放置的目標目錄
UnZipClass UnZc=new UnZipClass();
UnZc.UnZip(FileProperties);
}

好了,到此為止,如何壓縮和解壓縮的類都已經完成了,需要的朋友直接拿走調吧。

J. 想在linux上用C實現gzip壓縮與解壓縮,有沒有相關庫函數可以調用

linux下只支持tar.gz和tgz等格式.zip它是讀取不出來的!請您先用u盤把linux系統下的文件拷貝到windows系統下進行壓縮和解壓處理,處理完成放到u盤里帶到linux系統中,不過我不覺得linux系統會支持zip
bz2格式...
建議您用虛擬機載入linux系統

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:712
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:974
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:686
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:837
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:743
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1085
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:314
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:194
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:882
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:840