VB.NET中怎么压缩ZIP文件

发布时间:2021-07-19 16:11:02 作者:Leah
来源:亿速云 阅读:820

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

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文件有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. 压缩文件tar和zip
  2. c# 文件压缩zip或将zip文件解压的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vb.net

上一篇:VB.NET中怎么实现网络监控

下一篇:python中的EasyOCR库是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》