我们有一个大约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)