Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Compress a string (gzip) and write to Response

$
0
0

Let's say I have a large string that I want write to the Response Body. I can use a sample like this one below:

var largeString = System.Text.Encoding.UTF8.GetBytes("A very large string content");
await Response.Body.WriteAsync(largeString, 0, largeString.Length);

Now, I would like to Compress the largeString using gzip compression and set appropriate headers

Response.Headers.Add("Content-Encoding", "gzip");

What's the right way to do gzip and write to the Response body that the browser can understand? 

Thanks!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>