本文整理汇总了C#中System.IO.Compression.GZipStream.ReadAllBytes方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.ReadAllBytes方法的具体用法?C# GZipStream.ReadAllBytes怎么用?C# GZipStream.ReadAllBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.GZipStream
的用法示例。
在下文中一共展示了GZipStream.ReadAllBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GZipDecompress
/// <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);
}
}
示例2: Html
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);
}