gzipstream

Can I decompress and deserialize a file using streams?

£可爱£侵袭症+ 提交于 2019-11-27 07:56:21
问题 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,

GZipStream compression problem ( Lost Byte )

安稳与你 提交于 2019-11-27 07:41:21
问题 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

.NET GZipStream compress and decompress

China☆狼群 提交于 2019-11-27 05:43:20
问题 What is wrong with this code below. I always get FALSE, meaning after compression, decompressed data does not match original value. public static bool Test() { string sample = "This is a compression test of microsoft .net gzip compression method and decompression methods"; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] data = encoding.GetBytes(sample); bool result = false; //Compress MemoryStream cmpStream; cmpStream = new MemoryStream(); GZipStream hgs = new

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

二次信任 提交于 2019-11-26 20:20:52
问题 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

Why does my C# gzip produce a larger file than Fiddler or PHP?

巧了我就是萌 提交于 2019-11-26 15:22:53
If I GZip this text: Hello World through C# using this code: Stream stream = new MemoryStream(Encoding.Default.GetBytes("Hello World")); var compressedMemoryStream = new MemoryStream(); using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Compress)) { stream.CopyTo(gzipStream); gzipStream.Close(); } the resulting stream is 133 bytes long Running the same string through either Fiddler's Utilities.GzipCompress or this PHP page the result is only 31 bytes long. In both cases the input is 11 bytes, so I would imagine the PHP result is correct but obviously this means that

Why does my C# gzip produce a larger file than Fiddler or PHP?

天涯浪子 提交于 2019-11-26 04:24:10
问题 If I GZip this text: Hello World through C# using this code: Stream stream = new MemoryStream(Encoding.Default.GetBytes(\"Hello World\")); var compressedMemoryStream = new MemoryStream(); using (var gzipStream = new GZipStream(compressedMemoryStream, CompressionMode.Compress)) { stream.CopyTo(gzipStream); gzipStream.Close(); } the resulting stream is 133 bytes long Running the same string through either Fiddler\'s Utilities.GzipCompress or this PHP page the result is only 31 bytes long. In