javascript - 如何使用 chrome 应用程序文件系统将 FileEntry 转换为标准的 JavaScript 文件对象

标签 javascript filesystems google-chrome-app

是否可以将 FileEntry 转换为标准的 JavaScript 对象 File? 我在文档中找不到任何有意义的内容 https://developer.chrome.com/apps/fileSystem

最佳答案

FileEntry documentation确实在此处提供指导:

The FileSystemFileEntry interface of the File System API represents a file in a file system. It offers properties describing the file's attributes, as well as the file() method, which creates a File object that can be used to read the file.

不幸的是,file()方法依赖于回调而不是 Promises,但我们可以包装它并使使用 API(和阅读代码)更容易:

async function getFile(fileEntry) {
  try {
    return new Promise((resolve, reject) => fileEntry.file(resolve, reject));
  } catch (err) {
    console.log(err);
  }
}

// From inside an async method or JS module
let file = await getFile(fileEntry); // Wait until we have the file

关于javascript - 如何使用 chrome 应用程序文件系统将 FileEntry 转换为标准的 JavaScript 文件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45052875/

相关文章:

javascript - 如何从两个不同的 fs 方法创建对象?

c - 自定义文件打开函数在 Linux 内核中覆盖 sys_call_table 时的奇怪行为

mobile - Chrome Dev Editor中的Mobile Dart工作流程

google-chrome - Screencastify Chrome 应用程序如何工作?

javascript - Vue.js 2.0 主实例

javascript - Angular 2 : Expression has changed after it was checked on accessing child component property

windows - 为什么 Windows 将新创建文件的 "created time"属性设置为旧时间?

html - 我正在创建一个 chrome 应用程序来编辑纯文本,我正在使用 <textarea> 来完成此操作。它不会全尺寸

javascript - chrome.storage 从数组中删除特定项目

javascript - 将 json 对象发布到服务器时出现 404 错误请求