Skip to content

Instantly share code, notes, and snippets.

@vandanrohatgi
Created December 20, 2023 12:02
Show Gist options
  • Save vandanrohatgi/60ff5d5507df3129c54c9b1353e204fa to your computer and use it in GitHub Desktop.
Save vandanrohatgi/60ff5d5507df3129c54c9b1353e204fa to your computer and use it in GitHub Desktop.
C# code to return decompressed gzip data
public class Script: ScriptBase{
public override async Task < HttpResponseMessage > ExecuteAsync(){
var response = new HttpResponseMessage();
var contentAsString = await this.Context.Request.Content.ReadAsStringAsync().ConfigureAwait(false);
var contentAsJson = JObject.Parse(contentAsString);
var file = (string) contentAsJson("file");
byte[] data = Convert.FromBase64String(file);
string decompressedData = DecompressGzip(data);
response.Content = CreateJsonContent(new JObject {
["gzipBody"] = decompressedData,
}.ToString());
return response;
}
private string DecompressGzip(byte[] compressedData)
{
using (MemoryStream compressedStream = MemoryStream(compressedData))
using (GZipStream gzipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
using (MemoryStream decompressedStream = new MemoryStream())
{
gzipStream.CopyTo(decompressedStream);
return Encoding.UTF8.GetString(decompressedStream.ToArray());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment