forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip_asset_store.h
59 lines (41 loc) · 1.53 KB
/
zip_asset_store.h
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
54
55
56
57
58
59
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_ASSETS_ZIP_ASSET_STORE_H_
#define FLUTTER_ASSETS_ZIP_ASSET_STORE_H_
#include <map>
#include "flutter/assets/asset_resolver.h"
#include "flutter/fml/macros.h"
#include "third_party/zlib/contrib/minizip/unzip.h"
namespace flutter {
struct UniqueUnzipperTraits {
static inline void* InvalidValue() { return nullptr; }
static inline bool IsValid(void* value) { return value != InvalidValue(); }
static void Free(void* file);
};
using UniqueUnzipper = fml::UniqueObject<void*, UniqueUnzipperTraits>;
class ZipAssetStore final : public AssetResolver {
public:
ZipAssetStore(std::string file_path, std::string directory);
~ZipAssetStore() override;
private:
struct CacheEntry {
unz_file_pos file_pos;
size_t uncompressed_size;
CacheEntry(unz_file_pos p_file_pos, size_t p_uncompressed_size)
: file_pos(p_file_pos), uncompressed_size(p_uncompressed_size) {}
};
const std::string file_path_;
const std::string directory_;
mutable std::map<std::string, CacheEntry> stat_cache_;
// |AssetResolver|
bool IsValid() const override;
// |AssetResolver|
std::unique_ptr<fml::Mapping> GetAsMapping(
const std::string& asset_name) const override;
void BuildStatCache();
UniqueUnzipper CreateUnzipper() const;
FML_DISALLOW_COPY_AND_ASSIGN(ZipAssetStore);
};
} // namespace flutter
#endif // FLUTTER_ASSETS_ZIP_ASSET_STORE_H_