VB.NET这样一款面向对象的编程语言,应用范围非常广泛,可以帮助开发人员打造一个稳定安全的开发框架。而且其对文件的处理方面也是非常强大的。这里就为大家介绍一下有关VB.NET压缩ZIP文件的相关方法。#t#
![](/upload/ad_content/xuanchuantu-6.jpg)
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://www.shufengxianlan.com/qtweb/news41/353541.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
创新互联