koa-sendfile
basic file-sending utility for koa
Last updated 5 years ago by niftylettuce .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install koa-sendfile 
SYNC missed versions from official npm registry.

koa sendfile

NPM version Build status Test coverage Dependency Status License Downloads

Basic file-sending utility for koa. It does the following:

  • Check if a file exists
  • Set content-length, content-type, and last-modified headers
  • 304 based on last-modified
  • Handle HEAD requests

It does not:

  • Check for malicious paths or hidden files
  • Support directory indexes
  • Cache control
  • OPTIONS method

API

sendfile(context, filename)

You must pass the koa context. filename is the filename of the file.

sendfile returns a promise that resolves to the fs.stat() result of the filename. If sendfile() resolves, that doesn't mean that a response is set - the filename could be a directory. Instead, check if (context.status).

const sendfile = require('koa-sendfile')

app.use(async function (ctx, next) {
  const stats = await sendfile(ctx, '/Users/jong/.bash_profile')
  if (!ctx.status) ctx.throw(404)
})

Current Tags

  • 3.0.0                                ...           latest (5 years ago)
  • 1.1.2                                ...           latest-1 (8 years ago)

10 Versions

  • 3.0.0                                ...           5 years ago
  • 1.1.2                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           10 years ago
  • 1.1.1                                ...           11 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.3                                ...           12 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (11)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |