尝试使用TS和HTML5创建文本文件

尝试使用TS和HTML5创建文本文件,html,typescript,html5-filesystem,Html,Typescript,Html5 Filesystem,在我的应用程序中,我收到一个字符串,需要保存到本地机器。阅读指南(html5文件系统教程)。我必须使用TS(“typescript”:“2.6.1”)来解决这个问题,看起来API的一部分不受支持。下一行给出了两个错误: window.requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, this.errorHandler); 第一: [ts] Property 'requestFileSystem' does not exist

在我的应用程序中,我收到一个
字符串
,需要保存到本地机器。阅读指南(html5文件系统教程)。我必须使用TS(“typescript”:“2.6.1”)来解决这个问题,看起来API的一部分不受支持。下一行给出了两个错误:

  window.requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, this.errorHandler);
第一:

[ts] Property 'requestFileSystem' does not exist on type 'Window'.
第二:

[ts] Property 'TEMPORARY' does not exist on type 'Window'.

是否有解决方法或更新的文档?PS我知道这仅在Chrome中受支持。

此API目前仅在其他浏览器中使用,不适用于其他浏览器。但是,如果您使用的是Chrome,则必须使用此函数的前缀版本,即
webkitRequestFileSystem

var requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
该支持也适用于
window.TEMPORARY

现在,如果要创建一个文件并在其中写入一些内容,必须创建一个所谓的writer对象:

function onInitFs(fs) {
  fs.root.getFile('my-file.txt', {create: true}, function(fileEntry) {
    fileEntry.createWriter(function(fileWriter) {
      fileWriter.onwriteend = function(e) {
        ...
      };

      fileWriter.onerror = function(e) {
        ...
      };

      var blob = new Blob(['Content that goes into the file'], {type: 'text/plain'});

      fileWriter.write(blob);
    }, errorHandler);
  }, errorHandler);
}

requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler);
有关
FileSystemFileEntry
API的更多信息,请查看