return mate::ConvertToV8(isolate, new_path);
}
+ // Return the file descriptor.
+ int GetFD() const {
+ if (!archive_)
+ return -1;
+ return archive_->GetFD();
+ }
+
// Free the resources used by archive.
void Destroy() {
archive_.reset();
.SetMethod("readdir", &Archive::Readdir)
.SetMethod("realpath", &Archive::Realpath)
.SetMethod("copyFileOut", &Archive::CopyFileOut)
+ .SetMethod("getFd", &Archive::GetFD)
.SetMethod("destroy", &Archive::Destroy);
}
#include "atom/common/asar/archive.h"
+#if defined(OS_WIN)
+#include <io.h>
+#endif
+
#include <string>
#include <vector>
}
scoped_ptr<ScopedTemporaryFile> temp_file(new ScopedTemporaryFile);
- if (!temp_file->InitFromFile(file_, info.offset, info.size))
+ if (!temp_file->InitFromFile(&file_, info.offset, info.size))
return false;
*out = temp_file->path();
return true;
}
+int Archive::GetFD() const {
+ if (!file_.IsValid())
+ return -1;
+
+#if defined(OS_WIN)
+ return
+ _open_osfhandle(reinterpret_cast<intptr_t>(file_.GetPlatformFile()), 0);
+#elif defined(OS_POSIX)
+ return file_.GetPlatformFile();
+#else
+ return -1;
+#endif
+}
+
} // namespace asar
// For unpacked file, this method will return its real path.
bool CopyFileOut(const base::FilePath& path, base::FilePath* out);
+ // Returns the file's fd.
+ int GetFD() const;
+
base::FilePath path() const { return path_; }
base::DictionaryValue* header() const { return header_.get(); }
return base::CreateTemporaryFile(&path_);
}
-bool ScopedTemporaryFile::InitFromFile(base::File& src,
+bool ScopedTemporaryFile::InitFromFile(base::File* src,
uint64 offset, uint64 size) {
- if (!src.IsValid())
+ if (!src->IsValid())
return false;
if (!Init())
return false;
std::vector<char> buf(size);
- int len = src.Read(offset, buf.data(), buf.size());
+ int len = src->Read(offset, buf.data(), buf.size());
if (len != static_cast<int>(size))
return false;
bool Init();
// Init an temporary file and fill it with content of |path|.
- bool InitFromFile(base::File& src, uint64 offset, uint64 size);
+ bool InitFromFile(base::File* src, uint64 offset, uint64 size);
base::FilePath path() const { return path_; }