In. NET 2.0, you can use sharpziplib, an open source DLL, to easily decompress ZIP files and GZ files.
You can download sharpziplib here.
The following describes the specific code:
1. Unzip the ZIP file:
Namespace: icsharpcode. sharpziplib. Zip
Private Static void uncompresszip (string file, string DIR) <br/>{< br/> try <br/>{< br/> If (! Directory. exists (DIR) <br/> directory. createdirectory (DIR); </P> <p> zipinputstream S = new zipinputstream (file. openread (File); </P> <p> zipentry theentry; <br/> while (theentry = S. getnextentry ())! = NULL) <br/>{< br/> string directoryname = path. getdirectoryname (theentry. name); <br/> string filename = path. getfilename (theentry. name); </P> <p> If (directoryname! = String. Empty) <br/> directory. createdirectory (DIR + directoryname); </P> <p> If (filename! = String. empty) <br/>{< br/> filestream streamwriter = file. create (DIR + theentry. name); </P> <p> int size = 2048; <br/> byte [] DATA = new byte [2048]; <br/> while (true) <br/>{< br/> size = S. read (data, 0, Data. length); <br/> If (size> 0) <br/>{< br/> streamwriter. write (data, 0, size); <br/>}< br/> else <br/>{< br/> break; <br/>}</P> <p> streamwriter. close (); <br/>}< br/> S. close (); <br/>}< br/> catch (exception ex) <br/>{< br/> console. writeline (ex. message); <br/>}< br/>}
Where:
File indicates the path and file name of the ZIP file.
Dir indicates the decompressed path.
2. Decompress GZ:
Namespace: icsharpcode. sharpziplib. Gzip
Private Static void uncompressgzip (string file, string DIR) <br/>{< br/> try <br/>{< br/> If (! Directory. exists (path. getdirectoryname (DIR) <br/> directory. createdirectory (path. getdirectoryname (DIR); </P> <p> gzipinputstream S = new gzipinputstream (file. openread (File); <br/> filestream streamwriter = file. create (DIR); </P> <p> int size = 2048; <br/> byte [] DATA = new byte [2048]; <br/> while (true) <br/>{< br/> size = S. read (data, 0, Data. length); <br/> If (size> 0) <br/>{< br/> streamwriter. write (data, 0, size); <br/>}< br/> else <br/>{< br/> break; <br/>}</P> <p> streamwriter. close (); <br/>}< br/> catch (exception ex) <br/>{< br/> console. writeline (ex. message); <br/>}< br/>}
Where:
File indicates the path and file name of the GZ file.
Dir indicates the decompressed path and file name.
PS: in Windows NT, you can use the 7-zip tool to compress the file into the GZ format.