Does your file format have a header? If not, now is the time to add it (in any case, you change the file format while supporting compression). Choose a good magic value , make sure the title is extensible (add a version field or use certain magic values โโfor certain versions), and you are ready to go.
After loading, check the magic value. If not, use the current boot routines. If present, the header will tell you whether the content is compressed or not.
Update
, XML-, , , , , . , :)
() -; , .net "", SubRangeStream, , (DeflateStream, , , , , ).
Int64 oldPosition = reader.Position;
reader.Read(magic, 0, magic.length);
if(IsRightMagicValue(magic))
{
Header header = ReadHeader(reader);
Stream furtherReader = new SubRangeStream(reader, reader.Position, header.ContentLength);
if(header.IsCompressed)
{
furtherReader = new DeflateStream(furtherReader, CompressionMode.Decompress);
}
XmlSerializer xml = new XmlSerializer(typeof(Workspace));
workspace = (Workspace) xml.Deserialize(furtherReader);
} else
{
reader.Position = oldPosition;
LegacyLoad(reader);
}
- - , . , IsRightMagicValue, ( ), " " , . Factory Method, IWorkspaceReader .