VB.NET中怎么压缩ZIP文件
今天就跟大家聊聊有关VB.NET中怎么压缩ZIP文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
成都创新互联公司专业IDC数据服务器托管提供商,专业提供成都服务器托管,服务器租用,重庆服务器托管,重庆服务器托管,成都多线服务器托管等服务器托管服务。
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文件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
网站名称:VB.NET中怎么压缩ZIP文件
本文网址:http://pwwzsj.com/article/jiship.html