Xceed .NET Libraries Documentation
Extending the Compressor and Decompressor classes

Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Advanced Concepts > Extending > Extending the Compressor and Decompressor classes

The Compressor and Decompressor classes can be derived from to create custom compressor and decompressor classes which implement custom compression and decompression algorithms.

Basic Steps

The only implementation required when creating a class that derives from the Compressor class is an override of the Compress method. The same goes when deriving from the Decompressor class, except that in this case it is the Decompress method that is overridden.

Demonstration

The following example demonstrates the minimum implementations required for classes that derive from the Compressor and Decompressor classes:

VB.NET Copy Code

Imports System
Imports Xceed.Compression

Namespace Xceed.Compression.Samples
   Public Class CustomCompressor
      Inherits Compressor

      Public Overrides Function Compress( ByVal buffer As Byte(), _
                                          ByVal offset As Integer, _
                                          ByVal count As Integer, _ 
                                          ByVal endOfData As Boolean, _
                                          ByRef compressed As Byte() ) As Integer

         'The compressed size in bytes should be returned
         Return 0
      End Function
   End Class

   Public Class CustomDecompressor
      Inherits Decompressor
 
      Public Overrides Decompress( ByVal buffer As Byte(), _
                                   ByVal offset As Integer, _
                                   ByVal count As Integer, _
                                   ByVal endOfData As Boolean, _
                                   ByRef decompressed As Byte(), _
                                   ByRef remaining As Integer ) As Integer

         'The decompressed size in bytes should be returned
         Return 0
      End Function
   End Class
End Namespace

C# Copy Code

using System;
using Xceed.Compression;

namespace Xceed.Compression.Samples
{
   public class CustomCompressor : Compressor
   {
      public override int Compress( byte[] buffer,
                                    int offset,
                                    int count,
                                    bool endOfData,
                                    out byte[] compressed )
      {
         // The compressed size in bytes should be returned.
         return 0;
      }
   }

   public class CustomDecompressor : Decompressor
   {
      public override int Decompress( byte[] buffer,
                                      int offset,
                                      int count,
                                      ref bool endOfData,
                                      out byte[] decompressed,
                                      out int remaining )
      {
         // The decompressed size in bytes should be returned.
         return 0;
      }
   }
}