I tried to deflate a string I got from a websocket connection, but everytime I try to run this code I get an Error. I also tried to get the bytes directly from the string with an ascii encoding but it didn't work either.
public static byte[] Decompress(string input)
{
byte[] data = Convert.FromBase64String(input)
byte[] decompressedArray = null;
using (MemoryStream decompressedStream = new MemoryStream())
{
using (MemoryStream compressStream = new MemoryStream(data))
{
using (DeflateStream deflateStream = new DeflateStream(compressStream, CompressionMode.Decompress))
{
deflateStream.CopyTo(decompressedStream);
}
}
decompressedArray = decompressedStream.ToArray();
}
return decompressedArray;
}
System.IO.InvalidDataException: "Block length does not match with its complement."
I tried a few diffrent variations of this code but nothing worked, but i know that its possible because I can deflate it with this website http://www.txtwizard.net/compression and the deflate option.
One example string I want to deflate:
eAGdVMmO2kAU/BXUc3WYXr1wy3LIKYqUjHKIo6jtboODsVG72YT491SbIWMYkcNgiX4uv6pXr7efxHXdatYvtDPs8Qf7wkh0JF3xx5a+J7MjUVnKK8tsQbOEJqyQ2pQ0kSJ8s6118wOZcSlpROp2q411n7Xb2t5bAzyO5SkiymjDdFLaSgpZJCZOK6NYTINE7ztnx1pMifg0kAwrK16mqTSWSl4VcWGVGkiLOniTjKJqa/f+ky314Xu9ghBXIpFZSoPEXK/sCyqylAWTVRfKrTqDbLLrXGMIcrd1v9ENkGNOfE5mOXE5iXKyRywSBAcEFOMOI+MIFghijD1GkKq6aRDlpGh0uRy4vXfd0g7gDpYRIb1b67L2g9qUq9Mpb/9VRF0keDQ0cD5+fZo89Xp+5gUjUuB7oDKMl7pdG9LpNL3Sas7uGT6JZEpVIIYXNg3hniOU6TQb8PAC/H9WNs7Z1t/YgfDAB50P0bMl3dTzFmBOGlvB3JWxmyb5VIrJ40Se7QZX8Vh07OleS2FSXjckxtSbou+31mFe77cjIfmmZlLMZbBz3Ygce7nXhryzMsDH9JtWPmzKpfWTbzhG450yWhr1tqXJsix93QnExmZGvcgwZ5ct9rLHBjRsMIXNBiqJyKa37vlqUYZJQ1NDVZEmlRA6sfgL5/N3jfsDl8+djLNKiwMeDrGvnG6XkC60mQ+3iT+sw2XAI1J2TecYsh60KbQtkDVAPEA8VpXJLhDuNPLAdHgArbXTKzJ7F4uIVE29JjPvNvaE36+/hpSDkQ==
The string (JSON) probably comes from a GZipStream.
You can use this other stream to decompress the data content:
► You need .Net Framework 4.7.2+ to decompress the data correctly.
As a note, the compressed format is a little off. The compressed data signature,
78 : 01, may suggest that this is a ZLib compressed string, so the .Net DeflateStream, which is based on ZLib (from .NET Framework 4.5), should decompress the data.Both 7-Zip and WinZip cannot open the data (a stream saved as a binary file).
The JSON is UTF8-Encoded (it also applies to an ASCII string):
Resulting in (.Net Fidddle):