1

I have more .chunk files which I fetch using node-fetch and using these files I want to create another file by "gathering them together" somehow.

I tried with this:

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 })
    })

but the file is corrupted after it finishes, I also tried with flieStream.write(res.body, { end: true }) instead of res.body.pipe(fileStream, { end: true }) but I get the following error:

(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.

ILikeCats
  • 11
  • 2

0 Answers0