Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用多个.chunk文件创建文件?_Javascript_Node.js_Node Fetch - Fatal编程技术网

Javascript 如何使用多个.chunk文件创建文件?

Javascript 如何使用多个.chunk文件创建文件?,javascript,node.js,node-fetch,Javascript,Node.js,Node Fetch,我有更多的.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 =

我有更多的.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.