VB.NET用SharpZipLib解压.gzip文件
各位老师好,我打算用SharpZipLib解压.gzip文件,我修改了网上的一段程序,可以解压.zip:
Public Shared Sub DecompressZip(ByVal zipPath As String, ByVal folderPath As String)
'目标文件夹路径
Dim z As New ZipInputStream(File.OpenRead(zipPath))
Dim t As ZipEntry
Dim fp As String
' 开始循环解压
Do
t = z.GetNextEntry
If t Is Nothing Then Exit Do
fp = folderPath & t.Name
fp = folderPath
'如果是文件夹则创建文件夹
If t.IsDirectory AndAlso Not Directory.Exists(fp) Then
Directory.CreateDirectory(fp)
ElseIf t.IsFile Then
'如果是文件则解压文件
If (Not File.Exists(fp)) Then
Dim sw As FileStream = File.Create(fp)
Dim size As Integer
Dim data(2048) As Byte
Do '循环读取数据
size = z.Read(data, 0, data.Length)
If size = 0 Then Exit Do
sw.Write(data, 0, size)
Loop
sw.Close()
End If
End If
Loop
z.Close()
End Sub
上面程序是可以运行的,但是我想套用去解压gzip文件,把Dim z As New ZipInputStream(File.OpenRead(zipPath)) 改为Dim z As New GZipInputStream(File.OpenRead(zipPath)),之后 t = z.GetNextEntry这句会报错,提示GetNextEntry不是GZipInputStream的成员,我不知道怎么改为.gzip的格式,请帮忙看下是哪里的语法错误了。