gzipstream

How to read from file containing multiple GzipStreams

限于喜欢 提交于 2019-11-30 14:38:35
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.OpenRead("tmp")) { using (GZipStream gs=new GZipStream(fs,CompressionMode.Decompress,true)) { using

How do I read / write gzipped files in C++?

∥☆過路亽.° 提交于 2019-11-30 06:58:35
问题 How do I read / write gzipped files in C++? The iostream wrapper classes here look good, and here is a simple usage example: gz::igzstream in(filename); std::string line; while(std::getline(in, line)){ std::cout << line << std::endl; } But I wasn't able to actually link it (although I have a /usr/lib/libz.a ). A simple g++ test-gzstream.cpp -lz didn't do it ( undefined reference to gz::gzstreambase::~gzstreambase() ). 回答1: Obviously you need the cpp-file where the gzstreambase destructor is

Can I decompress and deserialize a file using streams?

浪尽此生 提交于 2019-11-29 13:51:49
My application serializes an object using Json.Net, compresses the resulting JSON, then saves this to file. Additionally the application can load an object from one of these files. These objects can be tens of Mb in size and I'm concerned about memory usage, due to the way the existing code creates large strings and byte arrays:- public void Save(MyClass myObject, string filename) { var json = JsonConvert.SerializeObject(myObject); var bytes = Compress(json); File.WriteAllBytes(filename, bytes); } public MyClass Load(string filename) { var bytes = File.ReadAllBytes(filename); var json =

GZipStream doesn't detect corrupt data (even CRC32 passes)?

☆樱花仙子☆ 提交于 2019-11-29 11:00:22
I'm using GZipStream to compress / decompress data. I chose this over DeflateStream since the documentation states that GZipStream also adds a CRC to detect corrupt data, which is another feature I wanted. My "positive" unit tests are working well in that I can compress some data, save the compressed byte array and then successfully decompress it again. The .NET GZipStream compress and decompress problem post helped me realize that I needed to close the GZipStream before accessing the compressed or decompressed data. Next, I continued to write a "negative" unit test to be sure corrupt data

How do I read / write gzipped files in C++?

谁说胖子不能爱 提交于 2019-11-28 23:31:19
How do I read / write gzipped files in C++? The iostream wrapper classes here look good, and here is a simple usage example: gz::igzstream in(filename); std::string line; while(std::getline(in, line)){ std::cout << line << std::endl; } But I wasn't able to actually link it (although I have a /usr/lib/libz.a ). A simple g++ test-gzstream.cpp -lz didn't do it ( undefined reference to gz::gzstreambase::~gzstreambase() ). Macke Obviously you need the cpp-file where the gzstreambase destructor is defined as well, i.e. gzstream.cpp (that's the link fault). libz is just a c-api for gzip, it knows

GZipStream compression problem ( Lost Byte )

≡放荡痞女 提交于 2019-11-28 13:27:22
I've got some strange problem with GZip Serializer. Trying serializing object with data in it. Following code give results( at POINT1 in debug ): ms.Length = 100028 and uncompressedStream.Length=100027 After POINT1 there is exception "End of Stream encountered before parsing was completed.", which i think is result of this lost byte. I am using .net 4.0. //generating data int length = 100000; byte[] data = new byte[length]; for (int i = 0; i < length; i++) { data[i] = System.Convert.ToByte(i % 100 + i % 50); } //serialization into memory stream IFormatter formatter = new BinaryFormatter(); var

GZipStream and decompression

最后都变了- 提交于 2019-11-28 09:58:50
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(compressedBuffer, offset, compressedBuffer.Length); } fd.Close(); fs.Close(); and I think it does, but I want to

Sending gzipped data in WebRequest?

☆樱花仙子☆ 提交于 2019-11-28 09:07:32
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("Content-Encoding: gzip"); System.IO.Stream reqStream = req.GetRequestStream(); GZipStream gz = new

GZipStream doesn't detect corrupt data (even CRC32 passes)?

折月煮酒 提交于 2019-11-28 04:17:50
问题 I'm using GZipStream to compress / decompress data. I chose this over DeflateStream since the documentation states that GZipStream also adds a CRC to detect corrupt data, which is another feature I wanted. My "positive" unit tests are working well in that I can compress some data, save the compressed byte array and then successfully decompress it again. The .NET GZipStream compress and decompress problem post helped me realize that I needed to close the GZipStream before accessing the

How to pipe one readable stream into two writable streams at once in Node.js?

让人想犯罪 __ 提交于 2019-11-27 20:26:35
The goal is to: Create a file read stream. Pipe it to gzip ( zlib.createGzip() ) Then pipe the read stream of zlib output to: 1) HTTP response object 2) and writable file stream to save the gzipped output. Now I can do down to 3.1: var gzip = zlib.createGzip(), sourceFileStream = fs.createReadStream(sourceFilePath), targetFileStream = fs.createWriteStream(targetFilePath); response.setHeader('Content-Encoding', 'gzip'); sourceFileStream.pipe(gzip).pipe(response); ... which works fine, but I need to also save the gzipped data to a file so that I don't need to regzip every time and be able to