| 69 | }; |
| 70 | |
| 71 | DeflateWriteStream::DeflateWriteStream(WriteStream* outStream, int compressionLevel, bool gzip) |
| 72 | : impl(std::make_unique<DeflateWriteStream::Impl>()) { |
| 73 | |
| 74 | // There has existed at some point at least one zlib implementation which thought it was being |
| 75 | // clever by randomizing the compression level. This is actually not entirely incorrect, except |
| 76 | // for the no-compression level which should always be deterministically pass-through. |
| 77 | // Users should instead consider the zero compression level broken and handle it themselves. |
| 78 | DEBUG_ASSERT(compressionLevel != 0); |
| 79 | |
| 80 | impl->outStream = outStream; |
| 81 | impl->inBufferIndex = 0; |
| 82 | if (!impl->outStream) { |
| 83 | return; |
| 84 | } |
| 85 | impl->ZStream.next_in = nullptr; |
| 86 | impl->ZStream.zalloc = &AllocFunction; |
| 87 | impl->ZStream.zfree = &FreeFunction; |
| 88 | impl->ZStream.opaque = nullptr; |
| 89 | DEBUG_ASSERT((compressionLevel <= 9 && compressionLevel >= -1)); |
| 90 | deflateInit2(&impl->ZStream, compressionLevel, Z_DEFLATED, gzip ? 0x1F : 0x0F, 8, |
| 91 | Z_DEFAULT_STRATEGY); |
| 92 | } |
| 93 | |
| 94 | DeflateWriteStream::~DeflateWriteStream() { |
| 95 | this->finalize(); |
nothing calls this directly
no outgoing calls
no test coverage detected