Archive::Archive(const base::FilePath& path)
: path_(path),
+ file_(path_, base::File::FLAG_OPEN | base::File::FLAG_READ),
header_size_(0) {
}
}
bool Archive::Init() {
- base::File file(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
- if (!file.IsValid())
+ if (!file_.IsValid())
return false;
std::vector<char> buf;
int len;
buf.resize(8);
- len = file.ReadAtCurrentPos(buf.data(), buf.size());
+ len = file_.ReadAtCurrentPos(buf.data(), buf.size());
if (len != static_cast<int>(buf.size())) {
PLOG(ERROR) << "Failed to read header size from " << path_.value();
return false;
}
buf.resize(size);
- len = file.ReadAtCurrentPos(buf.data(), buf.size());
+ len = file_.ReadAtCurrentPos(buf.data(), buf.size());
if (len != static_cast<int>(buf.size())) {
PLOG(ERROR) << "Failed to read header from " << path_.value();
return false;
}
scoped_ptr<ScopedTemporaryFile> temp_file(new ScopedTemporaryFile);
- if (!temp_file->InitFromFile(path_, info.offset, info.size))
+ if (!temp_file->InitFromFile(file_, info.offset, info.size))
return false;
*out = temp_file->path();
#include <vector>
#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
private:
base::FilePath path_;
+ base::File file_;
uint32 header_size_;
scoped_ptr<base::DictionaryValue> header_;
return base::CreateTemporaryFile(&path_);
}
-bool ScopedTemporaryFile::InitFromFile(const base::FilePath& path,
+bool ScopedTemporaryFile::InitFromFile(base::File& src,
uint64 offset, uint64 size) {
- if (!Init())
+ if (!src.IsValid())
return false;
- base::File src(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
- if (!src.IsValid())
+ if (!Init())
return false;
std::vector<char> buf(size);
#include "base/files/file_path.h"
+namespace base {
+class File;
+}
+
namespace asar {
// An object representing a temporary file that should be cleaned up when this
bool Init();
// Init an temporary file and fill it with content of |path|.
- bool InitFromFile(const base::FilePath& path, uint64 offset, uint64 size);
+ bool InitFromFile(base::File& src, uint64 offset, uint64 size);
base::FilePath path() const { return path_; }