javascript - 进行并行下载时,React-Native-fs 下载速度慢
问题描述
下载单个文件时我能够有很好的速度。但是当我开始下载多个文件时,下载速度太差了。我开始这是我的代码
import { DocumentDirectoryPath, exists, mkdir, readDir, downloadFile, writeFile , readFile} from 'react-native-fs'
function download(fileId, fileUrl){
let path = DocumentDirectoryPath+'/'+'Learning/'+fileId;
let zipPath =DocumentDirectoryPath+'/'+'Learning/'+fileId+"/Compressed.zip";
let exist = await exists(path);
if(exist === false){
await mkdir(path);
console.log("path created", path)
}
//alert("======"+fileUrl)
const downloadPromise = downloadFile({
fromUrl: fileUrl ,
toFile: zipPath,
progress: function ({contentLength, jobId, bytesWritten}) {
if (jobId === downloadPromise.jobId) {
progressCallback(bytesWritten / contentLength);
console.log( "\b",bytesWritten / contentLength)
}
},
});
const downloadResult = await downloadPromise.promise;}
然后像这样开始多次下载:
let files = [{url: "https//....", id: "y6HS6"}, {url: "https//....", id: "y6HghhS6"}]
files.map(item =>{
download(item.id, item.url)
})
解决方案
推荐阅读
- google-bigquery - 查询字段值的数据类型是数字(INT64)还是其他数据类型
- javascript - 使用 Google 应用脚本更新 Salesforce 字段
- enterprise-architect - 在 Enterprise Architect 中建模网络交互的正确方法
- ios - 如何在tabBarController中连接VC throw navController以快速传递数据
- delphi - 有没有办法让我看到视觉和非视觉组件背后的代码?
- tensorflow - 我的 Xception 模型出现以下错误。(GPU 开启)
- unicode - UTF-8 表与小写和大写以及它们之间的关系
- webstorm - WebStorm:关闭未使用的导入的自动删除
- typescript - TS中两种对象类型的深度交集类型
- java - 命令行太长。缩短 Test 或 JUnit 默认配置的命令行?