LZW compression on C# from string

后端 未结 3 1081
说谎
说谎 2021-01-25 21:17

I\'m looking for a LZW compression algorithm in C# that takes a \"string\" and returns a string. I\'ve googling for hours and all I\'ve found use MemoryStream, BinaryWriters, et

3条回答
  •  抹茶落季
    2021-01-25 22:07

    Use something like this:

    private string CompressToLZW(string input)
    {
        using (MemoryStream stream = new MemoryStream())
        {
            ComputeLZW(input, stream);
            stream.Seek(0, SeekOrigin.Begin);
            using (StreamReader reader = new StreamReader(stream))
            {
                return reader.ReadToEnd();
            }
        }
    }
    

    where ComputeLZW() is the LZW method you have that uses a stream.

提交回复
热议问题