1
Public
Function Decompress()
Function Decompress(ByVal algo As String, ByVal data() As Byte) As Byte()
2
Try
3
Dim sw As New Stopwatch
4
'---复制数据(压缩的)到ms---
5
Dim ms As New MemoryStream(data)
6
Dim zipStream As Stream = Nothing
7![](/Images/OutliningIndicators/InBlock.gif)
8
'---开始秒表---
9
sw.Start()
10
'---使用存储在ms中的数据解压---
11![](/Images/OutliningIndicators/InBlock.gif)
12
If algo = "Gzip" Then
13
zipStream = New GZipStream(ms, CompressionMode.Decompress)
14
ElseIf algo = "Deflate" Then
15
zipStream = New DeflateStream(ms, CompressionMode.Decompress, True)
16
End If
17![](/Images/OutliningIndicators/InBlock.gif)
18
'---用来存储解压的数据---
19
Dim dc_data() As Byte
20![](/Images/OutliningIndicators/InBlock.gif)
21
'---解压的数据存储于zipStream中;
22
'把它们提取到一个字节数组中---
23
dc_data = RetrieveBytesFromStream(zipStream, data.Length)
24![](/Images/OutliningIndicators/InBlock.gif)
25
'---停止秒表---
26
sw.Stop()
27
lblMessage.Text = "Decompression completed. Time spent: " & sw.ElapsedMilliseconds & "ms" & _
28
", Original size: " & dc_data.Length
29
Return dc_data
30
Catch ex As Exception
31
MsgBox(ex.ToString)
32
Return Nothing
33
End Try
34
End Function
35![](/Images/OutliningIndicators/None.gif)
36![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public
Function RetrieveBytesFromStream()
Function RetrieveBytesFromStream( _
37
ByVal stream As Stream, ByVal bytesblock As Integer) As Byte()
38![](/Images/OutliningIndicators/InBlock.gif)
39
'---从一个流对象中检索字节---
40
Dim data() As Byte
41
Dim totalCount As Integer = 0
42
Try
43
While True
44![](/Images/OutliningIndicators/InBlock.gif)
45
'---逐渐地增加数据字节数组-的大小--
46
ReDim Preserve data(totalCount + bytesblock)
47
Dim bytesRead As Integer = stream.Read(data, totalCount, bytesblock)
48
If bytesRead = 0 Then
49
Exit While
50
End If
51
totalCount += bytesRead
52
End While
53
'---确保字节数组正确包含提取的字节数---
54
ReDim Preserve data(totalCount - 1)
55
Return data
56
Catch ex As Exception
57
MsgBox(ex.ToString)
58
Return Nothing
59
End Try
60
End Function
61![](/Images/OutliningIndicators/None.gif)
62
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
35
![](/Images/OutliningIndicators/None.gif)
36
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/InBlock.gif)
52
![](/Images/OutliningIndicators/InBlock.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/InBlock.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/InBlock.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
61
![](/Images/OutliningIndicators/None.gif)
62
![](/Images/OutliningIndicators/None.gif)