小编Dev*_*Hod的帖子

在流中使用节点请求或axios来下载和解压缩文件,是否无法按预期处理背压?

我们有一个大约6 GB的大文件,需要将其解压缩为64 GB大小(OS映像),我们需要使用http下载该文件。我们正在使用节点的请求库或axios。使用以下代码即时下载和解压缩文件(管道):

 const downloadUsingHttp = (downloadUrl, destinationPath) => {enter code here
      return new Promise((resolve, reject) => {
        const unpackedPathWriteStream = fs.createWriteStream(destinationPath);

        let totalDownloadSize = 64023257088;
        let downloadedSize = 0;
        let lastProgressSent = 0;

        axios({
          method: 'get',
          url: downloadUrl,
          responseType: 'stream',
          auth: {
            username: 'user',
            password: 'pass'
          },
            withCredentials: true
         }).then(function (response) {
            response.data
              .on('data', chunk => {
                if (totalDownloadSize === 0) {
                  return;
                }
                downloadedSize += chunk.length;
                const progress = Math.floor((downloadedSize / totalDownloadSize) * 100);

                if (progress % 5 …
Run Code Online (Sandbox Code Playgroud)

javascript zlib request node.js axios

5
推荐指数
1
解决办法
208
查看次数

标签 统计

axios ×1

javascript ×1

node.js ×1

request ×1

zlib ×1