Created
January 3, 2020 07:53
-
-
Save ervinb/e3c882ae0e4b873bc1eec8d194a050d8 to your computer and use it in GitHub Desktop.
How to download gzipped file with request and Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request-promise-native'); | |
const os = require('os'); | |
const fs = require('fs-extra'); | |
const res = await request.get('http://link.to/some-gzipped-image.jpg', { | |
gzip: true, | |
resolveWithFullResponse: true, // optional, otherwise replace `res.body` with just `res` below | |
encoding: null | |
}); | |
const tmpPath = `${os.tmpdir()}/${new Date().getTime()}.jpg`; | |
await fs.writeFile(tmpPath, res.body, 'binary'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment