Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/claudetech/koa-stream
Send file with range requests
https://github.com/claudetech/koa-stream
Last synced: 2 months ago
JSON representation
Send file with range requests
- Host: GitHub
- URL: https://github.com/claudetech/koa-stream
- Owner: claudetech
- License: mit
- Created: 2015-06-19T09:04:20.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-02T08:45:01.000Z (about 9 years ago)
- Last Synced: 2024-10-31T08:52:20.361Z (2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/koa-stream
- Size: 163 KB
- Stars: 29
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - koa-stream - 支持范围请求的文件发送实用程序。 ![](https://img.shields.io/github/stars/claudetech/koa-stream.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-stream.svg?style=flat-square) (仓库 / 中间件)
README
# koa-stream [![Build Status](https://travis-ci.org/claudetech/koa-stream.svg?branch=master)](https://travis-ci.org/claudetech/koa-stream) [![Coverage Status](https://coveralls.io/repos/claudetech/koa-stream/badge.svg)](https://coveralls.io/r/claudetech/koa-stream)
Helper to stream files and buffers with range requests using koa.
This can be used with `video` tags, and other resource using the `Range` header.The implementation follows [RFC 7233](https://tools.ietf.org/html/rfc7233).
## Installation
```sh
$ npm install koa-stream
```## Usage
### Stream Files
```javascript
var stream = require('koa-stream');
var path = require('path');
var app = require('koa');app.use(function *() {
yield stream.file(this, 'my-video.mp4', {root: path.join(__dirname, '/public')});
});
```### Stream Buffers
```javascript
var stream = require('koa-stream');
var path = require('path');
var app = require('koa');app.use(function *() {
stream.buffer(this, new Buffer([1,2,3]), 'image/png', {allowDownload: true});
});
```See [sample/index.js](./sample/index.js) for a working example.
### Options
* `root`: the directory from which file paths will be resolved
* `allowDownload`: allow to return the file instead of streaming it if not `Range` header is provided