Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zzzs/egg-downloader
extend a method context.downloader to download file for egg
https://github.com/zzzs/egg-downloader
downloader egg egg-plugin javascript node
Last synced: 9 days ago
JSON representation
extend a method context.downloader to download file for egg
- Host: GitHub
- URL: https://github.com/zzzs/egg-downloader
- Owner: zzzs
- License: mit
- Created: 2018-09-09T11:05:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-16T04:10:06.000Z (about 6 years ago)
- Last Synced: 2024-08-01T18:31:30.571Z (3 months ago)
- Topics: downloader, egg, egg-plugin, javascript, node
- Language: JavaScript
- Size: 88.9 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-egg - egg-downloader - download file plugin for egg ![](https://img.shields.io/github/stars/zzzs/egg-downloader.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/egg-downloader.svg?style=flat-square) (仓库 / 插件)
- awesome-egg - egg-downloader - download file plugin for egg (Plugins)
README
# egg-downloader
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url][npm-image]: https://img.shields.io/npm/v/egg-downloader.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-downloader
[travis-image]: https://img.shields.io/travis/zzzs/egg-downloader.svg?style=flat-square
[travis-url]: https://travis-ci.org/zzzs/egg-downloader
[codecov-image]: https://img.shields.io/codecov/c/github/zzzs/egg-downloader.svg?style=flat-square
[codecov-url]: https://codecov.io/github/zzzs/egg-downloader?branch=master
[david-image]: https://img.shields.io/david/zzzs/egg-downloader.svg?style=flat-square
[david-url]: https://david-dm.org/zzzs/egg-downloader
[snyk-image]: https://snyk.io/test/github/zzzs/egg-downloader/badge.svg?targetFile=package.json
[snyk-url]: https://snyk.io/test/github/zzzs/egg-downloader?targetFile=package.json
[download-image]: https://img.shields.io/npm/dm/egg-downloader.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-downloaderextend a method `ctx.downloader` to download file
## Install
```bash
$ npm i egg-downloader --save
```## Usage
```js
// {app_root}/config/plugin.js
exports.downloader = {
enable: true,
package: 'egg-downloader',
};
```## Features
`ctx.downloader`用于提供文件下载的功能,支持三个参数,ctx.download(file, [name], [header])
* file: 必选,文件路径
* name: 可选,下载文件名(包含后缀)
* header: 可选,附加头信息, 并且header会改为全部小写(感谢[天猪](https://github.com/atian25)的建议:egg 推荐 header 全部小写,会有一定的性能提升)。> 如果 file 是个不带路径的文件,将默认视为下载 app/public/file 。
## Example
```js
// {app_root}/controller/home.js
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
// 下载为 package.json
this.ctx.downloader('./package.json');
// 下载为 new-name.json
// this.ctx.downloader('package.json', 'new-name.json');
// 下载为 new-name.json, header: X-Token: 123
// this.ctx.downloader('package.json', 'new-name.json', { 'x-token': '123' });
}
}
module.exports = HomeController;
```## Questions & Suggestions
Please open an issue [here](https://github.com/zzzs/egg-downloader/issues).
## License
[MIT](LICENSE)