aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ijar/zlib_client.h
diff options
context:
space:
mode:
authorGravatar Rumou Duan <rduan@google.com>2016-09-21 21:59:01 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-22 09:55:50 +0000
commita518f63e6a9f42996b1707dd6bb9a9287eb5b675 (patch)
tree0dc35c1f3a1dd9a7b6f2297a23b32a82e35ede4f /third_party/ijar/zlib_client.h
parentd7886f0589c217f90dca42cb5269d004ed3abbd1 (diff)
Move zlib-interfacing code from third_party/ijar/zip.cc into a separate class. And add a dummy zlib client.
-- MOS_MIGRATED_REVID=133879880
Diffstat (limited to 'third_party/ijar/zlib_client.h')
-rw-r--r--third_party/ijar/zlib_client.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/third_party/ijar/zlib_client.h b/third_party/ijar/zlib_client.h
new file mode 100644
index 0000000000..ed6616362f
--- /dev/null
+++ b/third_party/ijar/zlib_client.h
@@ -0,0 +1,68 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef THIRD_PARTY_IJAR_ZLIB_CLIENT_H_
+#define THIRD_PARTY_IJAR_ZLIB_CLIENT_H_
+
+#include <limits.h>
+
+#include "third_party/ijar/common.h"
+
+namespace devtools_ijar {
+// Try to compress a file entry in memory using the deflate algorithm.
+// It will compress buf (of size length) unless the compressed size is bigger
+// than the input size. The result will overwrite the content of buf and the
+// final size is returned.
+size_t TryDeflate(u1* buf, size_t length);
+
+u4 ComputeCrcChecksum(u1* buf, size_t length);
+
+struct DecompressedFile {
+ u1* uncompressed_data;
+ u4 uncompressed_size;
+ u4 compressed_size;
+};
+
+class Decompressor {
+ public:
+ Decompressor();
+ ~Decompressor();
+ DecompressedFile* UncompressFile(const u1* buffer, size_t bytes_avail);
+ char* GetError();
+
+ private:
+ // Administration of memory reserved for decompressed data. We use the same
+ // buffer for each file to avoid some malloc()/free() calls and free the
+ // memory only in the dtor. C-style memory management is used so that we
+ // can call realloc.
+ u1* uncompressed_data_;
+ size_t uncompressed_data_allocated_;
+ // last error
+ char errmsg[4 * PATH_MAX];
+
+ int error(const char* fmt, ...);
+
+ // Buffer size is initially INITIAL_BUFFER_SIZE. It doubles in size every
+ // time it is found too small, until it reaches MAX_BUFFER_SIZE. If that is
+ // not enough, we bail out. We only decompress class files, so they should
+ // be smaller than 64K anyway, but we give a little leeway.
+ // MAX_BUFFER_SIZE must be bigger than the size of the biggest file in the
+ // ZIP. It is set to 2GB here because no one has audited the code for 64-bit
+ // cleanliness.
+ static const size_t INITIAL_BUFFER_SIZE = 256 * 1024; // 256K
+ static const size_t MAX_BUFFER_SIZE = std::numeric_limits<int32_t>::max();
+};
+} // namespace devtools_ijar
+
+#endif // THIRD_PARTY_IJAR_ZLIB_CLIENT_H_