hi all
i have one function which generates string
that string is very lengthy.
i want to decrease its length and size
this is my code and result:
not posting real string it is very long
protected void Page_Load(object sender, EventArgs e)
{
string txt = "somestring";
Label1.Text = txt.Length.ToString();
string cmpString = Compress(txt);
Label2.Text = cmpString.Length.ToString();
}
public string Compress(string text)
{
byte[] buffer = Encoding.UTF8.GetBytes(text);
MemoryStream ms = new MemoryStream();
using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
{
zip.Write(buffer, 0, buffer.Length);
}
ms.Position = 0;
byte[] compressed = new byte[ms.Length];
ms.Read(compressed, 0, compressed.Length);
byte[] gzBuffer = new byte[compressed.Length + 4];
System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
return Convert.ToBase64String(gzBuffer);
}
result:
465832
667296
What I have tried:
my question is when i m compressing the data the length of that string should reduce it is increasing is there any solution becoz i want to minimize its length and size.