javascript - 如何使用多个 .chunk 文件创建文件?
问题描述
我有更多 .chunk 文件,我使用 node-fetch 获取并使用这些文件,我想通过某种方式“将它们收集在一起”来创建另一个文件。
我试过这个:
var fileStream = await fs.createWriteStream(`./paks/${file.Filename.slice(26)}`)
//below code is in a loop, above isn't in a loop
await fetch(chunkURL)
.then(async res => {
if(chunks.indexOf(chunk) == chunks.length - 1) await res.body.pipe(fileStream, { end: true })
else await res.body.pipe(fileStream, { end: false })
})
但是文件在完成后已损坏,我也尝试使用 flieStream.write(res.body, { end: true }) 而不是 res.body.pipe(fileStream, { end: true }) 但我收到以下错误:
(node:12110) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object
at validChunk (_stream_writable.js:265:10)
at WriteStream.Writable.write (_stream_writable.js:300:21)
at /root/api/getUpdate.js:97:87
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at async /root/api/getUpdate.js:94:57
(node:12110) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:12110) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
解决方案
推荐阅读
- elixir - 处理错误元组列表时是否有标准做法?
- microsoft-cognitive - 表单识别器 S0 层限制
- jquery - 如何从Nodejs接收base64数据并使用jquery显示
- c - 在分子动力学模拟中计算势能
- ruby-on-rails - 定义一个像 current_user rails 这样的通用方法
- bash - 如何比较默认列表中的用户输入值?
- asp.net-core - Ocelot ApiGateway 无法访问 Kubernetes 上的其他服务
- python - pip3 vs python3 -m pip vs python3.7 -m pip
- excel - excel 中的 SEARCH 功能无法正常工作
- linux - 如何将变量设置为shell脚本中变量内的变量