PeterSteph
April 24th, 2003, 06:21 AM
Hi all,
Is there a way to compress files that is the result of serialized objects?
Regards
Peter
Is there a way to compress files that is the result of serialized objects?
Regards
Peter
|
Click to See Complete Forum and Search --> : Serialization PeterSteph April 24th, 2003, 06:21 AM Hi all, Is there a way to compress files that is the result of serialized objects? Regards Peter MartinL April 24th, 2003, 08:32 AM Hm.. Sure it is possible... Generally, there are two ways how to do this kind of serialization. A.) Implement ISearializable interface in the classes you want searialize. By this method you can implement custom serialization process. B.) Explicitelly compress the file produced by basic serialization process. You have to explicitelly compress the file after you perform serialization of all classes you want store on the disk. Additionally, before you deserialize them, you need to decompress that file. Method A is more "straightforward" however you can discover this method as not enough effective for you. It is due to the phylosophy of compressing algorithm. You can just compress individual fields of the class (or event one instance of the class) using A method. However, this means the degradation of effectiveness of compress algorithms. You can compare it with following: You have one file of size 1GB. When you compress this file, you can decrease its size for example to 0.5GB. Now, try to divide 1GB file into 10 0.1GB files. Compress individually each of these new files and the bind them together. Size of the resulting file will be greater then 0.5GB. It means, it is degradation of compression process. This is similiar to situation that you implement your custom serialization (Method A). Method A is much less effective than method B. Method B is not so "clear" and needs additional logic to be implemented after serialization and before deserialization. However the resulting disk space save will be really better as when you use method A. The another possibility is to embedd all objects that you want to serialize into one class. Make them members of that class. Then make custom serialization only for that class. In GetObjectData() method of that class just use basic serialization for all members of the class, and resulting data compress before you add them into the SerializationInfo object of "supperior" class. The same way use in serialization contructor of your class. Implementation of method A: [Serializable] public class YourObject : ISerializable { public string strHugeString1; public string strHugeString2; // Public contructor used for object creation public YourObject() { } // Serialization contructor. Will be used during deserialization public YourObject(SerializationInfo info, StreamingContext context) { strHugeString1 = DecompressString(info.GetString("s1")); strHugeString2 = DecompressString(info.GetString("s2")); } // The member is called during serialization process to get data to be serialized... // You can use context to determine kind of serialization and for example disallow // serialization of things like window handles or references to created com objects. public void GetObjectData(SearializationInfo info, StreamingContext context) { info.AddValue("s1", CompressString(strHugeString1)); info.AddString("s2", CompressString(strHugeString2)); } // Implement algorithm to decompress string protected string DecompressString(string strCompressed) { } // Implement algorithm to compress string protected string CompressString(string strPlain) { } } martin pareshgh April 24th, 2003, 05:56 PM you can compress the serialized files however you will need to encorporate third party or Microsoft's cab compressor in your program and have that file compressed. -Paresh codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |