Javascript 获取zip文件的内容

Javascript 获取zip文件的内容,javascript,typescript,axios,fetch,jszip,Javascript,Typescript,Axios,Fetch,Jszip,下面的URL指向一个zip文件,其中包含一个名为bundlesizes.json的文件。我正在尝试读取我的React应用程序中的json文件的内容(不涉及节点服务器/后端) 通过执行以下操作,我能够获得zip文件的内容 const url = 'https://dev.azure.com/uifabric/cd9e4e13-b8db-429a-9c21-499bf1c98639/_apis/build/builds/8838/artifacts?artifactName=drop&a

下面的
URL
指向一个zip文件,其中包含一个名为
bundlesizes.json
的文件。我正在尝试读取我的
React
应用程序中的
json
文件的内容(不涉及
节点
服务器/后端)

通过执行以下操作,我能够获得
zip
文件的内容

const url =
  'https://dev.azure.com/uifabric/cd9e4e13-b8db-429a-9c21-499bf1c98639/_apis/build/builds/8838/artifacts?artifactName=drop&api-version=4.1&%24format=zip';
const response = await Axios({
  url,
  method: 'GET',
  responseType: 'stream'
});
console.log(response.data);
这将发出zip文件(
非ascii
字符)。但是,我希望读取其中的
bundlesizes.json
文件的内容

为此,我查阅了
jszip
,并尝试了以下方法:

var zip = new JSZip();
zip.createReader(
  new zip.BlobReader(response.data),
  function(reader: any) {
    // get all entries from the zip
    reader.getEntries(function(entries: any) {
      if (entries.length) {
        // get first entry content as text
        entries[0].getData(
          new zip.TextWriter(),
          function(text: any) {
            // text contains the entry data as a String
            console.log(text);

            // close the zip reader
            reader.close(function() {
              // onclose callback
            });
          },
          function(current: any, total: any) {
            // onprogress callback
            console.log(current);
            console.log(total);
          }
        );
      }
    });
  },
  function(error: any) {
    // onerror callback
    console.log(error);
  }
);
但是,这对我来说不起作用,并且会出错。 这是我收到的错误

如何使用
Javascript
/
Typescript
React
应用程序中读取zip中的文件内容

var zip = new JSZip();
zip.createReader(
  new zip.BlobReader(response.data),
  function(reader: any) {
    // get all entries from the zip
    reader.getEntries(function(entries: any) {
      if (entries.length) {
        // get first entry content as text
        entries[0].getData(
          new zip.TextWriter(),
          function(text: any) {
            // text contains the entry data as a String
            console.log(text);

            // close the zip reader
            reader.close(function() {
              // onclose callback
            });
          },
          function(current: any, total: any) {
            // onprogress callback
            console.log(current);
            console.log(total);
          }
        );
      }
    });
  },
  function(error: any) {
    // onerror callback
    console.log(error);
  }
);