Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ervinb/e3c882ae0e4b873bc1eec8d194a050d8 to your computer and use it in GitHub Desktop.
Save ervinb/e3c882ae0e4b873bc1eec8d194a050d8 to your computer and use it in GitHub Desktop.
How to download gzipped file with request and Node.js
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