# koa-sendfile

> basic file-sending utility for koa

Latest version **3.0.0** (published 2020-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-sendfile
pnpm add koa-sendfile
yarn add koa-sendfile
bun add koa-sendfile
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-10-31 |
| First published | 2014-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 2 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonathan Ong |
| Maintainers | aheckmann, coderhaoxin, niftylettuce, juliangruber, eivifj, dead_horse, tjholowaychuk, bitinn, jongleberry, fengmk2 |

## Links

- npm: https://www.npmjs.com/package/koa-sendfile
- Repository: https://github.com/koajs/sendfile
- Homepage: https://github.com/koajs/sendfile#readme
- Issues: https://github.com/koajs/sendfile/issues
- npm.io page: https://npm.io/package/koa-sendfile

## Dependencies (2)

- [etag](https://npm.io/package/etag.md) ^1.8.1
- [debug](https://npm.io/package/debug.md) ^4.2.0

## Recent versions

- 3.0.0 (latest) — 2020-10-31
- 1.1.2 (latest-1) — 2018-09-12
- 2.0.1 — 2018-09-12
- 2.0.0 — 2016-02-29
- 1.1.1 — 2015-05-17
- 1.1.0 — 2015-02-02
- 1.0.3 — 2014-09-11
- 1.0.2 — 2014-09-11
- 1.0.1 — 2014-05-08
- 1.0.0 — 2014-03-23

## README

# koa sendfile

[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

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)`.

```js
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)
})
```

[npm-image]: https://img.shields.io/npm/v/koa-sendfile.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-sendfile
[github-tag]: http://img.shields.io/github/tag/koajs/sendfile.svg?style=flat-square
[github-url]: https://github.com/koajs/sendfile/tags
[travis-image]: https://img.shields.io/travis/koajs/sendfile.svg?style=flat-square
[travis-url]: https://travis-ci.org/koajs/sendfile
[coveralls-image]: https://img.shields.io/coveralls/koajs/sendfile.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/koajs/sendfile?branch=master
[david-image]: http://img.shields.io/david/koajs/sendfile.svg?style=flat-square
[david-url]: https://david-dm.org/koajs/sendfile
[license-image]: http://img.shields.io/npm/l/koa-sendfile.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/koa-sendfile.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/koa-sendfile

---
_Source: https://npm.io/package/koa-sendfile · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
