c# - Yet another DeflateStream decompression problem (using using and memory streams) -
First of all, I see that the object requires more byte for compression, even though the object is binary Appears in the form. (228 vs 166).
Second, I can not uncompress it.
In addition, I can not use good copy functionality because I do not have version 4 .NET Framework
with the help of block should go to the final DeflateStream?
MyClass MyObj = New MyClass (); MyObj.MyProp1 = True; MyObj.MyProp2 = "D"; MyClass MyObAfterSerDeser = Null; (MemoryStream MS = New MemoryStream ()) Using {BinaryFormatter bf = New BinaryFormatter (); Bf Cyrilize (MS, Myos); Byte [] PREBITS = MS. Toure (); // Length 166. ms.SetLength (0L); (Deflestream TMPMS = New MemoryStream ()) (DeflestStream DSC = New DefaultTerm (TMPMS, Compression Mode. Compress)) {DSC. Worth (PREBITES, 0, PREBITT. LANG); Tmpms.WriteTo (MS); // unforunately though, just want # of compressed bytes }} Byte [] cbytes = ms.ToArray (); // length 228. longer than uncompressed version! Ms.SetLength (0L); (Memorystream TMPMS = new memorystream ()) using {tmpms.Write (cbytes, 0, cbytes.Length); Tmpms.position = 0; (Using difflstream dsd = new deflatstream (compression mode. Compressor)) {byte [DBATS = new byte [cbtl]]; Dsd.Read (dbytes, 0, dbytes.Length); Int offset = ReadAllBytesFromStream (dsd, dbytes); // dsd.Write (dbytes, 0, cbytes.Length) written by Mr. Skeet; // DSD. Read (DBATS, 0, DBAT.Length); Ms.Write (dbytes, 0, offset); }} MyObAfterSerDeser = (MyClass) bf.Deserialize (MS); }
There is no guarantee that deflate will always give results of a small size (Although it should use only "stored / raw / incomplete" section in such cases.) .NET deflate implementation (which is GZipStream) is small and / or pre-compressed data encoding, there are third party libraries with dotnet zip, which fix these two issues . Are present in the BCL.
When I bow down compression (on small pieces of data) I have a "deflated" flag so that the stream
Happy coding I have deflated the store sometimes, depending on if deflate was "worth it."
Comments
Post a Comment