Use SharpZip for compression and decompression, and use sharpzip for compression and decompression
Use SharpZip for compression and decompression
Prepared by: Zuo qiuwen
When you are working on a project, we believe that we will often encounter the need to compress and decompress data streams or dataset byte [] or files, such as using webservice to update and download data, if the file is too large and is not compressed, it is believed that the transfer fails, I would like to share with you the use of a foreign open-source sharpzip class as the decompression class to decompress the code. Here we will make a summary for your reference. If you are interested, you can discuss and learn it together. Otherwise, you can skip it.
1. I have worked on a project before. This project has a function to synchronize data with the Headquarters. The client communicates with the Headquarters over the internet and transmits data. We use webservice, the passed data is dataset. At the beginning, I directly used dataset as a parameter for direct transmission. when the data is small, there is no problem. However, if the data is large, it basically fails. At this time, we must use compression. we compress it before transmission, and the server receives it, decompress it, and update it to the server database.
2,We can Http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx Download the source code.
The following figure shows the overall framework of my downloaded webservice:
3,SharpzipComplete code:
View Code
1) Here, the first part of the parameter is input in the form of an object, and the return value is byte [], and these parameters are used in teams.
2) the latter part can directly input byte [] as the parameter, compress it, and return byte []. Of course, both compression and decompression are used in pairs.
4,SharpzipThe function of the base class is mainly used for File compression. The following is the operation code for File compression:
1) For file operations, the following code