解压缩流到流阅读器

时间:2014-03-11 15:09:31

标签: vb.net .net-3.5 gzip gz

尝试从下面的代码返回解压缩的流时,我得到Stream was not readable

    Using strmReader As New StreamReader(FileOpenRead(strFullFilename))
    ...
    End using

调用以下代码时:

Public Function FileOpenRead(ByVal strFullFilename As String) As Stream

        If File.Exists(strFullFilename) Then

            If Path.GetExtension(strFullFilename) = zipExtension Then
                Return DecompressToStream(strFullFilename)
            Else
                Return File.Open(strFullFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
            End If
        End If
        Return Nothing
    End Function

Private Function DecompressToStream(ByVal strFullFilename As String) As Stream

        Dim strmDecompressed As Stream = Nothing

        If File.Exists(strFullFilename) Then
            Using inpFile As FileStream = File.OpenRead(strFullFilename)
                Using Decompress As New GZipStream(inpFile, CompressionMode.Decompress)
                    strmDecompressed = New BufferedStream(Decompress)
                End Using
            End Using
        End If

        Return strmDecompressed
    End Function

我正在使用3.5框架,任何人都可以帮助我找到返回解压缩流的最佳方法吗?

0 个答案:

没有答案