使用lz4net解压缩LZ4压缩字符串

时间:2016-02-09 11:37:09

标签: .net lz4

我想使用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

的问题:

  1. lzStream的长度为-1,所以我无法读取它,我该怎么做?
  2. 我只能实例化具有固定长度的outputBytes,我想使它与所需的一样大

0 个答案:

没有答案