Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yields/download
download files with `xhr`, report progress and send the file.
https://github.com/yields/download
Last synced: 14 days ago
JSON representation
download files with `xhr`, report progress and send the file.
- Host: GitHub
- URL: https://github.com/yields/download
- Owner: yields
- Created: 2013-04-21T01:32:13.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-04-21T01:34:11.000Z (over 11 years ago)
- Last Synced: 2024-10-24T20:06:34.293Z (2 months ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# download
Downloads a file with `xhr`, report progress and send the file to the user.
## Installation
$ component install yields/download
## Example
You can run the example with `$ make example` and then `$ serve . && open http://localhost:300/`.
```js
var Download = require('download')
, Progress = require('progress');var download = new Download('somefile');
var progress = new Progress();
doument.body.appendChild(progress.el);
progress.update(0);download.on('progress', function(e){
progress.update(e.percent);
});download.end(function(err, req){
if (err) throw err;
location.pathname = '/somefile';
});
```## API
### Download(filepath)
Create a new Download with `filepath`.
### download.abort()
Abort the request.
### download.end(fn(err, req))
Start the download and invoke `fn(err, req)`, at this point you should just do `location.pathname = '/somefile'`.
## dependencies
- [yields/xhr](https://github.com/yields/xhr)
- [component/emitter](https://github.com/component/emitter)## License
MIT