Tag: gzip

为什么压缩小文件的gzip / deflate导致许多尾随零?

我正在使用以下代码在C#中压缩一个小的(~4kB)HTML文件。 byte[] fileBuffer = ReadFully(inFile, ResponsePacket.maxResponsePayloadLength); // Read the entire requested HTML file into a memory buffer inFile.Close(); // Close the requested HTML file byte[] payload; using (MemoryStream compMS = new MemoryStream()) // Create a new memory stream to hold the compressed HTML data { using (GZipStream gzip = new GZipStream(compMS, CompressionMode.Compress)) // Create a […]

使用.NET创建tar.gz

我是.NET的新手。 是否可以使用.NET环境创建tar.gz? 如果有,怎么样?

使用GZipStream解压缩仅返回第一行

我一直在研究解析第三方fms日志的function。 日志在Gzip中,因此我使用解压缩function,适用于我们使用的任何其他Gzip文件。 解压缩这些文件时,我只得到压缩文件的第一行,没有例外,它只是找不到其余的字节,好像第一行有一个EOF。 我尝试使用Ionic.Zlib而不是System.IO.Compression,但结果是一样的。 这些文件似乎没有任何损坏,使用Winrar解压缩它们。 如果有人知道如何解决这个问题,我将非常感谢你的帮助。 谢谢 您可以在此处下载示例文件: http : //www.adjustyourset.tv/fms_6F9E_20120621_0001.log.gz 这是我的减压function: public static bool DecompressGZip(String fileRoot, String destRoot) { try { using (FileStream fileStram = new FileStream(fileRoot, FileMode.Open, FileAccess.Read)) { using (FileStream fOutStream = new FileStream(destRoot, FileMode.Create, FileAccess.Write)) { using (GZipStream zipStream = new GZipStream(fileStram, CompressionMode.Decompress, true)) { byte[] buffer = new byte[4096]; int […]

有没有办法用另一个库解压缩DynaZip Max文件? FE DotNetZip

我有一个数据库,我们使用以下代码存储使用DynaZip Max Secure压缩的pdf文件: MemoryStream msIN = new System.IO.MemoryStream(); //Input MemoryStream MemoryStream msZip = new System.IO.MemoryStream(); //Compressed MemoryStream BinaryReader objBinaryReader; BinaryWriter objBinaryWriter; public MemoryStream CompressStream(byte[] vbuf) { System.IO.BinaryWriter bw = new System.IO.BinaryWriter(msIN); bw.Write(vbuf); CDZipSNET dz1 = new CDZipSNET(); dz1.ZipMemToMemCallback += new CDZipSNET.OnZipMemToMemCallback(this.ZipMemToMemCallback_event); dz1.ActionDZ = CDZipSNET.DZACTION.ZIP_MEMTOMEM; return msZip; } 这是ZipMemToMemCallback_event代码: public void ZipMemToMemCallback_event(CDZipSNET.MEMTOMEMACTION lAction,ref byte[] lpMemBuf,ref uint […]

如何提取从HttpWebResponse收到的压缩文件?

我将url放到浏览器的地址栏中,然后将zip文件下载到HD。 压缩文件的大小为386字节,在其属性中写入。 当我使用UnZipFiles方法提取文件时 – 它的工作原理。 但是,我想下载programaticaly并将其提取到内存中。 我使用GetResultFromServer方法来获取压缩内容。 如标题所示,内容的大小与HD上保存的压缩文件的大小相同: content-disposition: attachment; filename=emaillog-xml.zip Content-Length: 386 Cache-Control: private Content-Type: application/zip Date: Mon, 10 Sep 2012 08:28:28 GMT Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET 我的问题是如何提取GetResultFromServer返回的内容? 我尝试了以下方法: var ms = new MemoryStream(Encoding.Unicode.GetBytes(res)) var s = new ZipInputStream(ms); 但是我Unable to read from this stream 。 更新 我试过var zipStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), […]

GZipStream正在切断XML的最后一部分

我创建了一个名为AddGZip的扩展方法,如下所示: public static void AddGZip(this HttpResponse response) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); response.AppendHeader(“Content-Encoding”, “gzip”); } 这是代码的一个非常简化的版本: var response = HttpContext.Current.Response; var request = HttpContext.Current.Request; var result = File.ReadAllText(path); if (request.SupportsGZip) { response.AddGZip(); } response.Write(result); response.Flush(); 当您在具有GZip支持的Web浏览器中查看响应时,会出现如下错误: “XML解析错误:未关闭的令牌位置: http://webserver1/1234.xml第78行,第1列:” 当我查看源代码时,它基本上错过了XML文件末尾的最后一个> 。 所以1或2个字节。 如果我注释掉AddGZip线,它可以正常工作。 但是我真的想支持GZip,因为XML可能非常大。 有人对我有建议吗? 我已经尝试检查了很多博客,但似乎没有针对此类错误的解决方案。 戴夫

.NET中的DeflateStream 4GB限制

来自MSDN: DeflateStream类 DeflateStream不能用于压缩大于4 GB的文件。 没有4 GB限制的.NET是否还有其他实现? 注意:我真的需要解压缩GZ格式的文件,内容大于4 GB。 任何代码都可以这样做吗?

在WebRequest中发送gzip压缩数据?

我有大量的数据(~100k),我的C#app正在安装mod_gzip发送到我的Apache服务器。 我正在尝试使用System.IO.Compression.GZipStream首先gzip数据。 PHP接收原始的gzip压缩数据,因此Apache并没有像我期望的那样解压缩它。 我错过了什么吗? System.Net.WebRequest req = WebRequest.Create(this.Url); req.Method = this.Method; // “post” req.Timeout = this.Timeout; req.ContentType = “application/x-www-form-urlencoded”; req.Headers.Add(“Content-Encoding: gzip”); System.IO.Stream reqStream = req.GetRequestStream(); GZipStream gz = new GZipStream(reqStream, CompressionMode.Compress); System.IO.StreamWriter sw = new System.IO.StreamWriter(gz, Encoding.ASCII); sw.Write( large_amount_of_data ); sw.Close(); gz.Close(); reqStream.Close() System.Net.WebResponse resp = req.GetResponse(); // (handle response…) 我不完全确定“Content-Encoding:gzip”适用于客户端提供的头文件。

在ASP.NET MVC 3中GZipping内容文件

我使用以下属性来装饰我的BaseController类。 public class OutputCompressAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { string encodingsAccepted = filterContext.HttpContext.Request.Headers[“Accept-Encoding”]; if (string.IsNullOrEmpty(encodingsAccepted)) return; encodingsAccepted = encodingsAccepted.ToLowerInvariant(); HttpResponseBase response = filterContext.HttpContext.Response; if (encodingsAccepted.Contains(“gzip”)) { response.AppendHeader(“Content-encoding”, “gzip”); response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); } else if (encodingsAccepted.Contains(“deflate”)) { response.AppendHeader(“Content-encoding”, “deflate”); response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress); } } } 问题是,即使这对于视图和每个操作结果都很好,该属性也不适用于项目的/Content文件夹中的/Content 。 我想知道如何使它能够使Content文件夹中的文件使用控制器,或以某种方式绑定或挂钩允许我将这些filter附加到响应头的东西。

如何从包含多个GzipStream的文件中读取

我有一个用代码创建的文件,如下所示: using (var fs=File.OpenWrite(“tmp”)) { using (GZipStream gs=new GZipStream(fs,CompressionMode.Compress,true)) { using (StreamWriter sw=new StreamWriter(gs)) { sw.WriteLine(“hello “); } } using (GZipStream gs = new GZipStream(fs, CompressionMode.Compress, true)) { using (StreamWriter sw = new StreamWriter(gs)) { sw.WriteLine(“world”); } } } 现在我正在尝试使用以下代码从此文件中读取数据: string txt; using (var fs=File.OpenRead(“tmp”)) { using (GZipStream gs=new GZipStream(fs,CompressionMode.Decompress,true)) { using (var rdr = […]