Make fs.readdir support asar package.
This commit is contained in:
parent
9f9d209e3d
commit
0cab034dab
4 changed files with 80 additions and 12 deletions
|
@ -162,4 +162,25 @@ bool Archive::Stat(const base::FilePath& path, Stats* stats) {
|
|||
return FillFileInfoWithNode(stats, header_size_, node);
|
||||
}
|
||||
|
||||
bool Archive::Readdir(const base::FilePath& path,
|
||||
std::vector<base::FilePath>* list) {
|
||||
if (!header_)
|
||||
return false;
|
||||
|
||||
const base::DictionaryValue* node;
|
||||
if (!GetNodeFromPath(path.AsUTF8Unsafe(), header_.get(), &node))
|
||||
return false;
|
||||
|
||||
const base::DictionaryValue* files;
|
||||
if (!node->GetDictionaryWithoutPathExpansion("files", &files))
|
||||
return false;
|
||||
|
||||
base::DictionaryValue::Iterator iter(*files);
|
||||
while (!iter.IsAtEnd()) {
|
||||
list->push_back(base::FilePath::FromUTF8Unsafe(iter.key()));
|
||||
iter.Advance();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef ATOM_COMMON_ASAR_ARCHIVE_H_
|
||||
#define ATOM_COMMON_ASAR_ARCHIVE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
|
@ -41,6 +43,9 @@ class Archive : public base::RefCounted<Archive> {
|
|||
// Fs.stat(path).
|
||||
bool Stat(const base::FilePath& path, Stats* stats);
|
||||
|
||||
// Fs.readdir(path).
|
||||
bool Readdir(const base::FilePath& path, std::vector<base::FilePath>* files);
|
||||
|
||||
base::FilePath path() const { return path_; }
|
||||
base::DictionaryValue* header() const { return header_.get(); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue