/// <summary> /// Decompress a string using GZip and the specific encoding. Defaults to UTF-8 /// </summary> /// <param name="data"></param> /// <param name="encodingName"> </param> /// <returns></returns> public static string GZipDecompress(this byte[] data, string encodingName = "utf-8") { var enc = Encoding.GetEncoding(encodingName); using (var ms = new MemoryStream()) using (var gz = new GZipStream(ms, CompressionMode.Decompress)) { ms.Write(data, 0, data.Length); ms.Position = 0; var buffer = gz.ReadAllBytes(); return enc.GetString(buffer); } }
public ActionResult Html(string docId) { string xmlFileName, htmlFileName; if (!CheckRequest(docId, out xmlFileName) || !CheckRequest(docId, out htmlFileName, /*htmlFile=*/true)) { return View("Error"); } Document doc = new Document("", ""); doc.ReadXmlCompressed(xmlFileName); string charSet = doc.Features.GetFeatureValue("charSet"); byte[] bytes; using (FileStream stream = new FileStream(htmlFileName, FileMode.Open)) { using (GZipStream gzStream = new GZipStream(stream, CompressionMode.Decompress)) { bytes = gzStream.ReadAllBytes(/*sizeLimit=*/0); } } return File(bytes, "text/html; charset=" + charSet); }