shangxinli commented on code in PR #1014:
URL: https://github.com/apache/iceberg-cpp/pull/1014#discussion_r4284535799
##########
src/iceberg/util/gzip_internal.cc:
##########
@@ -86,6 +87,60 @@ class ZlibImpl {
z_stream stream_;
};
+class ZlibDeflateImpl {
+ public:
+ ZlibDeflateImpl() { memset(&stream_, 0, sizeof(stream_)); }
+
+ ~ZlibDeflateImpl() {
+ if (initialized_) {
+ deflateEnd(&stream_);
+ }
+ }
+
+ Status Init() {
+ // Maximum window size, plus the offset that selects a gzip wrapper over
+ // the raw zlib one, so GZipDecompressor's auto-detection accepts it.
+ constexpr int kWindowBits = 15;
+ constexpr int kGzipWrapper = 16;
+ int ret = deflateInit2(&stream_, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+ kWindowBits | kGzipWrapper, 8, Z_DEFAULT_STRATEGY);
+ if (ret != Z_OK) {
+ return CompressError("deflateInit2 failed, result:{}", ret);
+ }
+ initialized_ = true;
+ return {};
+ }
+
+ Result<std::string> Compress(const std::string& data) {
Review Comment:
No deflateReset() here, so a second Compress() on the same GZipCompressor
fails once the first hits Z_STREAM_END. Only latent today since Write() builds
a fresh one, but the Init()/Compress() split reads as reusable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]