尝试从下面的代码返回解压缩的流时,我得到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框架,任何人都可以帮助我找到返回解压缩流的最佳方法吗?