您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關VB.NET中怎么壓縮ZIP文件,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
VB.NET壓縮ZIP文件代碼示例:
Public Function Decompress()
Function Decompress
(ByVal algo As String, ByVal
data() As Byte) As Byte()
Try
Dim sw As New Stopwatch
'---復制數據(壓縮的)到ms---
Dim ms As New MemoryStream(data)
Dim zipStream As Stream = Nothing
'---開始秒表---
sw.Start()
'---使用存儲在ms中的數據解壓---
If algo = "Gzip" Then
zipStream = New GZipStream(ms,
CompressionMode.Decompress)
ElseIf algo = "Deflate" Then
zipStream = New DeflateStream(ms,
CompressionMode.Decompress, True)
End If
'---用來存儲解壓的數據---
Dim dc_data() As Byte
'---解壓的數據存儲于zipStream中;
'把它們提取到一個字節數組中---
dc_data = RetrieveBytesFromStream
(zipStream, data.Length)
'---停止秒表---
sw.Stop()
lblMessage.Text = "Decompression
completed. Time spent: " & sw.
ElapsedMilliseconds & "ms" & _
", Original size: " & dc_data.Length
Return dc_data
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
Public Function RetrieveBytes
FromStream()Function Retrieve
BytesFromStream( _
ByVal stream As Stream, ByVal
bytesblock As Integer) As Byte()
'---從一個流對象中檢索字節---
Dim data() As Byte
Dim totalCount As Integer = 0
Try
While True
'---逐漸地增加數據字節數組-的大小--
ReDim Preserve data(totalCount
+ bytesblock)
Dim bytesRead As Integer =
stream.Read(data, totalCount, bytesblock)
If bytesRead = 0 Then
Exit While
End If
totalCount += bytesRead
End While
'---確保字節數組正確包含提取的字節數---
ReDim Preserve data(totalCount - 1)
Return data
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
看完上述內容,你們對VB.NET中怎么壓縮ZIP文件有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。