Support running bundles from zip file. (flutter/engine#5473)

Support running bundles from zip file.
This commit is contained in:
Stanislav Baranov
2018-06-07 15:09:23 -07:00
committed by GitHub
parent 87a506ca5c
commit 5afc3daf35
2 changed files with 11 additions and 5 deletions

View File

@@ -22,8 +22,6 @@ class DirectoryAssetBundle : public AssetResolver {
const fml::UniqueFD descriptor_;
bool is_valid_ = false;
std::string GetPathForAsset(const std::string& asset_name) const;
// |blink::AssetResolver|
bool IsValid() const override;

View File

@@ -9,6 +9,7 @@
#include <utility>
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/assets/zip_asset_store.h"
#include "flutter/common/settings.h"
#include "flutter/fml/file.h"
#include "flutter/fml/platform/android/jni_util.h"
@@ -207,9 +208,16 @@ static void RunBundleAndSnapshot(
if (bundlepath.size() > 0) {
// If we got a bundle path, attempt to use that as a directory asset
// bundle.
asset_manager->PushBack(std::make_unique<blink::DirectoryAssetBundle>(
fml::OpenFile(bundlepath.c_str(), fml::OpenPermission::kRead, true)));
// bundle or a zip asset bundle.
const auto file_ext_index = bundlepath.rfind(".");
if (bundlepath.substr(file_ext_index) == ".zip") {
asset_manager->PushBack(std::make_unique<blink::ZipAssetStore>(
bundlepath));
} else {
asset_manager->PushBack(std::make_unique<blink::DirectoryAssetBundle>(
fml::OpenFile(bundlepath.c_str(), fml::OpenPermission::kRead, true),
bundlepath));
}
// Use the last path component of the bundle path to determine the
// directory in the APK assets.