2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __LIBS_STREAMINGZIPINFLATER_H
18 #define __LIBS_STREAMINGZIPINFLATER_H
24 #include <utils/Compat.h>
28 class StreamingZipInflater {
30 static const size_t INPUT_CHUNK_SIZE = 64 * 1024;
31 static const size_t OUTPUT_CHUNK_SIZE = 64 * 1024;
33 // Flavor that pages in the compressed data from a fd
34 StreamingZipInflater(int fd, off64_t compDataStart, size_t uncompSize, size_t compSize);
36 // Flavor that gets the compressed data from an in-memory buffer
37 StreamingZipInflater(class FileMap* dataMap, size_t uncompSize);
39 ~StreamingZipInflater();
41 // read 'count' bytes of uncompressed data from the current position. outBuf may
42 // be NULL, in which case the data is consumed and discarded.
43 ssize_t read(void* outBuf, size_t count);
45 // seeking backwards requires uncompressing fom the beginning, so is very
46 // expensive. seeking forwards only requires uncompressing from the current
47 // position to the destination.
48 off64_t seekAbsolute(off64_t absoluteInputPosition);
51 void initInflateState();
54 // where to find the uncompressed data
56 off64_t mInFileStart; // where the compressed data lives in the file
57 class FileMap* mDataMap;
59 z_stream mInflateState;
60 bool mStreamNeedsInit;
62 // output invariants for this asset
63 uint8_t* mOutBuf; // output buf for decompressed bytes
64 size_t mOutBufSize; // allocated size of mOutBuf
65 size_t mOutTotalSize; // total uncompressed size of the blob
67 // current output state bookkeeping
68 off64_t mOutCurPosition; // current position in total offset
69 size_t mOutLastDecoded; // last decoded byte + 1 in mOutbuf
70 size_t mOutDeliverable; // next undelivered byte of decoded output in mOutBuf
74 size_t mInBufSize; // allocated size of mInBuf;
75 size_t mInTotalSize; // total size of compressed data for this blob
77 // input state bookkeeping
78 size_t mInNextChunkOffset; // offset from start of blob at which the next input chunk lies
79 // the z_stream contains state about input block consumption