North Pittsburgh Meatpackers
    Have ideas to improve npm?Join in the discussion! »

    koa-stream

    0.2.0 • Public • Published

    koa-stream Build Status Coverage Status

    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.

    Installation

    $ npm install koa-stream

    Usage

    Stream Files

    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

    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 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

    Install

    npm i koa-stream

    DownloadsWeekly Downloads

    88

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • avatar