gzipstream

GZipStream effectivness

北战南征 提交于 2019-12-03 14:38:46
I am trying to save big UInt16 array into a file. positionCnt is about 50000, stationCnt is about 2500. Saved directly, without GZipStream, the file is about 250MB which can be compressed by external zip program to 19MB. With the following code the file is 507MB. What do I do wrong? GZipStream cmp = new GZipStream(File.Open(cacheFileName, FileMode.Create), CompressionMode.Compress); BinaryWriter fs = new BinaryWriter(cmp); fs.Write((Int32)(positionCnt * stationCnt)); for (int p = 0; p < positionCnt; p++) { for (int s = 0; s < stationCnt; s++) { fs.Write(BoundData[p, s]); } } fs.Close(); Not

Gzip compression not working ASP.net MVC5

风流意气都作罢 提交于 2019-12-03 03:22:08
I want to compress my web application with Gzip and I am using following class compression filter public class CompressFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase request = filterContext.HttpContext.Request; string acceptEncoding = request.Headers["Accept-Encoding"]; if (string.IsNullOrEmpty(acceptEncoding)) return; acceptEncoding = acceptEncoding.ToUpperInvariant(); HttpResponseBase response = filterContext.HttpContext.Response; if (acceptEncoding.Contains("GZIP")) { response.AppendHeader("Content-encoding",

Why does C# memory stream reserve so much memory?

瘦欲@ 提交于 2019-12-03 01:08:13
Our software is decompressing certain byte data through a GZipStream , which reads data from a MemoryStream . These data are decompressed in blocks of 4KB and written into another MemoryStream . We've realized that the memory the process allocates is much higher than the actual decompressed data. Example: A compressed byte array with 2,425,536 bytes gets decompressed to 23,050,718 bytes. The memory profiler we use shows that the Method MemoryStream.set_Capacity(Int32 value) allocated 67,104,936 bytes. That's a factor of 2.9 between reserved and actually written memory. Note: MemoryStream.set

Can I get a GZipStream for a file without writing to intermediate temporary storage?

淺唱寂寞╮ 提交于 2019-12-02 03:01:50
Can I get a GZipStream for a file on disk without writing the entire compressed content to temporary storage? I'm currently using a temporary file on disk in order to avoid possible memory exhaustion using MemoryStream on very large files (this is working fine). public void UploadFile(string filename) { using (var temporaryFileStream = File.Open("tempfile.tmp", FileMode.CreateNew, FileAccess.ReadWrite)) { using (var fileStream = File.OpenRead(filename)) using (var compressedStream = new GZipStream(temporaryFileStream, CompressionMode.Compress, true)) { fileStream.CopyTo(compressedStream); }

Decompressing using GZipStream returns only the first line

南笙酒味 提交于 2019-12-01 08:58:10
I’ve been working on a function parsing 3rd party fms logs. The logs are in Gzip, so I use a decompressing function that works for any other Gzip files we use. When decompressing these files I only get the first line of the compressed file, there’s no exception, it just doesn’t find the rest of the bytes as if there's an EOF at the first line. I tried using Ionic.Zlib instead of System.IO.Compression but the result was the same. The files don’t seem to be corrupted in any way, decompressing them with Winrar works. If anybody has any idea of how to solve this, I’ll appreciate your help. Thanks

Decompressing using GZipStream returns only the first line

*爱你&永不变心* 提交于 2019-12-01 06:50:00
问题 I’ve been working on a function parsing 3rd party fms logs. The logs are in Gzip, so I use a decompressing function that works for any other Gzip files we use. When decompressing these files I only get the first line of the compressed file, there’s no exception, it just doesn’t find the rest of the bytes as if there's an EOF at the first line. I tried using Ionic.Zlib instead of System.IO.Compression but the result was the same. The files don’t seem to be corrupted in any way, decompressing

GZipStream decompression performance is poor

心已入冬 提交于 2019-12-01 05:56:01
I have a .NET 2.0 WinForms app that connects to a backend WAS server. I am using GZipStream to decode data coming back from a HttpWebRequest call made to the server. The data returned is compressed CSV, which Apache is compressing. The entire server stack is Hibernate-->EJB-->Spring-->Apache. For small responses, the performance is fine (<50ms). When I get a response >150KB, it takes more than 60 seconds to decompress. The majority of the time seems to be spent in the GZipStream constructor. This is the code showing where I get the response stream from the HttpWebResponse call: using (Stream

GZIP decompression C# OutOfMemory

巧了我就是萌 提交于 2019-12-01 04:48:39
I have many large gzip files (approximately 10MB - 200MB) that I downloaded from ftp to be decompressed. So I tried to google and find some solution for gzip decompression. static byte[] Decompress(byte[] gzip) { using (GZipStream stream = new GZipStream(new MemoryStream(gzip), CompressionMode.Decompress)) { const int size = 4096; byte[] buffer = new byte[size]; using (MemoryStream memory = new MemoryStream()) { int count = 0; do { count = stream.Read(buffer, 0, size); if (count > 0) { memory.Write(buffer, 0, count); } } while (count > 0); return memory.ToArray(); } } } it works well for any

GZipStream and DeflateStream produce bigger files

怎甘沉沦 提交于 2019-12-01 03:35:30
I'm trying to use deflate/gzip streams in C# but it appears that the files after compression are bigger than before. For example, I compress a docx file of 900ko, but it produce a 1.4Mo one ! And it does it for every file I tried. May be I am wrong in the way I'm doing it? Here is my code : FileStream input = File.OpenRead(Environment.CurrentDirectory + "/file.docx"); FileStream output = File.OpenWrite(Environment.CurrentDirectory + "/compressedfile.dat"); GZipStream comp = new GZipStream(output, CompressionMode.Compress); while (input.Position != input.Length) comp.WriteByte((byte)input

GZipStream is cutting off last part of XML

核能气质少年 提交于 2019-11-30 22:15:51
I have created an extension method called AddGZip which looks like the following: public static void AddGZip(this HttpResponse response) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); response.AppendHeader("Content-Encoding", "gzip"); } This is a very cut down version of the code: 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(); When you view the response in a web browser with GZip support you get