Make NativeImage work with asar archive

This commit is contained in:
Cheng Zhao 2015-02-12 19:34:21 +08:00
parent 98a7f08be2
commit 3678f13dfb
3 changed files with 28 additions and 2 deletions

View file

@ -8,6 +8,7 @@
#include "atom/common/asar/archive.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/stl_util.h"
@ -57,4 +58,26 @@ bool GetAsarArchivePath(const base::FilePath& full_path,
return true;
}
bool ReadFileToString(const base::FilePath& path, std::string* contents) {
base::FilePath asar_path, relative_path;
if (!GetAsarArchivePath(path, &asar_path, &relative_path))
return base::ReadFileToString(path, contents);
std::shared_ptr<Archive> archive = GetOrCreateAsarArchive(asar_path);
if (!archive)
return false;
Archive::FileInfo info;
if (!archive->GetFileInfo(relative_path, &info))
return false;
base::File src(asar_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!src.IsValid())
return false;
contents->resize(info.size);
return static_cast<int>(info.size) == src.Read(
info.offset, const_cast<char*>(contents->data()), contents->size());
}
} // namespace asar