1/* This file is part of Strigi Desktop Search
2 *
3 * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20#ifndef STRIGI_ZIPINPUTSTREAM_H
21#define STRIGI_ZIPINPUTSTREAM_H
22
23#include <strigi/substreamprovider.h>
24#include <strigi/gzipinputstream.h>
25
26namespace Strigi {
27
28/**
29 * Partial implementation of the zip file format according to
30 * http://www.pkware.com/business_and_developers/developer/popups/appnote.txt
31 * http://www.pkware.com/documents/casestudies/APPNOTE.TXT
32 * 99% of zip files on my system can be read with this class.
33 * Exceptions are files that are (at least)
34 * - files generated by writing to stdout
35 * - files using other compression as deflated
36 * - encrypted files
37 **/
38class STREAMS_EXPORT ZipInputStream : public SubStreamProvider {
39private:
40 // information relating to the current entry
41 InputStream* compressedEntryStream;
42 GZipInputStream *uncompressionStream;
43 int32_t entryCompressedSize;
44 int32_t compressionMethod;
45
46 void readFileName(int32_t len);
47 void readHeader();
48public:
49 explicit ZipInputStream(InputStream* input);
50 ~ZipInputStream();
51 InputStream* nextEntry();
52 static bool checkHeader(const char* data, int32_t datasize);
53 static SubStreamProvider* factory(InputStream* input) {
54 return new ZipInputStream(input);
55 }
56};
57
58} // end namespace Strigi
59
60#endif
61