Online decompression using icsharpcode. sharpziplib. dll

Source: Internet
Author: User
Tags sharpdevelop

Icsharpcode. sharpziplib. dll is a GNU-based free library file with powerful functions.

: Http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx

The following describes how to decompress # ziplib under. net.

1. Bzip2

Add reference icsharpcode. sharpziplib. DLL to the \ sharpdevelop \ bin directory under the # develop installation directory. ThenProgramUse the using statement to include the Bzip2 class library.

Compression: compress uses the static Bzip2 method.

Its first parameter is the input stream represented by the file to be compressed. You can use the static openread method of system. Io. File.

The second parameter is the output stream represented by the compressed file to be created. You can use system. io. create a static file method. The compressed file name is the file name to be compressed plus the compression suffix. BZ (you can also use other file names ).

The third parameter is the block size to be compressed (generally an integer of 2048 ).

Decompress: Use the static decompress method of Bzip2.

Its first parameter is the input stream represented by the compressed file to be decompressed. You can use the static openread method of system. Io. File.

The second parameter is the output stream represented by the decompressed file to be created. You can use system. io. create a static file method, because the file name to be extracted is the compressed file name with the compressed file extension removed (you can also make it different from the compressed file name ).

Compile your program, and then input the Bzip2 File Name in command line mode (assuming the created C # file is Bzip2, the compressed file can be generated; enter the Bzip2-D file name, it will decompress the file (-D is used to indicate decompression, you can also use other symbols ).

Haha, the original compression can be so simple, and the compression effect can also be ah.
Using system;
Using system. IO;
Using icsharpcode. sharpziplib. Bzip2;

Class mainclass
{
Public static void main (string [] ARGs)
{
If (ARGs [0] = "-d") {// Extract
Bzip2.decompress (file. openread (ARGs [1]), file. Create (path. getfilenamewithoutextension (ARGs [1]);
} Else {// Compression
Bzip2.compress (file. openread (ARGs [0]), file. Create (ARGs [0] + ". BZ"), 4096 );
}
}
}

2. Gzip
Add reference icsharpcode. sharpziplib. DLL to the \ sharpdevelop \ bin directory under the # develop installation directory. Then, use the using statement in the program to include the gzip class library.

Gzip does not have a simple decompression method of Bzip2, so you can only use the stream method for decompression. For specific methods, see the description of the program.

Compile the program, and then enter the GZIP file name in the command line mode (assuming that the created C # file is gzip, the compressed file can be generated; enter the gzip-D file name, it will decompress the file (-D is used to indicate decompression, you can also use other symbols ).

Using system;
Using system. IO;

Using icsharpcode. sharpziplib. gzip;

Class mainclass
{
Public static void main (string [] ARGs)
{
If (ARGs [0] = "-d") {// Extract
Stream S = new gzipinputstream (file. openread (ARGs [1]);
// Generate a gzipinputstream stream to open the compressed file.
// Because gzipinputstream is derived from stream, it can be assigned to stream.
// Its constructor parameter is a file stream representing the compressed file to be decompressed
Filestream FS = file. Create (path. getfilenamewithoutextension (ARGs [1]);
// Generate a file stream, which is used to generate the decompressed File
// You can use the static function create of system. Io. File to generate a file stream.
Int size = 2048; // specify the size of the compressed block, which is generally a multiple of 2048.
Byte [] writedata = new byte [size]; // specify the buffer size
While (true ){
Size = S. Read (writedata, 0, size); // read a compressed Block
If (size> 0 ){
FS. Write (writedata, 0, size); // write the file stream represented by the decompressed File
} Else {
Break; // if the end of the compressed file is read, it ends.
}
}
S. Close ();
} Else {// Compression
Stream S = new gzipoutputstream (file. Create (ARGs [0] + ". GZ "));
// Generate a gzipoutputstream stream to generate a compressed file.
// Because gzipoutputstream is derived from stream, it can be assigned to stream.
Filestream FS = file. openread (ARGs [0]);
/Generate a file stream to open the file to be compressed
// You can use the static function openread of system. Io. File to generate a file stream.
Byte [] writedata = new byte [fs. Length];
// Specify the buffer size
FS. Read (writedata, 0, (INT) fs. Length );
// Read the file
S. Write (writedata, 0, writedata. Length );
// Write the compressed file
S. Close ();
// Close the file
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.