我想使用 NuGet https://www.nuget.org/packages/lz4net/提供的 lz4net 库解压缩 LZ4 编码的字符串,该库的 GitHub 站点是https://github.com/MiloszKrajewski/lz4net。
我对流和这个库都不熟悉,但到目前为止,这是我的代码:
Private Function LZ4Decompress(input As String) As String
Dim inputBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(input)
Dim inputStream As New MemoryStream()
inputStream.Write(inputBytes, 0, inputBytes.Length)
inputStream.Seek(0, SeekOrigin.Begin)
Dim outputStream As New MemoryStream()
Dim outputBytes(1024) As Byte
Dim output As String
Using lzStream As New LZ4.LZ4Stream(inputStream, LZ4.LZ4StreamMode.Decompress)
' how to write to outputStream ?
End Using
outputStream.Read(outputBytes, 0, outputStream.Length)
output = System.Text.Encoding.Unicode.GetString(outputBytes)
Return output
End Function
问题:
- lzStream 的长度为-1,所以我无法从中读取,我该怎么做?
- 我只能实例化具有固定长度的 outputBytes,我想让它与需要的一样大