Writing the following code makes me very laborious.
. Net provides the Compression example of System. IO. Compression. GZipStream, but there is no good code for decompression.
However, after extracting a section and compressing it, it becomes 1.16 MB, while the original data is 15 MB,
It took up to 3000 milliseconds!
I don't know why. Please kindly advise me!
First paste the Code:
1 1. public object DeCompression(byte[] request)
2 2. {
3 3. object ob = new object();
4 4. Stream sourceStream = new MemoryStream(request);
5 5. System.IO.Compression.GZipStream zipStream = new System.IO.Compression.GZipStream(
6 6. sourceStream,
7 7. System.IO.Compression.CompressionMode.Decompress);
8 8. byte[] buffer = new byte[20480];
9 9. byte[] bt = new byte[0];
10 10. int iread = 0;
11 11. do
12 12. {
13 13. iread = zipStream.Read(buffer, 0, 20480);
14 14. byte[] bswap = new byte[bt.Length + buffer.Length];
15 15. Buffer.BlockCopy(bt, 0, bswap, 0, bt.Length);
16 16. Buffer.BlockCopy(buffer, 0, bswap, bt.Length, buffer.Length);
17 17. bt = bswap;
18 18. bswap = null;
19 19. GC.Collect();
20 20. } while (iread > 0);
21 21. zipStream.Close();
22 22. sourceStream.Close();
23 23. MemoryStream ms = new MemoryStream(bt);
24 24. ob = DeSerializeBinary(ms);
25 25. ms.Close();
26 26. return ob;
27 27. }