5

Is it possible to use chrome.fileSystem inside NaCl?

Thanks

KaBa
  • 285
  • 3
  • 16
  • My guess is "probably not", but seeing that you can access the HTML5 filesystem you could, at worst, copy there to work with it. But I don't know the topic well enough. – Xan Apr 23 '15 at 17:33

1 Answers1

6

The chrome.fileSystem API allows you to access the user's local filesystem via a Chrome App. This requires a user to pick a directory to expose to the App.

This filesystem can be passed to the NaCl module and then used with the standard NaCl pp::FileSystem API.

There is an example of this in the NaCl SDK at examples/tutorial/filesystem_passing. You can browse the code for it here.

Here are the important parts: 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";

It's important to note that all paths in this FileSystem must be prefixed with full_path. Any other accesses will fail.

binji
  • 1,860
  • 9
  • 9