Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
GZip.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
8#include "Stroika/Foundation/Execution/FeatureNotSupportedException.h"
9
10#if qStroika_HasComponent_zlib
11#include "Private_/ZLibSupport.h"
12#endif
13
14#include "GZip.h"
15
16using std::byte;
17
18using namespace Stroika::Foundation;
22using namespace Stroika::Foundation::Debug;
23using namespace Stroika::Foundation::Streams;
24
25// Comment this in to turn on aggressive noisy DbgTrace in this module
26//#define USE_NOISY_TRACE_IN_THIS_MODULE_ 1
27
28#if !qStroika_HasComponent_zlib
29namespace {
30 const auto kNotSuppExcept_ = Execution::FeatureNotSupportedException{"GZip (ZLIB)"sv};
31}
32#endif
33#if qStroika_HasComponent_zlib
34using Compression::Private_::DeflateRep_;
35using Compression::Private_::InflateRep_;
36#endif
37
38Compression::Ptr GZip::Compress::New (const GZip::Compress::Options& o)
39{
40#if qStroika_HasComponent_zlib
41 struct MyRep_ : IRep {
42 GZip::Compress::Options fOptions_;
43 shared_ptr<DeflateRep_> fDelegate2;
44 MyRep_ (const GZip::Compress::Options& o)
45 : fOptions_{o}
46 {
47 }
49 {
50 fDelegate2 = make_shared<Private_::DeflateRep_> (src, fOptions_, true);
51 return InputStream::Ptr<byte>{fDelegate2};
52 }
53 virtual optional<Compression::Stats> GetStats () const
54 {
55 return nullopt;
56 }
57 };
58 return Compression::Ptr{make_shared<MyRep_> (o)};
59#else
60 Execution::Throw (kNotSuppExcept_);
61#endif
62}
63Compression::Ptr GZip::Decompress::New ([[maybe_unused]] const GZip::Decompress::Options& o)
64{
65#if qStroika_HasComponent_zlib
66 struct MyRep_ : IRep {
67 shared_ptr<InflateRep_> fDelegate2;
69 {
70 fDelegate2 = make_shared<InflateRep_> (src, true);
71 return InputStream::Ptr<byte>{fDelegate2};
72 }
73 virtual optional<Compression::Stats> GetStats () const
74 {
75 return nullopt;
76 }
77 };
78 return Compression::Ptr{make_shared<MyRep_> ()};
79#else
80 Execution::Throw (kNotSuppExcept_);
81#endif
82}
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...
Definition Throw.inl:43
virtual InputStream::Ptr< byte > Transform(const InputStream::Ptr< byte > &src)=0
virtual optional< Stats > GetStats() const =0