Closed Ookamini95 closed 1 year ago
@Ookamini95 async is not possible due to the way libcurl works, we must return something to libcurl as soon as they call us. You can use writeFileSync inside the writeResponse.
Keep in mind this may (and probably will) get called more than once, as the response is retrieved in chunks.
You are supposed to read nmemb * size
bytes of the buffer, and write those. Example here: https://github.com/JCMais/node-libcurl/blob/1563bb7699eb9b22989058a0d018c59a460aaf37/examples/16-ftp-download.js#L24-L36
Thanks for the response. Too bad though, I'll have to find another way.
If the file is not big, you can append the chunks to an array and then create a single buffer later to then write to a file.
Closing this as the original question has been answered.
Is it possible to use async on the writefunction, so as to use fs.promises to write onto a file? Something like
If I use await, error code 23 is shown (function expects an int, while a promise is returned). Also if I try to write onto the file directly in the runCurly function nothing is written (buffer is empty).