gzipstream

Sending gzipped data in WebRequest?

烈酒焚心 提交于 2019-12-28 13:45:29
问题 I have a large amount of data (~100k) that my C# app is sending to my Apache server with mod_gzip installed. I'm attempting to gzip the data first using System.IO.Compression.GZipStream. PHP receives the raw gzipped data, so Apache is not uncompressing it as I would expect. Am I missing something? 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(

Sending gzipped data in WebRequest?

不问归期 提交于 2019-12-28 13:45:08
问题 I have a large amount of data (~100k) that my C# app is sending to my Apache server with mod_gzip installed. I'm attempting to gzip the data first using System.IO.Compression.GZipStream. PHP receives the raw gzipped data, so Apache is not uncompressing it as I would expect. Am I missing something? 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(

Properly Compressing a CSV utilizing GZIP Stream and Memory Stream

人盡茶涼 提交于 2019-12-24 03:22:37
问题 I am compressing a CSV file utilizing GZIPStream and MemoryStream, and noticing something weird with the result file. It seems like the CSV is not properly recognized. This shows when the file is attached to an email, but works fine when saved on a windows desktop. Here is the current snippet handling the gzip portion: GZipStream gStream = null; MemoryStream mStream = null; MemoryStream mStream2 = null; try { if (attachment.Length > 0) { mStream = new MemoryStream(); gStream = new GZipStream

Why does C# memory stream reserve so much memory?

蓝咒 提交于 2019-12-20 11:04:27
问题 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

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

大城市里の小女人 提交于 2019-12-20 03:21:47
问题 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

GZIP decompression C# OutOfMemory

强颜欢笑 提交于 2019-12-19 07:07:11
问题 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

GZipStream and DeflateStream produce bigger files

非 Y 不嫁゛ 提交于 2019-12-19 05:46:48
问题 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

How to read from file containing multiple GzipStreams

梦想的初衷 提交于 2019-12-18 17:13:54
问题 I've got a file created with code which looks like this: 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"); } } } Now I'm trying to read the data from this file with following code: string txt; using (var fs=File

GZipStream and decompression

筅森魡賤 提交于 2019-12-17 19:14:52
问题 I have code that should do the compression: FileStream fs = new FileStream("g:\\gj.txt", FileMode.Open); FileStream fd = new FileStream("g:\\gj.zip", FileMode.Create); GZipStream csStream = new GZipStream(fd, CompressionMode.Compress); byte[] compressedBuffer = new byte[500]; int offset = 0; int nRead; nRead = fs.Read(compressedBuffer, offset, compressedBuffer.Length); while (nRead > 0) { csStream.Write(compressedBuffer, offset, nRead); offset = offset + nRead; nRead = fs.Read

“Invalid use of response filter” when compressing response from an IHttpHandler

不问归期 提交于 2019-12-12 19:27:47
问题 I have an IHttpHandler returning a file. When the response stream is compressed, either automatically using Telerik RadCompression or by explicitly setting a filter using context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress); the response returned to the browser is correct but at the end of the response is some HTML. The HTML contains the exception: [HttpException (0x80004005): Invalid use of response filter] System.Web.HttpResponseStreamFilterSink