UNPKG

@masx200/koa-range

Version:

range request implementation for koa

94 lines (67 loc) 2.38 kB
# koa-range forked from https://github.com/koajs/koa-range It seems that the original project has not been updated for a long time. The following problems have been fixed. https://github.com/koajs/koa-range/issues/17 https://github.com/koajs/koa-range/issues/15 https://github.com/koajs/koa-range/issues/16 https://github.com/koajs/koa-range/issues/19 https://github.com/koajs/koa-range/issues/20 ================= range request implementation for koa [![NPM version][npm-img]][npm-url] [![Build status][travis-img]][travis-url] [![Test coverage][coveralls-img]][coveralls-url] [![License][license-img]][license-url] [![Dependency status][david-img]][david-url] [![NPM](https://nodei.co/npm/koa-range.png?stars&downloads)](https://nodei.co/npm/koa-range/) [![NPM](https://nodei.co/npm-dl/koa-range.png)](https://nodei.co/npm/koa-range/) ### Installation ```sh $ npm install @masx200/koa-range ``` ### Usage (with koa@2) ```js var fs = require("fs"); var range = require("@masx200/koa-range"); var route = require("koa-route"); var Koa = require("koa"); var app = new Koa(); app.use(range); // via buffer app.use( route.get("/", async function (ctx) { ctx.body = new Buffer(100); }) ); // via object app.use( route.get("/json", async function (ctx) { ctx.body = { foo: "bar", }; }) ); // via readable stream app.use( route.get("/stream", async function (ctx) { ctx.body = fs.createReadStream("your path"); }) ); ``` Until async/await is supported by default, you will need to do one of the following: - Transpile your code with somehting like Babel - Use node v7 with --harmony-async-await flag ### License MIT [npm-img]: https://img.shields.io/npm/v/koa-range.svg?style=flat-square [npm-url]: https://npmjs.org/package/koa-range [travis-img]: https://img.shields.io/travis/koajs/koa-range.svg?style=flat-square [travis-url]: https://travis-ci.org/koajs/koa-range [coveralls-img]: https://img.shields.io/coveralls/koajs/koa-range.svg?style=flat-square [coveralls-url]: https://coveralls.io/r/koajs/koa-range?branch=master [license-img]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square [license-url]: https://opensource.org/licenses/MIT [david-img]: https://img.shields.io/david/koajs/koa-range.svg?style=flat-square [david-url]: https://david-dm.org/koajs/koa-range