您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關(guān)VB.NET中怎么壓縮ZIP文件,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
VB.NET壓縮ZIP文件代碼示例:
Public Function Decompress()
Function Decompress
(ByVal algo As String, ByVal
data() As Byte) As Byte()
Try
Dim sw As New Stopwatch
'---復(fù)制數(shù)據(jù)(壓縮的)到ms---
Dim ms As New MemoryStream(data)
Dim zipStream As Stream = Nothing
'---開(kāi)始秒表---
sw.Start()
'---使用存儲(chǔ)在ms中的數(shù)據(jù)解壓---
If algo = "Gzip" Then
zipStream = New GZipStream(ms,
CompressionMode.Decompress)
ElseIf algo = "Deflate" Then
zipStream = New DeflateStream(ms,
CompressionMode.Decompress, True)
End If
'---用來(lái)存儲(chǔ)解壓的數(shù)據(jù)---
Dim dc_data() As Byte
'---解壓的數(shù)據(jù)存儲(chǔ)于zipStream中;
'把它們提取到一個(gè)字節(jié)數(shù)組中---
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()
'---從一個(gè)流對(duì)象中檢索字節(jié)---
Dim data() As Byte
Dim totalCount As Integer = 0
Try
While True
'---逐漸地增加數(shù)據(jù)字節(jié)數(shù)組-的大小--
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
'---確保字節(jié)數(shù)組正確包含提取的字節(jié)數(shù)---
ReDim Preserve data(totalCount - 1)
Return data
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
看完上述內(nèi)容,你們對(duì)VB.NET中怎么壓縮ZIP文件有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。