VB.NET中怎么压缩ZIP文件

今天就跟大家聊聊有关VB.NET中怎么压缩ZIP文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

成都创新互联公司专业IDC数据服务器托管提供商,专业提供成都服务器托管,服务器租用,重庆服务器托管重庆服务器托管,成都多线服务器托管等服务器托管服务。

VB.NET压缩ZIP文件代码示例:

  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. '---开始秒表---  

  8. sw.Start()  

  9. '---使用存储在ms中的数据解压---  

  10. If algo = "Gzip" Then  

  11. zipStream = New GZipStream(ms, 
    CompressionMode.Decompress)  

  12. ElseIf algo = "Deflate" Then  

  13. zipStream = New DeflateStream(ms, 
    CompressionMode.Decompress, True)  

  14. End If  

  15. '---用来存储解压的数据---  

  16. Dim dc_data() As Byte  

  17. '---解压的数据存储于zipStream中;   

  18. '把它们提取到一个字节数组中---  

  19. dc_data = RetrieveBytesFromStream
    (zipStream, data.Length)  

  20. '---停止秒表---  

  21. sw.Stop()  

  22. lblMessage.Text = "Decompression 
    completed. Time spent: " & sw.
    ElapsedMilliseconds & "ms" & _  

  23. ", Original size: " & dc_data.Length  

  24. Return dc_data  

  25. Catch ex As Exception  

  26. MsgBox(ex.ToString)  

  27. Return Nothing  

  28. End Try  

  29. End Function  

  30. Public Function RetrieveBytes
    FromStream()Function Retrieve
    BytesFromStream( _  

  31. ByVal stream As Stream, ByVal 
    bytesblock As Integer) As Byte()  

  32. '---从一个流对象中检索字节---  

  33. Dim data() As Byte  

  34. Dim totalCount As Integer = 0 

  35. Try  

  36. While True  

  37. '---逐渐地增加数据字节数组-的大小--  

  38. ReDim Preserve data(totalCount 
    + bytesblock)  

  39. Dim bytesRead As Integer = 
    stream.Read(data, totalCount, bytesblock)  

  40. If bytesRead = 0 Then  

  41. Exit While  

  42. End If  

  43. totalCount += bytesRead  

  44. End While  

  45. '---确保字节数组正确包含提取的字节数---  

  46. ReDim Preserve data(totalCount - 1)  

  47. Return data  

  48. Catch ex As Exception  

  49. MsgBox(ex.ToString)  

  50. Return Nothing  

  51. End Try  

  52. End Function 

看完上述内容,你们对VB.NET中怎么压缩ZIP文件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。

网站栏目:VB.NET中怎么压缩ZIP文件
标题链接:https://www.cdcxhl.com/article8/jiship.html

成都网站建设公司_创新互联,为您提供品牌网站设计定制开发手机网站建设搜索引擎优化Google虚拟主机

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司