Save a binary file using REQUEST module in Node the right way
I was trying to save some PDF from an output of a request, and I always got a corrupted file.
Initially I found that I saved my file as UTF-8 while it was ascii (took almost double), so I added the ASCII encoding to the file fs,fileWrite command, this helped a bit but still corrupted.
Eventually I read some more about the request module and identified that i was missing the "encoding: 'binary'" in the options!
This is the final code:
Initially I found that I saved my file as UTF-8 while it was ascii (took almost double), so I added the ASCII encoding to the file fs,fileWrite command, this helped a bit but still corrupted.
Eventually I read some more about the request module and identified that i was missing the "encoding: 'binary'" in the options!
This is the final code:
Save a binary file using REQUEST module in Node the right way
Reviewed by Ran Davidovitz
on
11:13 AM
Rating:
No comments:
Post a Comment