node.js - 如何以角度连接 forkJoin() 返回的所有结果?
问题描述
我试图从 forkJoin() 返回的数组中获取单个字符串。我有一个大文件,因此我将其分成块并调用 API 和 forkJoining 响应。但我看到我得到了大约 40 个数组。这不是我所期待的。如何连接所有结果数据以表示单个文件数据?
这是我的代码:
比较服务.ts
getFileToCompare (fileSize: number, userRole: String, inFileName: String, inFilePath: String): Observable<any> {
let chunks = [{}];
const chunkSize = 1024 *1024* 20; // 20 kB each chunk
let j = 0;
for (let index = 0; index < fileSize; index += chunkSize + 1) {
chunks[j++] = { startRange: index, endRange: index + chunkSize > fileSize ? fileSize : index + chunkSize };
}
let headers = [];
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
const chunk = chunks[chunkIndex];
const httpHeaders = new HttpHeaders().append('startrange', chunk['startRange']).append('endrange', chunk['endRange']);
headers.push(this.httpClient.post(serviceUri + '/api/getFileToCompare', {
userrole: userRole,
srcfileName: inFileName,
srcfilePath: inFilePath
}, { headers: httpHeaders, responseType: 'json' }));
}
return forkJoin(headers);
}
我的 API:
var options = {
rangeStart: startRange,
rangeEnd: endRange
};
blobService.getBlobToText(containerName, fileName, options, (err, data) => {
if (err) {
log.error(err);
res.status(200).json({
status: 'failed',
data: err
});
} else {
res.status(200).json({
status: 'success',
data: data
});
}
});
比较.component.ts
this.jobService.getFileToCompare(fileSize, this.user.roles[0], fileName,path).toPromise()
.then((res) => {
console.log(res)// n no.of array ...[{status:'success',data:'hdghdh'}{status:'success',data:'xxx'}]
this.originalModel = Object.assign({}, this.originalModel, { code:res }); // res should a string 'hdghdhxxx'
this.modifiedModel = Object.assign({}, this.originalModel, { code:res });
});
}
解决方案
推荐阅读
- c - char 数组 __attribute__ 对齐
- c# - 使用 c# 读取 .PAK 文件
- react-select - 在 React-Select 上创建自定义组件
- reactjs - 编辑依赖库(节点模块)时,React Boilerplate 的 HMR 非常慢
- c# - 当调用同步和异步时,RestSharp 发布请求会获得不同的状态
- netbeans - 当重构错误后无法解决时,如何清理和重建 netbeans 中的项目?
- java - RxNetty 重用连接
- python - 'Return' 究竟做了什么,我应该在何时何地使用它?
- javascript - 在动态大小的文本区域中垂直居中占位符
- javascript - 显示从 firebase 到 ionic 的数据时出错