forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip_reader.hpp
53 lines (38 loc) · 1.66 KB
/
zip_reader.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "base/exception.hpp"
#include "std/function.hpp"
#include "std/utility.hpp"
class ZipFileReader : public FileReader
{
private:
uint64_t m_uncompressedFileSize;
public:
struct Delegate
{
virtual ~Delegate() = default;
// When |size| is zero, end of file is reached.
virtual void OnBlockUnzipped(size_t size, char const * data) = 0;
virtual void OnStarted() {}
virtual void OnCompleted() {}
};
typedef function<void(uint64_t, uint64_t)> ProgressFn;
/// Contains file name inside zip and it's uncompressed size
typedef vector<pair<string, uint32_t> > FileListT;
DECLARE_EXCEPTION(OpenZipException, OpenException);
DECLARE_EXCEPTION(LocateZipException, OpenException);
DECLARE_EXCEPTION(InvalidZipException, OpenException);
/// @param[in] logPageSize, logPageCount default values are equal with FileReader constructor.
ZipFileReader(string const & container, string const & file,
uint32_t logPageSize = 10, uint32_t logPageCount = 4);
/// @note Size() returns compressed file size inside zip
uint64_t UncompressedSize() const { return m_uncompressedFileSize; }
/// @warning Can also throw Writer::OpenException and Writer::WriteException
static void UnzipFile(string const & zipContainer, string const & fileInZip, Delegate & delegate);
static void UnzipFile(string const & zipContainer, string const & fileInZip,
string const & outPath);
static void FilesList(string const & zipContainer, FileListT & filesList);
/// Quick version without exceptions
static bool IsZip(string const & zipContainer);
};