"```javascript const url = 'example.com/file.zip';
fetch(url).then(response => { const total = response.headers.get('content-length'); let downloaded = 0;
const reader = response.body.getReader();
reader.read().then(function processResult(result) {
if (result.done) {
console.log('Download complete');
return;
}
const chunk = result.value;
downloaded += chunk.byteLength;
// 计算下载进度
const progress = Math.round((downloaded / total) * 100);
console.log(`Downloaded ${progress}%`);
// 继续读取下一个数据块
return reader.read().then(processResult);
});
}).catch(error => { console.error('Download error:', error); });