Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
GZip.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
8#include "Stroika/Foundation/Execution/FeatureNotSupportedException.h"
10
11#if qStroika_HasComponent_zlib
12#include "Stroika/Foundation/DataExchange/Compression/Private_/ZLibSupport.h"
13#endif
14
15#include "GZip.h"
16
17using std::byte;
18
19using namespace Stroika::Foundation;
23using namespace Stroika::Foundation::Debug;
24using namespace Stroika::Foundation::Streams;
25
26// Comment this in to turn on aggressive noisy DbgTrace in this module
27//#define USE_NOISY_TRACE_IN_THIS_MODULE_ 1
28
29#if !qStroika_HasComponent_zlib
30namespace {
31 const auto kNotSuppExcept_ = Execution::FeatureNotSupportedException{"GZip (ZLIB)"sv};
32}
33#endif
34#if qStroika_HasComponent_zlib
35using Compression::Private_::DeflateRep_;
36using Compression::Private_::InflateRep_;
37#endif
38
39Compression::Ptr GZip::Compress::New (const GZip::Compress::Options& o)
40{
41#if qStroika_HasComponent_zlib
42 struct MyRep_ final : IRep, public Memory::UseBlockAllocationIfAppropriate<MyRep_> {
43 GZip::Compress::Options fOptions_;
44 shared_ptr<DeflateRep_> fDelegate2;
45 MyRep_ (const GZip::Compress::Options& o)
46 : fOptions_{o}
47 {
48 }
50 {
51 fDelegate2 = Memory::MakeSharedPtr<Private_::DeflateRep_> (src, fOptions_, true);
52 return InputStream::Ptr<byte>{fDelegate2};
53 }
54 virtual optional<Compression::Stats> GetStats () const
55 {
56 return nullopt;
57 }
58 };
59 return Compression::Ptr{Memory::MakeSharedPtr<MyRep_> (o)};
60#else
61 Execution::Throw (kNotSuppExcept_);
62#endif
63}
64Compression::Ptr GZip::Decompress::New ([[maybe_unused]] const GZip::Decompress::Options& o)
65{
66#if qStroika_HasComponent_zlib
67 struct MyRep_ final : IRep, public Memory::UseBlockAllocationIfAppropriate<MyRep_> {
68 shared_ptr<InflateRep_> fDelegate2;
70 {
71 fDelegate2 = Memory::MakeSharedPtr<InflateRep_> (src, true);
72 return InputStream::Ptr<byte>{fDelegate2};
73 }
74 virtual optional<Compression::Stats> GetStats () const
75 {
76 return nullopt;
77 }
78 };
79 return Compression::Ptr{Memory::MakeSharedPtr<MyRep_> ()};
80#else
81 Execution::Throw (kNotSuppExcept_);
82#endif
83}
conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocationUseHelper< T >, Common::Empty > UseBlockAllocationIfAppropriate
Use this to enable block allocation for a particular class. Beware of subclassing.
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
virtual InputStream::Ptr< byte > Transform(const InputStream::Ptr< byte > &src)=0
virtual optional< Stats > GetStats() const =0