CompressionHelper

Helpers & Utilities · AiDotNet.Helpers

Provides transparent compression and decompression utilities for model serialization.

For Beginners

This helper automatically compresses your model when you save it and decompresses it when you load it. You don’t need to do anything special - just configure compression when building your model, and the rest happens automatically.

Benefits:

  • Smaller model files (50-90% size reduction)
  • Faster model loading over networks
  • Lower storage costs
  • Seamless integration with existing serialize/deserialize methods

How It Works

CompressionHelper handles the application of compression during model serialization and decompression during deserialization. It works transparently with the facade pattern, so users never directly interact with compression algorithms.

Methods

Method Summary
ValueTuple<long, long, double, double> GetCompressionStats(byte[] originalData, byte[] compressedData) Gets compression statistics for the last compression operation.
bool IsCompressedData(byte[] data) Checks if the data was compressed by AiDotNet.
byte[] Compress(byte[] data, CompressionConfig config) Compresses the serialized model data based on the compression configuration.
byte[] DecompressIfNeeded(byte[] data) Decompresses model data if it was compressed, otherwise returns unchanged data.