【问题标题】:GitHub - octokit - ArrayBuffer[Unit8Contents] -> converting to a tar / zip fileGitHub - octokit - ArrayBuffer[Unit8Contents] -> 转换为 tar / zip 文件
【发布时间】:2021-10-10 08:04:13
【问题描述】:

我开始使用 nodejs octokit。使用以下代码(来自 github 文档的示例代码),我能够从 Github 存储库中检索 .tar 文件:

await octokit.request('GET /repos/{owner}/{repo}/tarball/{ref}', {
  owner: 'octocat',
  repo: 'hello-world',
  ref: 'ref'
})

接收到的 .tar 文件存储在一个 json 文件中,编码如下:

data: w [ArrayBuffer] {
    [Uint8Contents]: <01 e7 ... 26850189 more bytes>,
    byteLength: 26850289
  }

我正在寻找一种解决方案,将带有 [Uint8Contents] 的 ArrayBuffer 转换为实际的 tar 文件并将其保存到我的 nodejs 项目中的文件夹中。大量谷歌搜索并没有找到解决方案。

很高兴得到一些帮助。

【问题讨论】:

    标签: node.js arraybuffer octokit-js


    【解决方案1】:

    找到了解决办法。这很容易:

    const fs = require('fs');
    fs.writeFileSync('filename or complete path', Buffer.from(buffer_data));
    

    【讨论】:

      猜你喜欢
      • 2021-08-24
      • 1970-01-01
      • 2017-12-15
      • 2011-04-22
      • 2016-12-30
      • 2012-06-16
      • 2013-08-28
      • 1970-01-01
      • 2011-11-25
      相关资源
      最近更新 更多