You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # download [![Build Status](https://travis-ci.org/kevva/download.svg?branch=master)](https://travis-ci.org/kevva/download)
  2. > Download and extract files
  3. *See [download-cli](https://github.com/kevva/download-cli) for the command-line version.*
  4. ## Install
  5. ```
  6. $ npm install --save download
  7. ```
  8. ## Usage
  9. ```js
  10. const fs = require('fs');
  11. const download = require('download');
  12. download('http://unicorn.com/foo.jpg', 'dist').then(() => {
  13. console.log('done!');
  14. });
  15. download('http://unicorn.com/foo.jpg').then(data => {
  16. fs.writeFileSync('dist/foo.jpg', data);
  17. });
  18. download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
  19. Promise.all([
  20. 'unicorn.com/foo.jpg',
  21. 'cats.com/dancing.gif'
  22. ].map(x => download(x, 'dist'))).then(() => {
  23. console.log('files downloaded!');
  24. });
  25. ```
  26. ## API
  27. ### download(url, [destination], [options])
  28. Returns both a `Promise<Buffer>` and a [Duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with [additional events](https://github.com/sindresorhus/got#streams).
  29. #### url
  30. Type: `string`
  31. URL to download.
  32. #### destination
  33. Type: `string`
  34. Path to where your file will be written.
  35. #### options
  36. Same options as [`got`](https://github.com/sindresorhus/got) in addition to the ones below.
  37. ##### extract
  38. Type: `boolean`<br>
  39. Default: `false`
  40. If set to `true`, try extracting the file using [`decompress`](https://github.com/kevva/decompress).
  41. ##### filename
  42. Type: `string`
  43. Name of the saved file.
  44. ##### proxy
  45. Type: `string`
  46. Proxy endpoint.
  47. ## License
  48. MIT © [Kevin Mårtensson](https://github.com/kevva)