Nodejs request download file unzip json.gz file
Just handle all errors and you know what went wrong. From your example it's impossible to tell you anything more than that the. But want exactly went wrong is a mystery because you don't check for errors in your code. Turns out that I wasn't waiting for the file to complete downloading before unzipping it; which was why the generated json was empty. I had to use the code for unzipping the file as a callback function -. This also explains why I was able to unzip the file manually just using the download code, as the download was complete at that point allowing me to successfully unzip it on the terminal.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Trouble unzipping. Asked 4 years, 8 months ago. Active 4 years, 8 months ago. Viewed 1k times. Improve this question. Anish Sana Anish Sana 1 1 gold badge 10 10 silver badges 27 27 bronze badges. Add a comment. Active Oldest Votes.
Improve this answer. I just had to use the code for unzipping the file as a callback function. Thanks for your help. Sign up or log in Sign up using Google. Sign up using Facebook. What is GZIP? So if you are not enabling GZIP in the request options then the actual response from the server that you will get is compressed gibberish that will result in a corrupt file. Also make sure the headers that you are setting are correct and they are in sync with what a normal request to that file would look like.
Now, inspect that request and check what are the actual Request Headers of the request and make sure they are in sync with your headers from your code. Do not forget to set the Cookie header or the Authorization Tokens if you are dealing with content only accessible to logged in users. You can easily do this by adding another parameter in the headers object just like this.
Lets end this with an overall recap of what is happening with this snippet and how it is working step by step.
There are plenty of alternatives out there, like: http.
0コメント