#pragma region CPL License
/*
Nuclex Native Framework
Copyright (C) 2002-2021 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#pragma endregion // CPL License
#ifndef NUCLEX_STORAGE_COMPRESSION_BROTLI_BROTLICOMPRESSIONALGORITHM_H
#define NUCLEX_STORAGE_COMPRESSION_BROTLI_BROTLICOMPRESSIONALGORITHM_H
#include "Nuclex/Storage/Config.h"
#if defined(NUCLEX_STORAGE_HAVE_BROTLI)
#include "Nuclex/Storage/Compression/CompressionAlgorithm.h"
namespace Nuclex { namespace Storage { namespace Compression { namespace Brotli {
// ------------------------------------------------------------------------------------------- //
/// Provides compressors and decompressors using Google's Brotli algorithm
class BrotliCompressionAlgorithm : public CompressionAlgorithm {
/// Quality parameter that results in the fastest compression
public: static const int FastestQuality;
/// Quality parameter that results in the highest ratio compression
public: static const int StrongestQuality;
/// Quality parameter that results in reasonable compression
///
/// There's usually a point where a compression algorithm's time requirement
/// rises exponentially while the gains on terms of compression ratio are just
/// minimal. This quality tries to reflect a point before.
///
public: static const int DefaultQuality;
/// Initializes the Brotli compression algorithm
///
/// Compression quality passed to the Brotli encoder
///
public: BrotliCompressionAlgorithm(int compressionQuality = DefaultQuality);
/// Frees all resources owned by the instance
public: virtual ~BrotliCompressionAlgorithm() override = default;
/// Returns the human-readable name of the compression algorithm
/// The name of the compression algorithm the factory provides
public: const std::string &GetName() const override {
return this->name;
}
/// Returns a unique id for the compression algorithm
/// The compression algorithm's unique id
public: std::array GetId() const override {
return std::array {
'B', 'R', 'T', 'L', '0', '0', '0', '1'
};
}
///
/// Returns the average number of CPU cycles this algorithm runs for to
/// compress one kilobyte of data
///
/// The average number of CPU cycles to comrpess one kilobyte
public: std::size_t GetCompressionCyclesPerKilobyte() const override {
return 15000;
};
///
/// Returns the average size of data compressed with this algorithm as compared
/// to its uncompressed size
///
/// The average ratio of compressed size to uncompressed size
public: float GetAverageCompressionRatio() const override {
return 0.85f;
}
/*
/// Returns the file extensions this codec is especially suited for
/// A list of file extensions for which this codec is suitable
///
/// Some algorithms are better suited for certain file types. This method returns
/// a list helping the caller decide whether the compression algorithm will achieve
/// good results for a known file extension.
///
public: virtual const std::vector &GetSuitableExtensions() const;
*/
/// Creates a new data compressor
/// A new data compressor of the algorithm's type
public: std::unique_ptr CreateCompressor() const override;
/// Creates a new data decompressor
/// A new data decompressor of the algorithm's type
public: std::unique_ptr CreateDecompressor() const override;
/// The name of the compression algorithm
private: std::string name;
/// Compression quality that will be used when compressing things
private: int quality;
};
// ------------------------------------------------------------------------------------------- //
}}}} // namespace Nuclex::Storage::Compression::Brotli
#endif // defined(NUCLEX_STORAGE_HAVE_BROTLI)
#endif // NUCLEX_STORAGE_COMPRESSION_BROTLI_BROTLICOMPRESSOR_H