Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/15 13:43:03 (9 years ago)
Author:
ascheibe
Message:

#2368 added support in persistence for typecaches in streams

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs

    r12012 r12455  
    218218
    219219    /// <summary>
    220     /// Deserializes an object from the specified stream.
     220    /// Deserializes an object from the specified stream using GZip compression.
    221221    /// </summary>
    222222    /// <param name="stream">The stream.</param>
    223223    /// <returns>A fresh object instance.</returns>
    224     public static object Deserialize(Stream stream) {
     224    public static object DeserializeWithGZip(Stream stream) {
    225225      try {
    226226        using (StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress))) {
     
    239239
    240240    /// <summary>
     241    /// Deserializes an object from the specified stream using Zip compression.
     242    /// </summary>
     243    /// <param name="stream">The stream.</param>
     244    /// <returns>A fresh object instance.</returns>
     245    private static object DeserializeWithZip(Stream stream) {
     246      ZipArchive zipFile = new ZipArchive(stream);
     247      return Deserialize(zipFile);
     248    }
     249
     250    /// <summary>
    241251    /// Deserializes an object from the specified stream.
    242252    /// </summary>
    243253    /// <typeparam name="T">object type expected from the serialized stream</typeparam>
    244254    /// <param name="stream">The stream.</param>
     255    /// <param name="useZip">If true, uses zip for decompression, otherwise gzip.</param>
    245256    /// <returns>A fresh object instance.</returns>
    246     public static T Deserialize<T>(Stream stream) {
    247       return (T)Deserialize(stream);
     257    public static T Deserialize<T>(Stream stream, bool useZip = false) {
     258      return (T)Deserialize(stream, useZip);
     259    }
     260
     261    /// <summary>
     262    /// Deserializes an object from the specified stream.
     263    /// </summary>
     264    /// <param name="stream">The stream.</param>
     265    /// <param name="useZip">If true, uses zip for decompression, otherwise gzip.</param>
     266    /// <returns>A fresh object instance.</returns>
     267    public static object Deserialize(Stream stream, bool useZip = false) {
     268      if (useZip) {
     269        return DeserializeWithZip(stream);
     270      } else {
     271        return DeserializeWithGZip(stream);
     272      }
    248273    }
    249274
Note: See TracChangeset for help on using the changeset viewer.