【问题标题】:Is chrome.fileSystem usable inside google Native Clientchrome.fileSystem 在 google Native Client 中是否可用
【发布时间】:2015-07-02 01:16:04
【问题描述】:

是否可以在NaCl 中使用chrome.fileSystem

谢谢

【问题讨论】:

  • 我的猜测是“可能不会”,但是看到您可以访问 HTML5 文件系统,您可以在最坏的情况下复制到那里使用它。但我不太了解这个话题。
  • @Xan 感谢您的评论!

标签: google-chrome google-chrome-extension google-chrome-app google-nativeclient


【解决方案1】:

The chrome.fileSystem API 允许您通过 Chrome 应用程序访问用户的本地文件系统。这需要用户选择要公开给应用程序的目录。

此文件系统可以传递给 NaCl 模块,然后与标准 NaCl pp::FileSystem API 一起使用。

examples/tutorial/filesystem_passing 的 NaCl SDK 中有一个示例。你可以浏览它的代码here

以下是重要部分: JavaScript:

chrome.fileSystem.chooseEntry({type: 'openDirectory'}, function(entry) {
  if (!entry) {
    // The user cancelled the dialog.
    return;
  }

  // Send the filesystem and the directory path to the NaCl module.
  common.naclModule.postMessage({
    filesystem: entry.filesystem,
    fullPath: entry.fullPath
  });
});

C++:

// Got a message from JavaScript. We're assuming it is a dictionary with
// two elements:
//   {
//     filesystem: <A Filesystem var>,
//     fullPath: <A string>
//   }
pp::VarDictionary var_dict(var_message);
pp::Resource filesystem_resource = var_dict.Get("filesystem").AsResource();
pp::FileSystem filesystem(filesystem_resource);
std::string full_path = var_dict.Get("fullPath").AsString();
std::string save_path = full_path + "/hello_from_nacl.txt";
std::string contents = "Hello, from Native Client!\n";

请务必注意,此文件系统中的所有路径都必须以 full_path 为前缀。任何其他访问都将失败。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多