I have a table in SQL Server with a varbinary(MAX)
column which is filled with SQL Compress
method of JSON string with utf8 characters for example {"id": 12, title: "فروش"}
in the sql I use CAST(DECOMPRESS(data) AS NVARCHAR(MAX))
and result is ok.
In the c# I use this code for decompressing the data column:
public static string Unzip(byte[] bytes)
{
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
CopyTo(gs, mso);
}
return Encoding.UTF8.GetString(mso.ToArray());
}
}
But the result is an invalid string: