I want to decompress a LZ4 encoded string using the lz4net library available from NuGet https://www.nuget.org/packages/lz4net/, the GitHub site for this library is https://github.com/MiloszKrajewski/lz4net.
I'm not familiar with streams nor this library, but here is my code so far:
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
Issues:
- lzStream has a length of -1 so I can't read from it, how do I do that?
- I can only instantiate outputBytes with a fixed length, I'd like to make it just as large as required